Changeset 355f7c2 in mainline


Ignore:
Timestamp:
2010-10-25T07:44:02Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ca07cd3
Parents:
7a7bfeb3
Message:

Better debugging support in VHCD

Also, added some missing comments.

Location:
uspace
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbvirt/ids.h

    r7a7bfeb3 r355f7c2  
    5050} usbvirt_transaction_type_t;
    5151
     52const char *usbvirt_str_transaction_type(usbvirt_transaction_type_t type);
    5253
    5354#endif
  • uspace/lib/usbvirt/transaction.c

    r7a7bfeb3 r355f7c2  
    3838#include <mem.h>
    3939
     40#include "ids.h"
    4041#include "private.h"
    4142
    4243static usb_direction_t setup_transaction_direction(usb_endpoint_t, void *, size_t);
    4344static void process_control_transfer(usb_endpoint_t, usbvirt_control_transfer_t *);
     45
     46/** Convert virtual USB transaction type to string.
     47 */
     48const char *usbvirt_str_transaction_type(usbvirt_transaction_type_t type)
     49{
     50        switch (type) {
     51                case USBVIRT_TRANSACTION_SETUP:
     52                        return "setup";
     53                case USBVIRT_TRANSACTION_IN:
     54                        return "in";
     55                case USBVIRT_TRANSACTION_OUT:
     56                        return "out";
     57                default:
     58                        return "unknown";
     59        }
     60}
    4461
    4562int transaction_setup(usbvirt_device_t *device, usb_endpoint_t endpoint,
  • uspace/srv/hw/bus/usb/hcd/virtual/Makefile

    r7a7bfeb3 r355f7c2  
    3535        conndev.c \
    3636        connhost.c \
     37        debug.c \
    3738        devices.c \
    3839        hc.c \
  • uspace/srv/hw/bus/usb/hcd/virtual/conndev.c

    r7a7bfeb3 r355f7c2  
    4444/** Connection handler for communcation with virtual device.
    4545 *
     46 * This function also takes care of proper phone hung-up.
     47 *
    4648 * @param phone_hash Incoming phone hash.
    4749 * @param dev Virtual device handle.
     
    5153        assert(dev != NULL);
    5254       
    53         dprintf("phone%#x: virtual device %d connected",
    54             phone_hash, dev->id);
     55        dprintf(0, "virtual device connected through phone %#x", phone_hash);
    5556       
    5657        while (true) {
     
    6465                                ipc_hangup(dev->phone);
    6566                                ipc_answer_0(callid, EOK);
    66                                 dprintf("phone%#x: device %d hang-up",
    67                                     phone_hash, dev->id);
     67                                dprintf(0, "phone%#x: device hung-up",
     68                                    phone_hash);
    6869                                return;
    6970                       
     
    7374                       
    7475                        default:
     76                                dprintf_inval_call(2, call, phone_hash);
    7577                                ipc_answer_0(callid, EINVAL);
    7678                                break;
  • uspace/srv/hw/bus/usb/hcd/virtual/connhost.c

    r7a7bfeb3 r355f7c2  
    5656static void out_callback(void * buffer, size_t len, usb_transaction_outcome_t outcome, void * arg)
    5757{
    58         dprintf("out_callback(buffer, %u, %d, %p)", len, outcome, arg);
    59         (void)len;
     58        dprintf(2, "out_callback(buffer, %u, %d, %p)", len, outcome, arg);
     59       
    6060        transaction_details_t * trans = (transaction_details_t *)arg;
    6161       
     
    6363       
    6464        free(trans);
    65         free(buffer);
     65        if (buffer) {
     66                free(buffer);
     67        }
    6668}
    6769
     
    7072static void in_callback(void * buffer, size_t len, usb_transaction_outcome_t outcome, void * arg)
    7173{
    72         dprintf("in_callback(buffer, %u, %d, %p)", len, outcome, arg);
     74        dprintf(2, "in_callback(buffer, %u, %d, %p)", len, outcome, arg);
    7375        transaction_details_t * trans = (transaction_details_t *)arg;
    7476       
     
    116118        };
    117119       
    118         dprintf("pretending transfer to function (dev=%d:%d)",
     120        dprintf(1, "pretending transfer to function (dev=%d:%d)",
    119121            target.address, target.endpoint);
    120122       
     
    144146        trans->handle = handle;
    145147       
    146         dprintf("adding transaction to HC", NAME);
    147148        hc_add_transaction_to_device(setup_transaction, target,
    148149            buffer, len,
     
    150151       
    151152        ipc_answer_1(iid, EOK, handle);
    152         dprintf("transfer to function scheduled (handle %d)", handle);
     153        dprintf(2, "transfer to function scheduled (handle %d)", handle);
    153154}
    154155
     
    163164        size_t len = IPC_GET_ARG3(icall);
    164165       
    165         dprintf("pretending transfer from function (dev=%d:%d)",
     166        dprintf(1, "pretending transfer from function (dev=%d:%d)",
    166167            target.address, target.endpoint);
    167168       
     
    183184        trans->handle = handle;
    184185       
    185         dprintf("adding transaction to HC", NAME);
    186186        hc_add_transaction_from_device(target,
    187187            buffer, len,
     
    189189       
    190190        ipc_answer_1(iid, EOK, handle);
    191         dprintf("transfer from function scheduled (handle %d)", handle);
     191        dprintf(2, "transfer from function scheduled (handle %d)", handle);
    192192}
    193193
     
    197197 * By host is typically meant top-level USB driver.
    198198 *
     199 * This function also takes care of proper phone hung-up.
     200 *
    199201 * @param phone_hash Incoming phone hash.
    200202 * @param host_phone Callback phone to host.
     
    204206        assert(host_phone > 0);
    205207       
    206         dprintf("phone%#x: host connected", phone_hash);
     208        dprintf(0, "host connected through phone %#x", phone_hash);
    207209       
    208210       
     
    217219                                ipc_hangup(host_phone);
    218220                                ipc_answer_0(callid, EOK);
    219                                 dprintf("phone%#x: host hang-up", phone_hash);
     221                                dprintf(0, "phone%#x: host hung-up",
     222                                    phone_hash);
    220223                                return;
    221224                       
     
    223226                                ipc_answer_0(callid, ELIMIT);
    224227                                break;
    225 
    226                        
    227                         case IPC_M_USB_HCD_SEND_DATA:
    228                                 handle_data_to_function(callid, call,
    229                                     false, host_phone);
    230                                 break;
    231                        
    232                         case IPC_M_USB_HCD_RECEIVE_DATA:
    233                                 handle_data_from_function(callid, call, host_phone);
    234                                 break;
    235228                       
    236229                        case IPC_M_USB_HCD_TRANSACTION_SIZE:
     
    271264                       
    272265                        default:
     266                                dprintf_inval_call(2, call, phone_hash);
    273267                                ipc_answer_0(callid, EINVAL);
    274268                                break;
  • uspace/srv/hw/bus/usb/hcd/virtual/hc.c

    r7a7bfeb3 r355f7c2  
    6868static link_t transaction_list;
    6969
    70 #define TRANSACTION_FORMAT "T[%d:%d (%d) %d]"
     70#define TRANSACTION_FORMAT "T[%d:%d %s (%d)]"
    7171#define TRANSACTION_PRINTF(t) \
    7272        (t).target.address, (t).target.endpoint, \
    73         (int)(t).len, (int)(t).type
     73        usbvirt_str_transaction_type((t).type), \
     74        (int)(t).len
    7475
    7576#define transaction_get_instance(lnk) \
     
    8889    usb_transaction_outcome_t outcome)
    8990{
    90         dprintf("processing transaction " TRANSACTION_FORMAT ", outcome: %s",
     91        dprintf(3, "processing transaction " TRANSACTION_FORMAT ", outcome: %s",
    9192            TRANSACTION_PRINTF(*transaction),
    9293            usb_str_transaction_outcome(outcome));
     
    113114                }
    114115               
    115                 dprintf("virtual hub has address %d:*.", virthub_dev.address);
     116                char ports[HUB_PORT_COUNT + 2];
     117                hub_get_port_statuses(ports, HUB_PORT_COUNT + 1);
     118                dprintf(3, "virtual hub: addr=%d ports=%s",
     119                    virthub_dev.address, ports);
    116120               
    117121                link_t *first_transaction_link = transaction_list.next;
     
    120124                list_remove(first_transaction_link);
    121125               
    122                 dprintf("processing transaction " TRANSACTION_FORMAT "",
     126                dprintf(3, "processing transaction " TRANSACTION_FORMAT "",
    123127                    TRANSACTION_PRINTF(*transaction));
    124128               
     
    148152        transaction->callback = callback;
    149153        transaction->callback_arg = arg;
     154       
     155        dprintf(1, "creating transaction " TRANSACTION_FORMAT,
     156            TRANSACTION_PRINTF(*transaction));
    150157       
    151158        return transaction;
  • uspace/srv/hw/bus/usb/hcd/virtual/hcd.c

    r7a7bfeb3 r355f7c2  
    5757       
    5858        ipc_answer_0(iid, EOK);
    59         printf("%s: new client connected (phone %#x).\n", NAME, phone_hash);
    6059       
    6160        while (true) {
     
    112111                 * No other methods could be served now.
    113112                 */
     113                dprintf_inval_call(1, call, phone_hash);
    114114                ipc_answer_0(callid, ENOTSUP);
    115115        }
     
    117117
    118118int main(int argc, char * argv[])
    119 {
    120         printf("%s: Virtual USB host controller driver.\n", NAME);
     119{       
     120        printf("%s: virtual USB host controller driver.\n", NAME);
     121       
     122        int i;
     123        for (i = 1; i < argc; i++) {
     124                if (str_cmp(argv[i], "-d") == 0) {
     125                        debug_level++;
     126                }
     127        }
    121128       
    122129        int rc;
     
    138145        hub_init();
    139146       
    140         printf("%s: accepting connections.\n", NAME);
     147        printf("%s: accepting connections [devmap=%s, debug=%d].\n", NAME,
     148            DEVMAP_PATH, debug_level);
    141149        hc_manager();
    142150       
  • uspace/srv/hw/bus/usb/hcd/virtual/hub.c

    r7a7bfeb3 r355f7c2  
    4343#include "hubintern.h"
    4444
    45 hub_port_t hub_ports[HUB_PORT_COUNT];
    4645
    4746/** Standard device descriptor. */
     
    108107};
    109108
     109/** All hub configuration descriptors. */
    110110static usbvirt_device_configuration_extras_t extra_descriptors[] = {
    111111        {
     
    137137};
    138138
     139/** Hub as a virtual device. */
    139140usbvirt_device_t virthub_dev = {
    140141        .ops = &hub_ops,
    141142        .descriptors = &descriptors,
    142143};
    143  
     144
     145/** Hub device. */
    144146hub_device_t hub_dev;
    145147
     148/** Initialize virtual hub. */
    146149void hub_init(void)
    147150{
     
    156159       
    157160        usbvirt_connect_local(&virthub_dev);
    158         //virthub_dev.send_data = send_data;
    159        
    160         printf("%s: virtual hub (%d ports) created.\n", NAME, HUB_PORT_COUNT);
    161 }
    162 
     161       
     162        dprintf(1, "virtual hub (%d ports) created", HUB_PORT_COUNT);
     163}
     164
     165/** Connect device to the hub.
     166 *
     167 * @param device Device to be connected.
     168 * @return Port where the device was connected to.
     169 */
    163170size_t hub_add_device(virtdev_connection_t *device)
    164171{
     
    191198}
    192199
    193 
     200/** Disconnect device from the hub. */
    194201void hub_remove_device(virtdev_connection_t *device)
    195202{
     
    209216}
    210217
     218/** Tell whether device port is open.
     219 *
     220 * @return Whether communication to and from the device can go through the hub.
     221 */
    211222bool hub_can_device_signal(virtdev_connection_t * device)
    212223{
     
    221232}
    222233
     234/** Format hub port status.
     235 *
     236 * @param result Buffer where to store status string.
     237 * @param len Number of characters that is possible to store in @p result
     238 *      (excluding trailing zero).
     239 */
     240void hub_get_port_statuses(char *result, size_t len)
     241{
     242        if (len > HUB_PORT_COUNT) {
     243                len = HUB_PORT_COUNT;
     244        }
     245        size_t i;
     246        for (i = 0; i < len; i++) {
     247                result[i] = hub_port_state_as_char(hub_dev.ports[i].state);
     248        }
     249        result[len] = 0;
     250}
    223251
    224252/**
  • uspace/srv/hw/bus/usb/hcd/virtual/hub.h

    r7a7bfeb3 r355f7c2  
    5151void hub_remove_device(virtdev_connection_t *);
    5252bool hub_can_device_signal(virtdev_connection_t *);
     53void hub_get_port_statuses(char *result, size_t len);
    5354
    5455#endif
  • uspace/srv/hw/bus/usb/hcd/virtual/hubintern.h

    r7a7bfeb3 r355f7c2  
    3838#include "hub.h"
    3939
     40/** Endpoint number for status change pipe. */
    4041#define HUB_STATUS_CHANGE_PIPE 1
     42/** Configuration value for hub configuration. */
    4143#define HUB_CONFIGURATION_ID 1
    4244
     
    6668} __attribute__ ((packed)) hub_descriptor_t;
    6769
     70/** Hub port internal state.
     71 * Some states (e.g. port over current) are not covered as they are not
     72 * simulated at all.
     73 */
    6874typedef enum {
    6975        HUB_PORT_STATE_NOT_CONFIGURED,
     
    7884} hub_port_state_t;
    7985
     86/** Convert hub port state to a char. */
     87static inline char hub_port_state_as_char(hub_port_state_t state) {
     88        switch (state) {
     89                case HUB_PORT_STATE_NOT_CONFIGURED:
     90                        return '-';
     91                case HUB_PORT_STATE_POWERED_OFF:
     92                        return 'O';
     93                case HUB_PORT_STATE_DISCONNECTED:
     94                        return 'X';
     95                case HUB_PORT_STATE_DISABLED:
     96                        return 'D';
     97                case HUB_PORT_STATE_RESETTING:
     98                        return 'R';
     99                case HUB_PORT_STATE_ENABLED:
     100                        return 'E';
     101                case HUB_PORT_STATE_SUSPENDED:
     102                        return 'S';
     103                case HUB_PORT_STATE_RESUMING:
     104                        return 'F';
     105                default:
     106                        return '?';
     107        }
     108}
     109
     110/** Hub status change mask bits. */
    80111typedef enum {
    81112        HUB_STATUS_C_PORT_CONNECTION = (1 << 0),
     
    87118} hub_status_change_t;
    88119
     120/** Hub port information. */
    89121typedef struct {
    90122        virtdev_connection_t *device;
     
    93125} hub_port_t;
    94126
     127/** Hub device type. */
    95128typedef struct {
    96129        hub_port_t ports[HUB_PORT_COUNT];
  • uspace/srv/hw/bus/usb/hcd/virtual/hubops.c

    r7a7bfeb3 r355f7c2  
    4343#include "hubintern.h"
    4444
     45/** Produce a byte from bit values.
     46 */
    4547#define MAKE_BYTE(b0, b1, b2, b3, b4, b5, b6, b7) \
    4648        (( \
     
    6365    void *buffer, size_t size, size_t *actual_size);
    6466
    65 
     67/** Standard USB requests. */
    6668static usbvirt_standard_device_request_ops_t standard_request_ops = {
    6769        .on_get_status = NULL,
     
    7880};
    7981
    80 
     82/** Hub operations. */
    8183usbvirt_device_ops_t hub_ops = {
    8284        .standard_request_ops = &standard_request_ops,
     
    8688};
    8789
     90/** Callback for GET_DESCRIPTOR request. */
    8891static int on_get_descriptor(struct usbvirt_device *dev,
    8992    usb_device_request_setup_packet_t *request, uint8_t *data)
     
    124127}
    125128
     129/** Get access to a port or return with EINVAL. */
    126130#define _GET_PORT(portvar, index) \
    127131        do { \
     
    274278
    275279
    276 
    277 
     280/** Callback for class request. */
    278281static int on_class_request(struct usbvirt_device *dev,
    279282    usb_device_request_setup_packet_t *request, uint8_t *data)
    280283{       
    281         printf("%s: hub class request (%d)\n", NAME, (int) request->request);
     284        dprintf(2, "hub class request (%d)\n", (int) request->request);
    282285       
    283286        uint8_t recipient = request->request_type & 31;
     
    287290        do { \
    288291                if (!(cond)) { \
    289                         printf("%s: WARN: invalid class request (%s not met).\n", \
     292                        dprintf(0, "WARN: invalid class request (%s not met).\n", \
    290293                            NAME, #cond); \
    291294                        return EINVAL; \
     
    347350}
    348351
     352/** Callback for data request. */
    349353static int on_data_request(struct usbvirt_device *dev,
    350354    usb_endpoint_t endpoint,
    351355    void *buffer, size_t size, size_t *actual_size)
    352356{
     357        if (endpoint != HUB_STATUS_CHANGE_PIPE) {
     358                return EINVAL;
     359        }
     360       
    353361        uint8_t change_map = 0;
    354362       
  • uspace/srv/hw/bus/usb/hcd/virtual/vhcd.h

    r7a7bfeb3 r355f7c2  
    3636#define VHCD_VHCD_H_
    3737
    38 #include <stdio.h>
    39 
    4038#define NAME "hcd-virt"
    4139#define NAMESPACE "usb"
     
    4341#define DEVMAP_PATH NAMESPACE "/" NAME
    4442
    45 /** Debugging printf.
    46  * @see printf
    47  */
    48 static inline void dprintf(const char * format, ...)
    49 {
    50         printf("%s:   ", NAME);
    51         va_list args;
    52         va_start(args, format);
    53         vprintf(format, args);
    54         va_end(args);
    55         printf("\n");
    56 }
     43extern int debug_level;
     44void dprintf(int, const char *, ...);
     45void dprintf_inval_call(int, ipc_call_t, ipcarg_t);
    5746
    5847#endif
Note: See TracChangeset for help on using the changeset viewer.