Changes in / [925e099:0e45e7f] in mainline


Ignore:
Location:
uspace
Files:
5 added
6 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ohci/Makefile

    r925e099 r0e45e7f  
    3333
    3434SOURCES = \
    35         iface.c \
     35        hc_iface.c \
    3636        batch.c \
    3737        main.c \
    38         hc.c \
    39         root_hub.c \
     38        ohci_hc.c \
     39        ohci_rh.c \
    4040        pci.c
    4141
  • uspace/drv/ohci/batch.c

    r925e099 r0e45e7f  
    3939
    4040#include "batch.h"
    41 #include "utils/malloc32.h"
    42 
    43 static void batch_call_in_and_dispose(batch_t *instance);
    44 static void batch_call_out_and_dispose(batch_t *instance);
    4541
    4642#define DEFAULT_ERROR_COUNT 3
    47 batch_t * batch_get(
    48     ddf_fun_t *fun,
    49                 usb_target_t target,
    50     usb_transfer_type_t transfer_type,
    51                 size_t max_packet_size,
    52     usb_speed_t speed,
    53                 char *buffer,
    54                 size_t buffer_size,
    55                 char *setup_buffer,
    56                 size_t setup_size,
    57     usbhc_iface_transfer_in_callback_t func_in,
    58     usbhc_iface_transfer_out_callback_t func_out,
    59                 void *arg,
    60                 device_keeper_t *manager
    61                 )
    62 {
    63 #define CHECK_NULL_DISPOSE_RETURN(ptr, message...) \
    64         if (ptr == NULL) { \
    65                 usb_log_error(message); \
    66                 if (instance) { \
    67                         batch_dispose(instance); \
    68                 } \
    69                 return NULL; \
    70         } else (void)0
    7143
    72         batch_t *instance = malloc(sizeof(batch_t));
    73         CHECK_NULL_DISPOSE_RETURN(instance,
    74             "Failed to allocate batch instance.\n");
    75         batch_init(instance, target, transfer_type, speed, max_packet_size,
    76             buffer, NULL, buffer_size, NULL, setup_size, func_in,
    77             func_out, arg, fun, NULL);
    78 
    79         if (buffer_size > 0) {
    80                 instance->transport_buffer = malloc32(buffer_size);
    81                 CHECK_NULL_DISPOSE_RETURN(instance->transport_buffer,
    82                     "Failed to allocate device accessible buffer.\n");
    83         }
    84 
    85         if (setup_size > 0) {
    86                 instance->setup_buffer = malloc32(setup_size);
    87                 CHECK_NULL_DISPOSE_RETURN(instance->setup_buffer,
    88                     "Failed to allocate device accessible setup buffer.\n");
    89                 memcpy(instance->setup_buffer, setup_buffer, setup_size);
    90         }
    91 
    92 
    93         return instance;
    94 }
    95 /*----------------------------------------------------------------------------*/
    96 void batch_dispose(batch_t *instance)
    97 {
    98         assert(instance);
    99         free32(instance->transport_buffer);
    100         free32(instance->setup_buffer);
    101         free(instance);
    102 }
    103 /*----------------------------------------------------------------------------*/
    104 void batch_control_write(batch_t *instance)
    105 {
    106         assert(instance);
    107         /* We are data out, we are supposed to provide data */
    108         memcpy(instance->transport_buffer, instance->buffer,
    109             instance->buffer_size);
    110         instance->next_step = batch_call_out_and_dispose;
    111         /* TODO: implement */
    112         usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance);
    113 }
    114 /*----------------------------------------------------------------------------*/
    115 void batch_control_read(batch_t *instance)
    116 {
    117         assert(instance);
    118         instance->next_step = batch_call_in_and_dispose;
    119         /* TODO: implement */
    120         usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance);
    121 }
    122 /*----------------------------------------------------------------------------*/
    123 void batch_interrupt_in(batch_t *instance)
    124 {
    125         assert(instance);
    126         instance->direction = USB_DIRECTION_IN;
    127         instance->next_step = batch_call_in_and_dispose;
    128         /* TODO: implement */
    129         usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance);
    130 }
    131 /*----------------------------------------------------------------------------*/
    132 void batch_interrupt_out(batch_t *instance)
    133 {
    134         assert(instance);
    135         instance->direction = USB_DIRECTION_OUT;
    136         /* We are data out, we are supposed to provide data */
    137         memcpy(instance->transport_buffer, instance->buffer,
    138             instance->buffer_size);
    139         instance->next_step = batch_call_out_and_dispose;
    140         /* TODO: implement */
    141         usb_log_debug("Batch(%p) INTERRUPT OUT initialized.\n", instance);
    142 }
    143 /*----------------------------------------------------------------------------*/
    144 void batch_bulk_in(batch_t *instance)
    145 {
    146         assert(instance);
    147         instance->direction = USB_DIRECTION_IN;
    148         instance->next_step = batch_call_in_and_dispose;
    149         /* TODO: implement */
    150         usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
    151 }
    152 /*----------------------------------------------------------------------------*/
    153 void batch_bulk_out(batch_t *instance)
    154 {
    155         assert(instance);
    156         instance->direction = USB_DIRECTION_IN;
    157         instance->next_step = batch_call_in_and_dispose;
    158         /* TODO: implement */
    159         usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
    160 }
    161 /*----------------------------------------------------------------------------*/
    162 /** Helper function calls callback and correctly disposes of batch structure.
    163  *
    164  * @param[in] instance Batch structure to use.
    165  */
    166 void batch_call_in_and_dispose(batch_t *instance)
    167 {
    168         assert(instance);
    169         batch_call_in(instance);
    170         batch_dispose(instance);
    171 }
    172 /*----------------------------------------------------------------------------*/
    173 /** Helper function calls callback and correctly disposes of batch structure.
    174  *
    175  * @param[in] instance Batch structure to use.
    176  */
    177 void batch_call_out_and_dispose(batch_t *instance)
    178 {
    179         assert(instance);
    180         batch_call_out(instance);
    181         batch_dispose(instance);
    182 }
    18344/**
    18445 * @}
  • uspace/drv/ohci/iface.h

    r925e099 r0e45e7f  
    4040#define NAME "ohci"
    4141
    42 extern usbhc_iface_t hc_iface;
     42extern usbhc_iface_t ohci_hc_iface;
    4343
    4444#endif
  • uspace/drv/ohci/main.c

    r925e099 r0e45e7f  
    4545#include "pci.h"
    4646#include "iface.h"
    47 #include "hc.h"
     47#include "ohci_hc.h"
    4848
    4949static int ohci_add_device(ddf_dev_t *device);
    50 static int get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
    51 {
    52         assert(handle);
    53   assert(fun != NULL);
    54 
    55   *handle = fun->handle;
    56   return EOK;
    57 }
    58 /*----------------------------------------------------------------------------*/
    59 static int get_address(
    60     ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)
    61 {
    62         assert(fun);
    63         device_keeper_t *manager = &fun_to_hc(fun)->manager;
    64   usb_address_t addr = device_keeper_find(manager, handle);
    65   if (addr < 0) {
    66     return addr;
    67   }
    68 
    69   if (address != NULL) {
    70     *address = addr;
    71   }
    72 
    73   return EOK;
    74 }
    7550/*----------------------------------------------------------------------------*/
    7651/** IRQ handling callback, identifies device
     
    8358{
    8459        assert(dev);
    85         hc_t *hc = (hc_t*)dev->driver_data;
     60        ohci_hc_t *hc = (ohci_hc_t*)dev->driver_data;
    8661        assert(hc);
    87         hc_interrupt(hc, 0);
     62        ohci_hc_interrupt(hc, 0);
    8863}
    8964/*----------------------------------------------------------------------------*/
     
    9671        .driver_ops = &ohci_driver_ops
    9772};
    98 /*----------------------------------------------------------------------------*/
    99 static usb_iface_t hc_usb_iface = {
    100         .get_address = get_address,
    101         .get_hc_handle = get_hc_handle,
     73static ddf_dev_ops_t hc_ops = {
     74        .interfaces[USBHC_DEV_IFACE] = &ohci_hc_iface,
    10275};
    103 /*----------------------------------------------------------------------------*/
    104 static ddf_dev_ops_t hc_ops = {
    105         .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
    106         .interfaces[USBHC_DEV_IFACE] = &hc_iface,
    107 };
     76
    10877/*----------------------------------------------------------------------------*/
    10978/** Initializes a new ddf driver instance of OHCI hcd.
     
    136105            "Failed(%d) disable legacy USB: %s.\n", ret, str_error(ret));
    137106
    138         hc_t *hcd = malloc(sizeof(hc_t));
     107        ohci_hc_t *hcd = malloc(sizeof(ohci_hc_t));
    139108        if (hcd == NULL) {
    140109                usb_log_error("Failed to allocate OHCI driver.\n");
     
    160129        }
    161130
    162         ret = hc_init(hcd, hc_fun, device, mem_reg_base, mem_reg_size, interrupts);
     131        ret = ohci_hc_init(hcd, hc_fun, mem_reg_base, mem_reg_size, interrupts);
    163132        if (ret != EOK) {
    164133                usb_log_error("Failed to initialize OHCI driver.\n");
     
    179148        hc_fun->driver_data = hcd;
    180149
    181         fid_t later = fibril_create((int(*)(void*))hc_register_hub, hcd);
    182         fibril_add_ready(later);
     150        /* TODO: register interrupt handler */
    183151
    184152        usb_log_info("Controlling new OHCI device `%s' (handle %llu).\n",
  • uspace/drv/uhci-hcd/batch.c

    r925e099 r0e45e7f  
    183183
    184184                        device_keeper_set_toggle(data->manager,
    185                             instance->target, instance->direction,
    186                             td_toggle(&data->tds[i]));
     185                            instance->target, td_toggle(&data->tds[i]));
    187186                        if (i > 0)
    188187                                goto substract_ret;
     
    239238{
    240239        assert(instance);
    241         instance->direction = USB_DIRECTION_IN;
    242240        batch_data(instance, USB_PID_IN);
    243241        instance->next_step = batch_call_in_and_dispose;
     
    254252{
    255253        assert(instance);
    256         instance->direction = USB_DIRECTION_OUT;
    257254        /* We are data out, we are supposed to provide data */
    258255        memcpy(instance->transport_buffer, instance->buffer,
     
    273270        assert(instance);
    274271        batch_data(instance, USB_PID_IN);
    275         instance->direction = USB_DIRECTION_IN;
    276272        instance->next_step = batch_call_in_and_dispose;
    277273        usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
     
    287283{
    288284        assert(instance);
    289         instance->direction = USB_DIRECTION_OUT;
    290285        /* We are data out, we are supposed to provide data */
    291286        memcpy(instance->transport_buffer, instance->buffer,
     
    311306
    312307        const bool low_speed = instance->speed == USB_SPEED_LOW;
    313         int toggle = device_keeper_get_toggle(
    314             data->manager, instance->target, instance->direction);
     308        int toggle = device_keeper_get_toggle(data->manager, instance->target);
    315309        assert(toggle == 0 || toggle == 1);
    316310
     
    343337        }
    344338        td_set_ioc(&data->tds[packet - 1]);
    345         device_keeper_set_toggle(data->manager, instance->target,
    346             instance->direction, toggle);
     339        device_keeper_set_toggle(data->manager, instance->target, toggle);
    347340}
    348341/*----------------------------------------------------------------------------*/
  • uspace/lib/usb/include/usb/host/batch.h

    r925e099 r0e45e7f  
    4646        usb_transfer_type_t transfer_type;
    4747        usb_speed_t speed;
    48         usb_direction_t direction;
    4948        usbhc_iface_transfer_in_callback_t callback_in;
    5049        usbhc_iface_transfer_out_callback_t callback_out;
  • uspace/lib/usb/include/usb/host/device_keeper.h

    r925e099 r0e45e7f  
    4444        usb_speed_t speed;
    4545        bool occupied;
    46         uint16_t toggle_status[2];
     46        uint16_t toggle_status;
    4747        devman_handle_t handle;
    4848};
     
    6363
    6464void device_keeper_reset_if_need(
    65     device_keeper_t *instance, usb_target_t target,
    66     const unsigned char *setup_data);
     65    device_keeper_t *instance, usb_target_t target, const unsigned char *setup_data);
    6766
    68 int device_keeper_get_toggle(
    69     device_keeper_t *instance, usb_target_t target, usb_direction_t direction);
     67int device_keeper_get_toggle(device_keeper_t *instance, usb_target_t target);
    7068
    71 int device_keeper_set_toggle(device_keeper_t *instance,
    72     usb_target_t target, usb_direction_t direction, bool toggle);
     69int device_keeper_set_toggle(
     70    device_keeper_t *instance, usb_target_t target, bool toggle);
    7371
    7472usb_address_t device_keeper_request(
  • uspace/lib/usb/src/host/batch.c

    r925e099 r0e45e7f  
    6262        instance->transfer_type = transfer_type;
    6363        instance->speed = speed;
    64         instance->direction = USB_DIRECTION_BOTH;
    6564        instance->callback_in = func_in;
    6665        instance->callback_out = func_out;
  • uspace/lib/usb/src/host/device_keeper.c

    r925e099 r0e45e7f  
    5555                instance->devices[i].occupied = false;
    5656                instance->devices[i].handle = 0;
    57                 instance->devices[i].toggle_status[0] = 0;
    58                 instance->devices[i].toggle_status[1] = 0;
     57                instance->devices[i].toggle_status = 0;
    5958        }
    6059}
     
    119118                if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) {
    120119                        /* endpoint number is < 16, thus first byte is enough */
    121                         instance->devices[target.address].toggle_status[0] &=
    122                             ~(1 << data[4]);
    123                         instance->devices[target.address].toggle_status[1] &=
     120                        instance->devices[target.address].toggle_status &=
    124121                            ~(1 << data[4]);
    125122                }
     
    130127                /* target must be device */
    131128                if ((data[0] & 0xf) == 0) {
    132                         instance->devices[target.address].toggle_status[0] = 0;
    133                         instance->devices[target.address].toggle_status[1] = 0;
     129                        instance->devices[target.address].toggle_status = 0;
    134130                }
    135131        break;
     
    144140 * @return Error code
    145141 */
    146 int device_keeper_get_toggle(
    147     device_keeper_t *instance, usb_target_t target, usb_direction_t direction)
    148 {
    149         assert(instance);
    150         /* only control pipes are bi-directional and those do not need toggle */
    151         if (direction == USB_DIRECTION_BOTH)
    152                 return ENOENT;
     142int device_keeper_get_toggle(device_keeper_t *instance, usb_target_t target)
     143{
     144        assert(instance);
    153145        int ret;
    154146        fibril_mutex_lock(&instance->guard);
     
    159151                ret = EINVAL;
    160152        } else {
    161                 ret = (instance->devices[target.address].toggle_status[direction]
     153                ret = (instance->devices[target.address].toggle_status
    162154                        >> target.endpoint) & 1;
    163155        }
     
    173165 * @return Error code.
    174166 */
    175 int device_keeper_set_toggle(device_keeper_t *instance,
    176     usb_target_t target, usb_direction_t direction, bool toggle)
    177 {
    178         assert(instance);
    179         /* only control pipes are bi-directional and those do not need toggle */
    180         if (direction == USB_DIRECTION_BOTH)
    181                 return ENOENT;
     167int device_keeper_set_toggle(
     168    device_keeper_t *instance, usb_target_t target, bool toggle)
     169{
     170        assert(instance);
    182171        int ret;
    183172        fibril_mutex_lock(&instance->guard);
     
    189178        } else {
    190179                if (toggle) {
    191                         instance->devices[target.address].toggle_status[direction]
    192                             |= (1 << target.endpoint);
     180                        instance->devices[target.address].toggle_status |= (1 << target.endpoint);
    193181                } else {
    194                         instance->devices[target.address].toggle_status[direction]
    195                             &= ~(1 << target.endpoint);
     182                        instance->devices[target.address].toggle_status &= ~(1 << target.endpoint);
    196183                }
    197184                ret = EOK;
     
    228215        instance->devices[new_address].occupied = true;
    229216        instance->devices[new_address].speed = speed;
    230         instance->devices[new_address].toggle_status[0] = 0;
    231         instance->devices[new_address].toggle_status[1] = 0;
     217        instance->devices[new_address].toggle_status = 0;
    232218        instance->last_address = new_address;
    233219        fibril_mutex_unlock(&instance->guard);
Note: See TracChangeset for help on using the changeset viewer.