Changeset e0ba26b in mainline for uspace/drv/vhc


Ignore:
Timestamp:
2011-01-25T19:20:26Z (15 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
192a0063
Parents:
a088d15 (diff), 68a68705 (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 vojtechhorky/ - various fixes

The merge includes following changes

  • USB transaction outcome is propagated to clients
  • virtual host controller handles device unplugging
  • Doxygen documentation fixes
Location:
uspace/drv/vhc
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/vhc/conn.h

    ra088d15 re0ba26b  
    5151
    5252void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);
     53void on_client_close(device_t *);
    5354
    5455
  • uspace/drv/vhc/conndev.c

    ra088d15 re0ba26b  
    8888                int callback = IPC_GET_ARG5(*icall);
    8989                virtdev_connection_t *dev
    90                     = virtdev_add_device(callback);
     90                    = virtdev_add_device(callback, (sysarg_t)fibril_get_id());
    9191                if (!dev) {
    9292                        ipc_answer_0(icallid, EEXISTS);
     
    9999                int rc = get_device_name(callback, devname, DEVICE_NAME_MAXLENGTH);
    100100
    101                 dprintf(0, "virtual device connected (name: %s)",
    102                     rc == EOK ? devname : "<unknown>");
    103 
    104                 /* FIXME: destroy the device when the client disconnects. */
     101                dprintf(0, "virtual device connected (name: %s, id: %x)",
     102                    rc == EOK ? devname : "<unknown>", dev->id);
    105103
    106104                return;
     
    110108}
    111109
     110/** Callback for DDF when client disconnects.
     111 *
     112 * @param d Device the client was connected to.
     113 */
     114void on_client_close(device_t *d)
     115{
     116        /*
     117         * Maybe a virtual device is being unplugged.
     118         */
     119        virtdev_connection_t *dev = virtdev_find((sysarg_t)fibril_get_id());
     120        if (dev == NULL) {
     121                return;
     122        }
     123
     124        dprintf(0, "virtual device disconnected (id: %x)", dev->id);
     125        virtdev_destroy_device(dev);
     126}
     127
    112128
    113129/**
  • uspace/drv/vhc/devices.c

    ra088d15 re0ba26b  
    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) {
     
    140179                        transaction->actual_len = IPC_GET_ARG1(answer_data);
    141180                        rc = (int)answer_rc;
     181                }
     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;
    142189                }
    143190        }
     
    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                               
     
    178223                }
    179224                dprintf(4, "transaction on hub processed...");
     225                outcome = USB_OUTCOME_OK;
    180226        }
    181227       
     
    184230         * real-life image.
    185231         */
    186         return USB_OUTCOME_OK;
     232        return outcome;
    187233}
    188234
  • uspace/drv/vhc/devices.h

    ra088d15 re0ba26b  
    4545        /** Phone used when sending data to device. */
    4646        int phone;
     47        /** Unique identification. */
     48        sysarg_t id;
    4749        /** Linked-list handle. */
    4850        link_t link;
    4951} virtdev_connection_t;
    5052
    51 virtdev_connection_t *virtdev_add_device(int);
    52 virtdev_connection_t *virtdev_get_mine(void);
     53virtdev_connection_t *virtdev_add_device(int, sysarg_t);
     54virtdev_connection_t *virtdev_find(sysarg_t);
    5355void virtdev_destroy_device(virtdev_connection_t *);
    5456usb_transaction_outcome_t virtdev_send_to_all(transaction_t *);
  • uspace/drv/vhc/hcd.c

    ra088d15 re0ba26b  
    6969        .interfaces[USBHC_DEV_IFACE] = &vhc_iface,
    7070        .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
     71        .close = on_client_close,
    7172        .default_handler = default_connection_handler
    7273};
  • uspace/drv/vhc/hub/hub.c

    ra088d15 re0ba26b  
    155155}
    156156
     157/** Disconnects a device from a hub.
     158 *
     159 * @param hub Hub the device was connected to.
     160 * @param device Device to be disconnected.
     161 * @return Error code.
     162 */
     163int hub_disconnect_device(hub_t *hub, void *device)
     164{
     165        size_t index = hub_find_device(hub, device);
     166        if (index == (size_t) -1) {
     167                return ENOENT;
     168        }
     169
     170        hub_port_t *port = &hub->ports[index];
     171
     172        port->connected_device = NULL;
     173        port->state = HUB_PORT_STATE_DISCONNECTED;
     174        set_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION);
     175
     176        return EOK;
     177}
     178
    157179/** Find port device is connected to.
    158180 *
     
    173195        }
    174196
    175         return 0;
     197        return -1;
    176198}
    177199
  • uspace/drv/vhc/hub/hub.h

    ra088d15 re0ba26b  
    9494void hub_init(hub_t *);
    9595size_t hub_connect_device(hub_t *, void *);
     96int hub_disconnect_device(hub_t *, void *);
    9697size_t hub_find_device(hub_t *, void *);
    9798void hub_acquire(hub_t *);
  • uspace/drv/vhc/hub/virthub.c

    ra088d15 re0ba26b  
    203203
    204204        hub_acquire(hub);
    205         /* TODO: implement. */
     205        hub_disconnect_device(hub, conn);
    206206        hub_release(hub);
    207207
Note: See TracChangeset for help on using the changeset viewer.