Changes in / [cc8d91a:a649e73f] in mainline


Ignore:
Location:
uspace
Files:
2 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ns8250/ns8250.c

    rcc8d91a ra649e73f  
    123123static void delete_ns8250_dev_data(ns8250_dev_data_t *data)
    124124{
    125         if (data != NULL)
     125        if (NULL != data)
    126126                free(data);
    127127}
     
    251251static void ns8250_dev_cleanup(device_t *dev)
    252252{
    253         if (dev->driver_data != NULL) {
     253        if (NULL != dev->driver_data) {
    254254                delete_ns8250_dev_data((ns8250_dev_data_t*) dev->driver_data);
    255255                dev->driver_data = NULL;
     
    332332        /* Allocate driver data for the device. */
    333333        ns8250_dev_data_t *data = create_ns8250_dev_data();
    334         if (data == NULL)
     334        if (NULL == data)
    335335                return ENOMEM;
    336336        dev->driver_data = data;
     
    436436        /* Enable interrupt globally. */
    437437        res = interrupt_enable(data->irq);
    438         if (res != EOK)
     438        if (EOK != res)
    439439                return res;
    440440       
     
    480480        uint8_t div_low, div_high;
    481481       
    482         if (baud_rate < 50 || MAX_BAUD_RATE % baud_rate != 0) {
     482        if (50 > baud_rate || 0 != MAX_BAUD_RATE % baud_rate) {
    483483                printf(NAME ": error - somebody tried to set invalid baud rate "
    484484                    "%d\n", baud_rate);
     
    534534 * @param stop_bits     The number of stop bits used (one or two).
    535535 */
    536 static void ns8250_port_get_com_props(ioport8_t *port, unsigned int *parity,
     536static void
     537ns8250_port_get_com_props(ioport8_t *port, unsigned int *parity,
    537538    unsigned int *word_length, unsigned int *stop_bits)
    538539{
     
    571572 *                      is invalid.
    572573 */
    573 static int ns8250_port_set_com_props(ioport8_t *port, unsigned int parity,
     574static int
     575ns8250_port_set_com_props(ioport8_t *port, unsigned int parity,
    574576    unsigned int word_length, unsigned int stop_bits)
    575577{
     
    689691 * @param dev           The serial port device.
    690692 */
    691 static inline void ns8250_interrupt_handler(device_t *dev, ipc_callid_t iid,
    692     ipc_call_t *icall)
     693static inline void
     694ns8250_interrupt_handler(device_t *dev, ipc_callid_t iid, ipc_call_t *icall)
    693695{
    694696        ns8250_read_from_device(dev);
     
    724726 * @param dev           The serial port device.
    725727 */
    726 static int ns8250_add_device(device_t *dev)
     728static int ns8250_add_device(device_t *dev) 
    727729{
    728730        printf(NAME ": ns8250_add_device %s (handle = %d)\n",
     
    730732       
    731733        int res = ns8250_dev_initialize(dev);
    732         if (res != EOK)
     734        if (EOK != res)
    733735                return res;
    734736       
     
    748750       
    749751        /* Register interrupt handler. */
    750         if (ns8250_register_interrupt_handler(dev) != EOK) {
     752        if (EOK != ns8250_register_interrupt_handler(dev)) {
    751753                printf(NAME ": failed to register interrupt handler.\n");
    752754                ns8250_dev_cleanup(dev);
     
    756758        /* Enable interrupt. */
    757759        res = ns8250_interrupt_enable(dev);
    758         if (res != EOK) {
     760        if (EOK != res) {
    759761                printf(NAME ": failed to enable the interrupt. Error code = "
    760762                    "%d.\n", res);
     
    857859 * @param stop_bits     The number of stop bits to be used.
    858860 */
    859 static int ns8250_set_props(device_t *dev, unsigned int baud_rate,
    860     unsigned int parity, unsigned int word_length, unsigned int stop_bits)
     861static int
     862ns8250_set_props(device_t *dev, unsigned int baud_rate, unsigned int parity,
     863    unsigned int word_length, unsigned int stop_bits)
    861864{
    862865        printf(NAME ": ns8250_set_props: baud rate %d, parity 0x%x, word "
     
    871874        ns8250_port_interrupts_disable(port);
    872875        ret = ns8250_port_set_baud_rate(port, baud_rate);
    873         if (ret == EOK)
     876        if (EOK == ret)
    874877                ret = ns8250_port_set_com_props(port, parity, word_length, stop_bits);
    875878        ns8250_port_interrupts_enable(port);
     
    884887 * Configure the parameters of the serial communication.
    885888 */
    886 static void ns8250_default_handler(device_t *dev, ipc_callid_t callid,
    887     ipc_call_t *call)
     889static void
     890ns8250_default_handler(device_t *dev, ipc_callid_t callid, ipc_call_t *call)
    888891{
    889892        ipcarg_t method = IPC_GET_METHOD(*call);
  • uspace/drv/pciintel/pci.c

    rcc8d91a ra649e73f  
    6565        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
    6666       
    67         if (dev_data == NULL)
     67        if (NULL == dev_data)
    6868                return NULL;
    6969        return &dev_data->hw_resources;
     
    109109       
    110110        bus_data = (pci_bus_data_t *) malloc(sizeof(pci_bus_data_t));
    111         if (bus_data != NULL) {
     111        if (NULL != bus_data) {
    112112                memset(bus_data, 0, sizeof(pci_bus_data_t));
    113113                fibril_mutex_initialize(&bus_data->conf_mutex);
    114114        }
    115 
    116115        return bus_data;
    117116}
     
    124123static void pci_conf_read(device_t *dev, int reg, uint8_t *buf, size_t len)
    125124{
    126         assert(dev->parent != NULL);
     125        assert(NULL != dev->parent);
    127126       
    128127        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
     
    154153static void pci_conf_write(device_t *dev, int reg, uint8_t *buf, size_t len)
    155154{
    156         assert(dev->parent != NULL);
     155        assert(NULL != dev->parent);
    157156       
    158157        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
     
    225224       
    226225        match_id = create_match_id();
    227         if (match_id != NULL) {
     226        if (NULL != match_id) {
    228227                asprintf(&match_id_str, "pci/ven=%04x&dev=%04x",
    229228                    dev_data->vendor_id, dev_data->device_id);
     
    231230                match_id->score = 90;
    232231                add_match_id(&dev->match_ids, match_id);
    233         }
    234 
     232        }       
    235233        /* TODO add more ids (with subsys ids, using class id etc.) */
    236234}
     
    244242        size_t count = hw_res_list->count;
    245243       
    246         assert(hw_resources != NULL);
     244        assert(NULL != hw_resources);
    247245        assert(count < PCI_MAX_HW_RES);
    248246       
     
    277275        bool io;
    278276        /* 64-bit wide address */
    279         bool addrw64;
     277        bool w64;
    280278       
    281279        /* Size of the io or memory range specified by the BAR */
     
    289287        io = (bool) (val & 1);
    290288        if (io) {
    291                 addrw64 = false;
     289                w64 = false;
    292290        } else {
    293291                switch ((val >> 1) & 3) {
    294292                case 0:
    295                         addrw64 = false;
     293                        w64 = false;
    296294                        break;
    297295                case 2:
    298                         addrw64 = true;
     296                        w64 = true;
    299297                        break;
    300298                default:
     
    314312        range_size = pci_bar_mask_to_size(mask);
    315313       
    316         if (addrw64) {
     314        if (w64) {
    317315                range_addr = ((uint64_t)pci_conf_read_32(dev, addr + 4) << 32) |
    318316                    (val & 0xfffffff0);
     
    321319        }
    322320       
    323         if (range_addr != 0) {
     321        if (0 != range_addr) {
    324322                printf(NAME ": device %s : ", dev->name);
    325323                printf("address = %x", range_addr);
     
    329327        pci_add_range(dev, range_addr, range_size, io);
    330328       
    331         if (addrw64)
     329        if (w64)
    332330                return addr + 8;
    333331       
     
    356354{
    357355        uint8_t irq = pci_conf_read_8(dev, PCI_BRIDGE_INT_LINE);
    358         if (irq != 0xff)
     356        if (0xff != irq)
    359357                pci_add_interrupt(dev, irq);
    360358}
     
    417415                        create_pci_match_ids(dev);
    418416                       
    419                         if (child_device_register(dev, parent) != EOK) {
     417                        if (EOK != child_device_register(dev, parent)) {
    420418                                pci_clean_resource_list(dev);
    421419                                clean_match_ids(&dev->match_ids);
     
    426424                       
    427425                        if (header_type == PCI_HEADER_TYPE_BRIDGE ||
    428                             header_type == PCI_HEADER_TYPE_CARDBUS) {
     426                            header_type == PCI_HEADER_TYPE_CARDBUS ) {
    429427                                child_bus = pci_conf_read_8(dev,
    430428                                    PCI_BRIDGE_SEC_BUS_NUM);
    431429                                printf(NAME ": device is pci-to-pci bridge, "
    432430                                    "secondary bus number = %d.\n", bus_num);
    433                                 if (child_bus > bus_num)
     431                                if(child_bus > bus_num)
    434432                                        pci_bus_scan(parent, child_bus);
    435433                        }
     
    455453       
    456454        pci_bus_data_t *bus_data = create_pci_bus_data();
    457         if (bus_data == NULL) {
     455        if (NULL == bus_data) {
    458456                printf(NAME ": pci_add_device allocation failed.\n");
    459457                return ENOMEM;
     
    515513}
    516514
    517 pci_dev_data_t *create_pci_dev_data(void)
    518 {
    519         pci_dev_data_t *res = (pci_dev_data_t *) malloc(sizeof(pci_dev_data_t));
    520        
    521         if (res != NULL)
    522                 memset(res, 0, sizeof(pci_dev_data_t));
    523         return res;
    524 }
    525 
    526 void init_pci_dev_data(pci_dev_data_t *dev_data, int bus, int dev, int fn)
    527 {
    528         dev_data->bus = bus;
    529         dev_data->dev = dev;
    530         dev_data->fn = fn;
    531 }
    532 
    533 void delete_pci_dev_data(pci_dev_data_t *dev_data)
    534 {
    535         if (dev_data != NULL) {
    536                 clean_hw_resource_list(&dev_data->hw_resources);
    537                 free(dev_data);
    538         }
    539 }
    540 
    541 void create_pci_dev_name(device_t *dev)
    542 {
    543         pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
    544         char *name = NULL;
    545        
    546         asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev,
    547             dev_data->fn);
    548         dev->name = name;
    549 }
    550 
    551 bool pci_alloc_resource_list(device_t *dev)
    552 {
    553         pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
    554        
    555         dev_data->hw_resources.resources =
    556             (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t));
    557         return dev_data->hw_resources.resources != NULL;
    558 }
    559 
    560 void pci_clean_resource_list(device_t *dev)
    561 {
    562         pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
    563        
    564         if (dev_data->hw_resources.resources != NULL) {
    565                 free(dev_data->hw_resources.resources);
    566                 dev_data->hw_resources.resources = NULL;
    567         }
    568 }
    569 
    570 /** Read the base address registers (BARs) of the device and adds the addresses
    571  * to its hw resource list.
    572  *
    573  * @param dev the pci device.
    574  */
    575 void pci_read_bars(device_t *dev)
    576 {
    577         /*
    578          * Position of the BAR in the PCI configuration address space of the
    579          * device.
    580          */
    581         int addr = PCI_BASE_ADDR_0;
    582        
    583         while (addr <= PCI_BASE_ADDR_5)
    584                 addr = pci_read_bar(dev, addr);
    585 }
    586 
    587 size_t pci_bar_mask_to_size(uint32_t mask)
    588 {
    589         return ((mask & 0xfffffff0) ^ 0xffffffff) + 1;
    590 }
    591 
    592515int main(int argc, char *argv[])
    593516{
  • uspace/drv/pciintel/pci.h

    rcc8d91a ra649e73f  
    6969extern void pci_bus_scan(device_t *, int);
    7070
    71 extern pci_dev_data_t *create_pci_dev_data(void);
    72 extern void init_pci_dev_data(pci_dev_data_t *, int, int, int);
    73 extern void delete_pci_dev_data(pci_dev_data_t *);
    74 extern void create_pci_dev_name(device_t *);
     71static inline pci_dev_data_t *create_pci_dev_data(void)
     72{
     73        pci_dev_data_t *res = (pci_dev_data_t *) malloc(sizeof(pci_dev_data_t));
     74       
     75        if (NULL != res)
     76                memset(res, 0, sizeof(pci_dev_data_t));
     77        return res;
     78}
    7579
    76 extern bool pci_alloc_resource_list(device_t *);
    77 extern void pci_clean_resource_list(device_t *);
     80static inline void
     81init_pci_dev_data(pci_dev_data_t *d, int bus, int dev, int fn)
     82{
     83        d->bus = bus;
     84        d->dev = dev;
     85        d->fn = fn;
     86}
    7887
    79 extern void pci_read_bars(device_t *);
    80 extern size_t pci_bar_mask_to_size(uint32_t);
     88static inline void delete_pci_dev_data(pci_dev_data_t *d)
     89{
     90        if (NULL != d) {
     91                clean_hw_resource_list(&d->hw_resources);
     92                free(d);
     93        }
     94}
     95
     96static inline void create_pci_dev_name(device_t *dev)
     97{
     98        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
     99        char *name = NULL;
     100       
     101        asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev,
     102            dev_data->fn);
     103        dev->name = name;
     104}
     105
     106static inline bool pci_alloc_resource_list(device_t *dev)
     107{
     108        pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
     109       
     110        dev_data->hw_resources.resources =
     111            (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t));
     112        return dev_data->hw_resources.resources != NULL;
     113}
     114
     115static inline void pci_clean_resource_list(device_t *dev)
     116{
     117        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
     118       
     119        if (NULL != dev_data->hw_resources.resources) {
     120                free(dev_data->hw_resources.resources);
     121                dev_data->hw_resources.resources = NULL;
     122        }
     123}
     124
     125/** Read the base address registers (BARs) of the device and adds the addresses
     126 * to its hw resource list.
     127 *
     128 * @param dev the pci device.
     129 */
     130static inline  void pci_read_bars(device_t *dev)
     131{
     132        /*
     133         * Position of the BAR in the PCI configuration address space of the
     134         * device.
     135         */
     136        int addr = PCI_BASE_ADDR_0;
     137       
     138        while (addr <= PCI_BASE_ADDR_5)
     139                addr = pci_read_bar(dev, addr);
     140}
     141
     142static inline size_t pci_bar_mask_to_size(uint32_t mask)
     143{
     144        return ((mask & 0xfffffff0) ^ 0xffffffff) + 1;
     145}
    81146
    82147#endif
  • uspace/srv/devman/devman.c

    rcc8d91a ra649e73f  
    7676        .remove_callback = devices_remove_callback
    7777};
    78 
    79 /**
    80  * Initialize the list of device driver's.
    81  *
    82  * @param drv_list the list of device driver's.
    83  *
    84  */
    85 void init_driver_list(driver_list_t *drv_list)
    86 {
    87         assert(drv_list != NULL);
    88        
    89         list_initialize(&drv_list->drivers);
    90         fibril_mutex_initialize(&drv_list->drivers_mutex);
    91 }
    9278
    9379/** Allocate and initialize a new driver structure.
     
    562548}
    563549
    564 /** Initialize device driver structure.
    565  *
    566  * @param drv           The device driver structure.
    567  */
    568 void init_driver(driver_t *drv)
    569 {
    570         assert(drv != NULL);
    571 
    572         memset(drv, 0, sizeof(driver_t));
    573         list_initialize(&drv->match_ids.ids);
    574         list_initialize(&drv->devices);
    575         fibril_mutex_initialize(&drv->driver_mutex);
    576 }
    577 
    578 /** Device driver structure clean-up.
    579  *
    580  * @param drv           The device driver structure.
    581  */
    582 void clean_driver(driver_t *drv)
    583 {
    584         assert(drv != NULL);
    585 
    586         free_not_null(drv->name);
    587         free_not_null(drv->binary_path);
    588 
    589         clean_match_ids(&drv->match_ids);
    590 
    591         init_driver(drv);
    592 }
    593 
    594 /** Delete device driver structure.
    595  *
    596  * @param drv           The device driver structure.
    597  */
    598 void delete_driver(driver_t *drv)
    599 {
    600         assert(drv != NULL);
    601        
    602         clean_driver(drv);
    603         free(drv);
    604 }
    605550
    606551/** Create devmap path and name for the device. */
     
    740685}
    741686
    742 /* Device nodes */
    743 
    744 /** Create a new device node.
    745  *
    746  * @return              A device node structure.
    747  */
    748 node_t *create_dev_node(void)
    749 {
    750         node_t *res = malloc(sizeof(node_t));
    751        
    752         if (res != NULL) {
    753                 memset(res, 0, sizeof(node_t));
    754                 list_initialize(&res->children);
    755                 list_initialize(&res->match_ids.ids);
    756                 list_initialize(&res->classes);
    757         }
    758        
    759         return res;
    760 }
    761 
    762 /** Delete a device node.
    763  *
    764  * @param node          The device node structure.
    765  */
    766 void delete_dev_node(node_t *node)
    767 {
    768         assert(list_empty(&node->children));
    769         assert(node->parent == NULL);
    770         assert(node->drv == NULL);
    771        
    772         clean_match_ids(&node->match_ids);
    773         free_not_null(node->name);
    774         free_not_null(node->pathname);
    775         free(node);
    776 }
    777 
    778 /** Find the device node structure of the device witch has the specified handle.
    779  *
    780  * Device tree's rwlock should be held at least for reading.
    781  *
    782  * @param tree          The device tree where we look for the device node.
    783  * @param handle        The handle of the device.
    784  * @return              The device node.
    785  */
    786 node_t *find_dev_node_no_lock(dev_tree_t *tree, device_handle_t handle)
    787 {
    788         unsigned long key = handle;
    789         link_t *link = hash_table_find(&tree->devman_devices, &key);
    790         return hash_table_get_instance(link, node_t, devman_link);
    791 }
    792 
    793 /** Find the device node structure of the device witch has the specified handle.
    794  *
    795  * @param tree          The device tree where we look for the device node.
    796  * @param handle        The handle of the device.
    797  * @return              The device node.
    798  */
    799 node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle)
    800 {
    801         node_t *node = NULL;
    802        
    803         fibril_rwlock_read_lock(&tree->rwlock);
    804         node = find_dev_node_no_lock(tree, handle);
    805         fibril_rwlock_read_unlock(&tree->rwlock);
    806        
    807         return node;
    808 }
    809 
    810 
    811687/** Create and set device's full path in device tree.
    812688 *
     
    949825        return NULL;
    950826}
    951 
    952 /* Device classes */
    953 
    954 /** Create device class.
    955  *
    956  * @return      Device class.
    957  */
    958 dev_class_t *create_dev_class(void)
    959 {
    960         dev_class_t *cl;
    961        
    962         cl = (dev_class_t *) malloc(sizeof(dev_class_t));
    963         if (cl != NULL) {
    964                 memset(cl, 0, sizeof(dev_class_t));
    965                 list_initialize(&cl->devices);
    966                 fibril_mutex_initialize(&cl->mutex);
    967         }
    968        
    969         return cl;
    970 }
    971 
    972 /** Create device class info.
    973  *
    974  * @return              Device class info.
    975  */
    976 dev_class_info_t *create_dev_class_info(void)
    977 {
    978         dev_class_info_t *info;
    979        
    980         info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
    981         if (info != NULL)
    982                 memset(info, 0, sizeof(dev_class_info_t));
    983        
    984         return info;
    985 }
    986 
    987 size_t get_new_class_dev_idx(dev_class_t *cl)
    988 {
    989         size_t dev_idx;
    990        
    991         fibril_mutex_lock(&cl->mutex);
    992         dev_idx = ++cl->curr_dev_idx;
    993         fibril_mutex_unlock(&cl->mutex);
    994        
    995         return dev_idx;
    996 }
    997 
    998827
    999828/** Create unique device name within the class.
     
    1092921}
    1093922
    1094 void add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl)
    1095 {
    1096         list_append(&cl->link, &class_list->classes);
    1097 }
    1098 
    1099923void init_class_list(class_list_t *class_list)
    1100924{
     
    1106930
    1107931
    1108 /* Devmap devices */
     932/* devmap devices */
    1109933
    1110934node_t *find_devmap_tree_device(dev_tree_t *tree, dev_handle_t devmap_handle)
     
    1143967}
    1144968
    1145 void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli)
    1146 {
    1147         unsigned long key = (unsigned long) cli->devmap_handle;
    1148        
    1149         fibril_rwlock_write_lock(&class_list->rwlock);
    1150         hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
    1151         fibril_rwlock_write_unlock(&class_list->rwlock);
    1152 }
    1153 
    1154 void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
    1155 {
    1156         unsigned long key = (unsigned long) node->devmap_handle;
    1157         fibril_rwlock_write_lock(&tree->rwlock);
    1158         hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
    1159         fibril_rwlock_write_unlock(&tree->rwlock);
    1160 }
    1161 
    1162969/** @}
    1163970 */
  • uspace/srv/devman/devman.h

    rcc8d91a ra649e73f  
    283283/* Drivers */
    284284
    285 extern void init_driver_list(driver_list_t *);
     285/**
     286 * Initialize the list of device driver's.
     287 *
     288 * @param drv_list the list of device driver's.
     289 *
     290 */
     291static inline void init_driver_list(driver_list_t *drv_list)
     292{
     293        assert(drv_list != NULL);
     294       
     295        list_initialize(&drv_list->drivers);
     296        fibril_mutex_initialize(&drv_list->drivers_mutex);
     297}
     298
    286299extern driver_t *create_driver(void);
    287300extern bool get_driver_info(const char *, const char *, driver_t *);
     
    298311extern driver_t *find_driver(driver_list_t *, const char *);
    299312extern void set_driver_phone(driver_t *, ipcarg_t);
    300 extern void initialize_running_driver(driver_t *, dev_tree_t *);
    301 
    302 extern void init_driver(driver_t *);
    303 extern void clean_driver(driver_t *);
    304 extern void delete_driver(driver_t *);
     313void initialize_running_driver(driver_t *, dev_tree_t *);
     314
     315/** Initialize device driver structure.
     316 *
     317 * @param drv           The device driver structure.
     318 */
     319static inline void init_driver(driver_t *drv)
     320{
     321        assert(drv != NULL);
     322
     323        memset(drv, 0, sizeof(driver_t));
     324        list_initialize(&drv->match_ids.ids);
     325        list_initialize(&drv->devices);
     326        fibril_mutex_initialize(&drv->driver_mutex);
     327}
     328
     329/** Device driver structure clean-up.
     330 *
     331 * @param drv           The device driver structure.
     332 */
     333static inline void clean_driver(driver_t *drv)
     334{
     335        assert(drv != NULL);
     336
     337        free_not_null(drv->name);
     338        free_not_null(drv->binary_path);
     339
     340        clean_match_ids(&drv->match_ids);
     341
     342        init_driver(drv);
     343}
     344
     345/** Delete device driver structure.
     346 *
     347 * @param drv           The device driver structure.
     348 */
     349static inline void delete_driver(driver_t *drv)
     350{
     351        assert(drv != NULL);
     352       
     353        clean_driver(drv);
     354        free(drv);
     355}
     356
    305357
    306358/* Device nodes */
    307359
    308 extern node_t *create_dev_node(void);
    309 extern void delete_dev_node(node_t *node);
    310 extern node_t *find_dev_node_no_lock(dev_tree_t *tree,
    311     device_handle_t handle);
    312 extern node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle);
     360/** Create a new device node.
     361 *
     362 * @return              A device node structure.
     363 */
     364static inline node_t *create_dev_node(void)
     365{
     366        node_t *res = malloc(sizeof(node_t));
     367       
     368        if (res != NULL) {
     369                memset(res, 0, sizeof(node_t));
     370                list_initialize(&res->children);
     371                list_initialize(&res->match_ids.ids);
     372                list_initialize(&res->classes);
     373        }
     374       
     375        return res;
     376}
     377
     378/** Delete a device node.
     379 *
     380 * @param node          The device node structure.
     381 */
     382static inline void delete_dev_node(node_t *node)
     383{
     384        assert(list_empty(&node->children));
     385        assert(node->parent == NULL);
     386        assert(node->drv == NULL);
     387       
     388        clean_match_ids(&node->match_ids);
     389        free_not_null(node->name);
     390        free_not_null(node->pathname);
     391        free(node);
     392}
     393
     394/** Find the device node structure of the device witch has the specified handle.
     395 *
     396 * Device tree's rwlock should be held at least for reading.
     397 *
     398 * @param tree          The device tree where we look for the device node.
     399 * @param handle        The handle of the device.
     400 * @return              The device node.
     401 */
     402static inline node_t *find_dev_node_no_lock(dev_tree_t *tree,
     403    device_handle_t handle)
     404{
     405        unsigned long key = handle;
     406        link_t *link = hash_table_find(&tree->devman_devices, &key);
     407        return hash_table_get_instance(link, node_t, devman_link);
     408}
     409
     410/** Find the device node structure of the device witch has the specified handle.
     411 *
     412 * @param tree          The device tree where we look for the device node.
     413 * @param handle        The handle of the device.
     414 * @return              The device node.
     415 */
     416static inline node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle)
     417{
     418        node_t *node = NULL;
     419       
     420        fibril_rwlock_read_lock(&tree->rwlock);
     421        node = find_dev_node_no_lock(tree, handle);
     422        fibril_rwlock_read_unlock(&tree->rwlock);
     423       
     424        return node;
     425}
     426
    313427extern node_t *find_dev_node_by_path(dev_tree_t *, char *);
    314428extern node_t *find_node_child(node_t *, const char *);
     429
    315430
    316431/* Device tree */
     
    320435extern bool insert_dev_node(dev_tree_t *, node_t *, char *, node_t *);
    321436
     437
    322438/* Device classes */
    323439
    324 extern dev_class_t *create_dev_class(void);
    325 extern dev_class_info_t *create_dev_class_info(void);
    326 extern size_t get_new_class_dev_idx(dev_class_t *);
     440/** Create device class.
     441 *
     442 * @return      Device class.
     443 */
     444static inline dev_class_t *create_dev_class(void)
     445{
     446        dev_class_t *cl;
     447       
     448        cl = (dev_class_t *) malloc(sizeof(dev_class_t));
     449        if (cl != NULL) {
     450                memset(cl, 0, sizeof(dev_class_t));
     451                list_initialize(&cl->devices);
     452                fibril_mutex_initialize(&cl->mutex);
     453        }
     454       
     455        return cl;
     456}
     457
     458/** Create device class info.
     459 *
     460 * @return              Device class info.
     461 */
     462static inline dev_class_info_t *create_dev_class_info(void)
     463{
     464        dev_class_info_t *info;
     465       
     466        info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
     467        if (info != NULL)
     468                memset(info, 0, sizeof(dev_class_info_t));
     469       
     470        return info;
     471}
     472
     473static inline size_t get_new_class_dev_idx(dev_class_t *cl)
     474{
     475        size_t dev_idx;
     476       
     477        fibril_mutex_lock(&cl->mutex);
     478        dev_idx = ++cl->curr_dev_idx;
     479        fibril_mutex_unlock(&cl->mutex);
     480       
     481        return dev_idx;
     482}
     483
    327484extern char *create_dev_name_for_class(dev_class_t *, const char *);
    328485extern dev_class_info_t *add_device_to_class(node_t *, dev_class_t *,
     
    333490extern dev_class_t *get_dev_class(class_list_t *, char *);
    334491extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *);
    335 extern void add_dev_class_no_lock(class_list_t *, dev_class_t *);
     492
     493static inline void add_dev_class_no_lock(class_list_t *class_list,
     494    dev_class_t *cl)
     495{
     496        list_append(&cl->link, &class_list->classes);
     497}
     498
    336499
    337500/* Devmap devices */
     
    340503extern node_t *find_devmap_class_device(class_list_t *, dev_handle_t);
    341504
    342 extern void class_add_devmap_device(class_list_t *, dev_class_info_t *);
    343 extern void tree_add_devmap_device(dev_tree_t *, node_t *);
     505static inline void class_add_devmap_device(class_list_t *class_list,
     506    dev_class_info_t *cli)
     507{
     508        unsigned long key = (unsigned long) cli->devmap_handle;
     509       
     510        fibril_rwlock_write_lock(&class_list->rwlock);
     511        hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
     512        fibril_rwlock_write_unlock(&class_list->rwlock);
     513}
     514
     515static inline void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
     516{
     517        unsigned long key = (unsigned long) node->devmap_handle;
     518        fibril_rwlock_write_lock(&tree->rwlock);
     519        hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
     520        fibril_rwlock_write_unlock(&tree->rwlock);
     521}
    344522
    345523#endif
  • uspace/srv/devman/main.c

    rcc8d91a ra649e73f  
    6666static driver_t *devman_driver_register(void)
    6767{
     68        printf(NAME ": devman_driver_register \n");
     69       
    6870        ipc_call_t icall;
    69         ipc_callid_t iid;
     71        ipc_callid_t iid = async_get_call(&icall);
    7072        driver_t *driver = NULL;
    71 
    72         printf(NAME ": devman_driver_register \n");
    73        
    74         iid = async_get_call(&icall);
     73       
    7574        if (IPC_GET_METHOD(icall) != DEVMAN_DRIVER_REGISTER) {
    7675                ipc_answer_0(iid, EREFUSED);
     
    8685                return NULL;
    8786        }
    88 
    8987        printf(NAME ": the %s driver is trying to register by the service.\n",
    9088            drv_name);
     
    9391        driver = find_driver(&drivers_list, drv_name);
    9492       
    95         if (driver == NULL) {
     93        if (NULL == driver) {
    9694                printf(NAME ": no driver named %s was found.\n", drv_name);
    9795                free(drv_name);
     
    148146        }
    149147       
    150         if (match_id == NULL) {
     148        if (NULL == match_id) {
    151149                printf(NAME ": ERROR: devman_receive_match_id - failed to "
    152150                    "allocate match id.\n");
     
    162160        rc = async_data_write_accept((void **) &match_id_str, true, 0, 0, 0, 0);
    163161        match_id->id = match_id_str;
    164         if (rc != EOK) {
     162        if (EOK != rc) {
    165163                delete_match_id(match_id);
    166164                printf(NAME ": devman_receive_match_id - failed to receive "
     
    183181 * @return              Zero on success, negative error code otherwise.
    184182 */
    185 static int devman_receive_match_ids(ipcarg_t match_count,
    186     match_id_list_t *match_ids)
     183static int
     184devman_receive_match_ids(ipcarg_t match_count, match_id_list_t *match_ids)
    187185{
    188186        int ret = EOK;
     
    207205       
    208206        fibril_rwlock_write_lock(&tree->rwlock);
    209         node_t *parent = find_dev_node_no_lock(&device_tree, parent_handle);
    210        
    211         if (parent == NULL) {
     207        node_t *parent =  find_dev_node_no_lock(&device_tree, parent_handle);
     208       
     209        if (NULL == parent) {
    212210                fibril_rwlock_write_unlock(&tree->rwlock);
    213211                ipc_answer_0(callid, ENOENT);
    214212                return;
    215         }
     213        }       
    216214       
    217215        char *dev_name = NULL;
    218216        int rc = async_data_write_accept((void **)&dev_name, true, 0, 0, 0, 0);
    219         if (rc != EOK) {
     217        if (EOK != rc) {
    220218                fibril_rwlock_write_unlock(&tree->rwlock);
    221219                ipc_answer_0(callid, rc);
     
    229227                ipc_answer_0(callid, ENOMEM);
    230228                return;
    231         }
    232 
     229        }       
    233230        fibril_rwlock_write_unlock(&tree->rwlock);
    234231       
     
    248245        /* Create devmap path and name for the device. */
    249246        char *devmap_pathname = NULL;
    250 
    251247        asprintf(&devmap_pathname, "%s/%s%c%s", DEVMAP_CLASS_NAMESPACE,
    252248            cli->dev_class->name, DEVMAP_SEPARATOR, cli->dev_name);
    253         if (devmap_pathname == NULL)
     249        if (NULL == devmap_pathname)
    254250                return;
    255251       
     
    283279       
    284280        node_t *dev = find_dev_node(&device_tree, handle);
    285         if (dev == NULL) {
     281        if (NULL == dev) {
    286282                ipc_answer_0(callid, ENOENT);
    287283                return;
     
    322318       
    323319        driver_t *driver = devman_driver_register();
    324         if (driver == NULL)
     320        if (NULL == driver)
    325321                return;
    326322       
     
    377373        free(pathname);
    378374
    379         if (dev == NULL) {
     375        if (NULL == dev) {
    380376                ipc_answer_0(iid, ENOENT);
    381377                return;
     
    408404                                ipc_answer_0(callid, ENOENT);
    409405                }
    410         }
    411 }
    412 
    413 static void devman_forward(ipc_callid_t iid, ipc_call_t *icall,
    414     bool drv_to_parent)
     406        }       
     407}
     408
     409static void
     410devman_forward(ipc_callid_t iid, ipc_call_t *icall, bool drv_to_parent)
    415411{
    416412        device_handle_t handle = IPC_GET_ARG2(*icall);
    417413       
    418414        node_t *dev = find_dev_node(&device_tree, handle);
    419         if (dev == NULL) {
     415        if (NULL == dev) {
    420416                printf(NAME ": devman_forward error - no device with handle %x "
    421417                    "was found.\n", handle);
     
    427423       
    428424        if (drv_to_parent) {
    429                 if (dev->parent != NULL)
     425                if (NULL != dev->parent)
    430426                        driver = dev->parent->drv;
    431         } else if (dev->state == DEVICE_USABLE) {
     427        } else if (DEVICE_USABLE == dev->state) {
    432428                driver = dev->drv;
    433                 assert(driver != NULL);
    434         }
    435        
    436         if (driver == NULL) {
     429                assert(NULL != driver);
     430        }
     431       
     432        if (NULL == driver) {
    437433                printf(NAME ": devman_forward error - the device is not in "
    438434                    "usable state.\n", handle);
     
    454450                return;
    455451        }
    456 
    457452        printf(NAME ": devman_forward: forward connection to device %s to "
    458453            "driver %s.\n", dev->pathname, driver->name);
     
    465460{
    466461        dev_handle_t devmap_handle = IPC_GET_METHOD(*icall);
    467         node_t *dev;
    468 
    469         dev = find_devmap_tree_device(&device_tree, devmap_handle);
    470         if (dev == NULL)
     462       
     463        node_t *dev = find_devmap_tree_device(&device_tree, devmap_handle);
     464        if (NULL == dev)
    471465                dev = find_devmap_class_device(&class_list, devmap_handle);
    472466       
    473         if (dev == NULL || dev->drv == NULL) {
     467        if (NULL == dev || NULL == dev->drv) {
    474468                ipc_answer_0(iid, ENOENT);
    475469                return;
    476470        }
    477471       
    478         if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) {
     472        if (DEVICE_USABLE != dev->state || dev->drv->phone <= 0) {
    479473                ipc_answer_0(iid, EINVAL);
    480474                return;
     
    499493         * passes device handle to the driver as an ipc method.)
    500494         */
    501         if (IPC_GET_METHOD(*icall) != IPC_M_CONNECT_ME_TO)
     495        if (IPC_M_CONNECT_ME_TO != IPC_GET_METHOD(*icall))
    502496                devman_connection_devmapper(iid, icall);
    503497
     
    537531        /* Initialize list of available drivers. */
    538532        init_driver_list(&drivers_list);
    539         if (lookup_available_drivers(&drivers_list,
    540             DRIVER_DEFAULT_STORE) == 0) {
     533        if (0 == lookup_available_drivers(&drivers_list,
     534            DRIVER_DEFAULT_STORE)) {
    541535                printf(NAME " no drivers found.");
    542536                return false;
    543537        }
    544 
    545538        printf(NAME ": devman_init  - list of drivers has been initialized.\n");
    546539
  • uspace/srv/devman/match.c

    rcc8d91a ra649e73f  
    5555                match_id_t *tmp_ma_id;
    5656       
    57                 if (str_cmp(drv_id->id, dev_id->id) == 0) {
     57                if (0 == str_cmp(drv_id->id, dev_id->id)) {
    5858                        /*
    5959                         * We found a match.
     
    6767                 * list of match ids.
    6868                 */
    69                 if (drv_link->next != drv_head) {
     69                if (drv_head != drv_link->next) {
    7070                        tmp_ma_id = list_get_instance(drv_link->next,
    7171                            match_id_t, link);
     
    7979                 * list of match ids.
    8080                 */
    81                 if (dev_link->next != dev_head) {
     81                if (dev_head != dev_link->next) {
    8282                        tmp_ma_id = list_get_instance(dev_link->next,
    8383                            match_id_t, link);
     
    9999                }
    100100               
    101         } while (drv_link->next != drv_head && dev_link->next != dev_head);
     101        } while (drv_head != drv_link->next && dev_head != dev_link->next);
    102102       
    103103        return 0;
  • uspace/srv/devman/util.c

    rcc8d91a ra649e73f  
    6161char *get_path_elem_end(char *path)
    6262{
    63         while (*path != '\0' && *path != '/')
     63        while (0 != *path && '/' != *path)
    6464                path++;
    6565        return path;
    6666}
    6767
    68 bool skip_spaces(char **buf)
    69 {
    70         while (isspace(**buf))
    71                 (*buf)++;
    72         return *buf != 0;
    73 }
    74 
    75 size_t get_nonspace_len(const char *str)
    76 {
    77         size_t len = 0;
    78        
    79         while(*str != '\0' && !isspace(*str)) {
    80                 len++;
    81                 str++;
    82         }
    83 
    84         return len;
    85 }
    86 
    87 void free_not_null(const void *ptr)
    88 {
    89         if (ptr != NULL)
    90                 free(ptr);
    91 }
    92 
    93 char *clone_string(const char *s)
    94 {
    95         size_t size = str_size(s) + 1;
    96         char *str;
    97        
    98         str = (char *) malloc(size);
    99         if (str != NULL)
    100                 str_cpy(str, size, s);
    101         return str;
    102 }
    103 
    104 void replace_char(char *str, char orig, char repl)
    105 {
    106         while (*str) {
    107                 if (*str == orig)
    108                         *str = repl;
    109                 str++;
    110         }
    111 }
    112 
    11368/** @}
    11469 */
  • uspace/srv/devman/util.h

    rcc8d91a ra649e73f  
    4141extern char *get_path_elem_end(char *);
    4242
    43 extern bool skip_spaces(char **);
    44 extern size_t get_nonspace_len(const char *);
    45 extern void free_not_null(const void *);
    46 extern char *clone_string(const char *);
    47 extern void replace_char(char *, char, char);
     43static inline bool skip_spaces(char **buf)
     44{
     45        while (isspace(**buf))
     46                (*buf)++;
     47        return *buf != 0;
     48}
     49
     50static inline size_t get_nonspace_len(const char *str)
     51{
     52        size_t len = 0;
     53       
     54        while(*str != 0 && !isspace(*str)) {
     55                len++;
     56                str++;
     57        }
     58        return len;
     59}
     60
     61static inline void free_not_null(const void *ptr)
     62{
     63        if (NULL != ptr)
     64                free(ptr);
     65}
     66
     67static inline char *clone_string(const char *s)
     68{
     69        size_t size = str_size(s) + 1;
     70        char *str;
     71       
     72        str = (char *) malloc(size);
     73        if (NULL != str)
     74                str_cpy(str, size, s);
     75        return str;
     76}
     77
     78static inline void replace_char(char *str, char orig, char repl)
     79{
     80        while (*str) {
     81                if (orig == *str)
     82                        *str = repl;
     83                str++;
     84        }
     85}
    4886
    4987#endif
Note: See TracChangeset for help on using the changeset viewer.