Changeset 9097c16a in mainline for uspace/drv/vhc/devices.c


Ignore:
Timestamp:
2011-02-04T13:14:14Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9e7cdf8
Parents:
11797d5 (diff), ff244e6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merged development

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/vhc/devices.c

    r11797d5 r9097c16a  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbvhc
    3030 * @{
    3131 */
     
    5858/** Create virtual device.
    5959 *
    60  * @param address USB address.
    6160 * @param phone Callback phone.
     61 * @param id Device id.
    6262 * @return New device.
    63  * @retval NULL Out of memory or address already occupied.
    64  */
    65 virtdev_connection_t *virtdev_add_device(int phone)
     63 * @retval NULL Out of memory.
     64 */
     65virtdev_connection_t *virtdev_add_device(int phone, sysarg_t id)
    6666{
    6767        virtdev_connection_t *dev = (virtdev_connection_t *)
    6868            malloc(sizeof(virtdev_connection_t));
     69        if (dev == NULL) {
     70                return NULL;
     71        }
     72
    6973        dev->phone = phone;
     74        dev->id = id;
    7075        list_append(&dev->link, &devices);
    7176       
     
    7378       
    7479        return dev;
     80}
     81
     82/** Find virtual device by id.
     83 *
     84 * @param id Device id.
     85 * @return Device with given id.
     86 * @retval NULL No such device.
     87 */
     88virtdev_connection_t *virtdev_find(sysarg_t id)
     89{
     90        link_t *pos;
     91        list_foreach(pos, &devices) {
     92                virtdev_connection_t *dev
     93                    = list_get_instance(pos, virtdev_connection_t, link);
     94                if (dev->id == id) {
     95                        return dev;
     96                }
     97        }
     98
     99        return NULL;
    75100}
    76101
     
    90115usb_transaction_outcome_t virtdev_send_to_all(transaction_t *transaction)
    91116{
     117        /* For easier debugging. */
     118        switch (transaction->type) {
     119                case USBVIRT_TRANSACTION_SETUP:
     120                case USBVIRT_TRANSACTION_OUT:
     121                        transaction->actual_len = transaction->len;
     122                        break;
     123                case USBVIRT_TRANSACTION_IN:
     124                        transaction->actual_len = 0;
     125                        break;
     126                default:
     127                        assert(false && "unreachable branch in switch()");
     128        }
     129        usb_transaction_outcome_t outcome = USB_OUTCOME_BABBLE;
     130
    92131        link_t *pos;
    93132        list_foreach(pos, &devices) {
     
    141180                        rc = (int)answer_rc;
    142181                }
     182
     183                /*
     184                 * If at least one device was able to accept this
     185                 * transaction and process it, we can announce success.
     186                 */
     187                if (rc == EOK) {
     188                        outcome = USB_OUTCOME_OK;
     189                }
    143190        }
    144191       
     
    149196        if (virtual_hub_device.address == transaction->target.address) {
    150197                size_t tmp;
    151                 dprintf(1, "sending `%s' transaction to hub",
     198                usb_log_debug2("Sending `%s' transaction to hub.\n",
    152199                    usbvirt_str_transaction_type(transaction->type));
    153200                switch (transaction->type) {
     
    165212                                    transaction->buffer, transaction->len,
    166213                                    &tmp);
    167                                 if (tmp < transaction->len) {
    168                                         transaction->len = tmp;
    169                                 }
     214                                transaction->actual_len = tmp;
    170215                                break;
    171216                               
     
    177222                                break;
    178223                }
    179                 dprintf(4, "transaction on hub processed...");
     224                outcome = USB_OUTCOME_OK;
    180225        }
    181226       
     
    184229         * real-life image.
    185230         */
    186         return USB_OUTCOME_OK;
     231        return outcome;
    187232}
    188233
Note: See TracChangeset for help on using the changeset viewer.