Changes in / [7964475:cdc1aa1] in mainline


Ignore:
Location:
uspace
Files:
2 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhub/main.c

    r7964475 rcdc1aa1  
    3030#include <errno.h>
    3131#include "usbhub.h"
    32 #include "usbhub_private.h"
    33 
    34 
    35 usb_general_list_t usb_hub_list;
    3632
    3733static driver_ops_t hub_driver_ops = {
     
    4642int main(int argc, char *argv[])
    4743{
    48         usb_lst_init(&usb_hub_list);
    4944        return driver_main(&hub_driver);
    5045}
  • uspace/drv/usbhub/usbhub.h

    r7964475 rcdc1aa1  
    3838#define NAME "usbhub"
    3939
    40 #include "usb/hcdhubd.h"
    41 
    42 
    43 
    44 /** Information about attached hub. */
    45 typedef struct {
    46         /** Number of ports. */
    47         int port_count;
    48         /** General device info. */
    49         usb_hcd_attached_device_info_t * device;
    50 } usb_hub_info_t;
    51 
    52 
    5340int usb_add_hub_device(device_t *);
    5441
  • uspace/drv/usbhub/utils.c

    r7964475 rcdc1aa1  
    4343#include <usb/classes/hub.h>
    4444#include "usbhub.h"
    45 #include "usbhub_private.h"
    46 #include "port_status.h"
    47 #include <usb/devreq.h>
    4845
    4946static void check_hub_changes(void);
     
    5754//*********************************************
    5855
    59 //hub descriptor utils
    6056void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor) {
    6157        //base size
     
    8985        uint8_t * sdescriptor = (uint8_t*) serialized_descriptor;
    9086        if (sdescriptor[1] != USB_DESCTYPE_HUB) return NULL;
    91         usb_hub_descriptor_t * result = usb_new(usb_hub_descriptor_t);
     87        usb_hub_descriptor_t * result = (usb_hub_descriptor_t*) malloc(sizeof (usb_hub_descriptor_t));
    9288        //uint8_t size = sdescriptor[0];
    9389        result->ports_count = sdescriptor[2];
     
    106102}
    107103
    108 //control transactions
    109 int usb_drv_sync_control_read(
    110     int phone, usb_target_t target,
    111     usb_device_request_setup_packet_t * request,
    112     void * rcvd_buffer, size_t rcvd_size, size_t * actual_size
    113 ){
    114         usb_handle_t handle;
    115         int opResult;
    116         //setup
    117         opResult = usb_drv_async_control_read_setup(phone, target,
    118         request, sizeof(usb_device_request_setup_packet_t),
    119         &handle);
    120         if(opResult!=EOK){
    121                 return opResult;
    122         }
    123         opResult = usb_drv_async_wait_for(handle);
    124         if(opResult!=EOK){
    125                 return opResult;
    126         }
    127         //read
    128         opResult = usb_drv_async_control_read_data(phone, target,
    129             rcvd_buffer,  rcvd_size, actual_size,
    130             &handle);
    131         if(opResult!=EOK){
    132                 return opResult;
    133         }
    134         opResult = usb_drv_async_wait_for(handle);
    135         if(opResult!=EOK){
    136                 return opResult;
    137         }
    138         //finalize
    139         opResult = usb_drv_async_control_read_status(phone, target,
    140             &handle);
    141         if(opResult!=EOK){
    142                 return opResult;
    143         }
    144         opResult = usb_drv_async_wait_for(handle);
    145         if(opResult!=EOK){
    146                 return opResult;
    147         }
    148         return EOK;
    149 }
    150 
    151 
    152 int usb_drv_sync_control_write(
    153     int phone, usb_target_t target,
    154     usb_device_request_setup_packet_t * request,
    155     void * sent_buffer, size_t sent_size
    156 ){
    157         usb_handle_t handle;
    158         int opResult;
    159         //setup
    160         opResult = usb_drv_async_control_write_setup(phone, target,
    161         request, sizeof(usb_device_request_setup_packet_t),
    162         &handle);
    163         if(opResult!=EOK){
    164                 return opResult;
    165         }
    166         opResult = usb_drv_async_wait_for(handle);
    167         if(opResult!=EOK){
    168                 return opResult;
    169         }
    170         //write
    171         opResult = usb_drv_async_control_write_data(phone, target,
    172         sent_buffer, sent_size,
    173         &handle);
    174         if(opResult!=EOK){
    175                 return opResult;
    176         }
    177         opResult = usb_drv_async_wait_for(handle);
    178         if(opResult!=EOK){
    179                 return opResult;
    180         }
    181         //finalize
    182         opResult = usb_drv_async_control_write_status(phone, target,
    183         &handle);
    184         if(opResult!=EOK){
    185                 return opResult;
    186         }
    187         opResult = usb_drv_async_wait_for(handle);
    188         if(opResult!=EOK){
    189                 return opResult;
    190         }
    191         return EOK;
    192 }
    193 
    194 //list implementation
    195 
    196 usb_general_list_t * usb_lst_create(void){
    197         usb_general_list_t* result = usb_new(usb_general_list_t);
    198         usb_lst_init(result);
    199         return result;
    200 }
    201 
    202 void usb_lst_init(usb_general_list_t * lst){
    203         lst->prev = lst;
    204         lst->next = lst;
    205         lst->data = NULL;
    206 }
    207 
    208 void usb_lst_prepend(usb_general_list_t* item, void* data){
    209         usb_general_list_t* appended = usb_new(usb_general_list_t);
    210         appended->data=data;
    211         appended->next=item;
    212         appended->prev=item->prev;
    213         item->prev->next = appended;
    214         item->prev = appended;
    215 }
    216 
    217 void usb_lst_append(usb_general_list_t* item, void* data){
    218         usb_general_list_t* appended =usb_new(usb_general_list_t);
    219         appended->data=data;
    220         appended->next=item->next;
    221         appended->prev=item;
    222         item->next->prev = appended;
    223         item->next = appended;
    224 }
    225 
    226 
    227 void usb_lst_remove(usb_general_list_t* item){
    228         item->next->prev = item->prev;
    229         item->prev->next = item->next;
    230 }
    231 
    232 
    233104
    234105//*********************************************
     
    238109//*********************************************
    239110
    240 usb_hub_info_t * usb_create_hub_info(device_t * device) {
    241         usb_hub_info_t* result = usb_new(usb_hub_info_t);
    242         //result->device = device;
    243         result->port_count = -1;
    244 
    245         //get hc connection
    246         int hc = usb_drv_hc_connect(NULL, 0);
    247         printf("[usb_hub] phone to hc = %d\n",hc);
    248         if (hc < 0) {
    249                 return result;
    250         }
    251         //get some hub info
    252 
    253         usb_address_t addr = usb_drv_get_my_address(hc,device);
    254         printf("[usb_hub] addres of newly created hub = %d\n",addr);
    255         /*if(addr<0){
    256                 //return result;
    257                
    258         }*/
    259         result->device = usb_new(usb_hcd_attached_device_info_t);
    260         result->device->address=addr;
    261         //hub configuration?
    262         printf("[usb_hub] hub info created\n");
    263 
    264        
    265        
     111usb_hcd_hub_info_t * usb_create_hub_info(device_t * device) {
     112        usb_hcd_hub_info_t* result = (usb_hcd_hub_info_t*) malloc(sizeof (usb_hcd_hub_info_t));
     113
    266114        return result;
    267115}
     
    274122int usb_add_hub_device(device_t *dev) {
    275123        printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle);
    276         printf("[usb_hub] hub device\n");
     124
     125        check_hub_changes();
    277126
    278127        /*
     
    283132
    284133        //create the hub structure
    285         usb_hub_info_t * hub_info = usb_create_hub_info(dev);
    286         usb_lst_append(&usb_hub_list, hub_info);
    287         printf("[usb_hub] hub info added to list\n");
    288         //(void)hub_info;
    289         check_hub_changes();
    290         printf("[usb_hub] hub dev added\n");
    291         //test port status type...
     134        usb_hcd_hub_info_t * hub_info = usb_create_hub_info(dev);
     135        (void)hub_info;
    292136
    293137        return EOK;
    294138        //return ENOTSUP;
    295139}
    296 
    297 
    298140
    299141
     
    304146         * Iterate through all hubs.
    305147         */
    306         usb_general_list_t * lst_item;
    307         for (lst_item = usb_hub_list.next;
    308              lst_item != &usb_hub_list;
    309              lst_item = lst_item->next) {
    310                 printf("[usb_hub] checking hub changes\n");
     148        for (; false; ) {
    311149                /*
    312150                 * Check status change pipe of this hub.
    313151                 */
    314                
    315152                usb_target_t target = {
    316153                        .address = 5,
    317154                        .endpoint = 1
    318155                };
    319                 /// \TODO uncomment once it works correctly
    320                 //target.address = usb_create_hub_info(lst_item)->device->address;
    321156
    322157                size_t port_count = 7;
     
    325160                 * Connect to respective HC.
    326161                 */
    327                 /// \FIXME this is incorrect code: here
    328                 /// must be used particular device instead of NULL
    329162                int hc = usb_drv_hc_connect(NULL, 0);
    330163                if (hc < 0) {
     
    341174                /*
    342175                 * Send the request.
    343                  */
    344                 int opResult = usb_drv_async_interrupt_in(hc, target,
     176                 * FIXME: check returned value for possible errors
     177                 */
     178                usb_drv_async_interrupt_in(hc, target,
    345179                                change_bitmap, byte_length, &actual_size,
    346180                                &handle);
    347181
    348182                usb_drv_async_wait_for(handle);
    349 
    350                 if(opResult!=EOK){
    351                         printf("[usb_hub] something went wrong while getting status of hub\n");
    352                         continue;
    353                 }
    354                 unsigned int port;
    355                 for(port=0;port<port_count;++port){
    356                         bool interrupt = (((uint8_t*)change_bitmap)[port/8]>>(port%8))%2;
    357                         if(interrupt){
    358                                 printf("[usb_hub] interrupt at port %d\n",port);
    359                                 //determine type of change
    360                                 usb_port_status_t status;
    361                                 size_t rcvd_size;
    362                                 usb_device_request_setup_packet_t request;
    363                                 usb_hub_set_port_status_request(&request,port);
    364 
    365                                 opResult = usb_drv_sync_control_read(
    366                                     hc, target,
    367                                     &request,
    368                                     &status, 4, &rcvd_size
    369                                 );
    370                                 if(opResult!=EOK){
    371                                         continue;
    372                                 }
    373                                 if(rcvd_size!=sizeof(usb_port_status_t)){
    374                                         continue;
    375                                 }
    376                                
    377                                 if(usb_port_connect_change(&status)){
    378                                         printf("[usb_hub] some connectionchanged\n");
    379                                         usb_drv_reserve_default_address(hc);
    380                                         //enable port
    381                                         usb_hub_set_enable_port_request(&request,port);
    382                                         opResult = usb_drv_sync_control_write(
    383                                                 hc, target,
    384                                                 &request,
    385                                                 NULL, 0
    386                                         );
    387                                         if(opResult!=EOK){
    388                                                 continue;
    389                                         }
    390                                         //set address
    391                                         usb_address_t new_device_address =
    392                                                         usb_drv_request_address(hc);
    393                                         usb_hub_set_set_address_request
    394                                                         (&request,new_device_address);
    395                                         opResult = usb_drv_sync_control_write(
    396                                                 hc, target,
    397                                                 &request,
    398                                                 NULL, 0
    399                                         );
    400                                         //some other work with drivers
    401                                         /// \TODO do the work with drivers
    402 
    403 
    404                                         usb_drv_release_default_address(hc);
    405                                 }else{
    406                                         printf("[usb_hub] no supported event occured\n");
    407                                 }
    408                                 /// \TODO handle other changes
    409                                 /// \TODO debug log for various situations
    410 
    411 
    412 
    413                                 /*
    414                                 //configure device
    415                                 usb_drv_reserve_default_address(hc);
    416 
    417                                 usb_address_t new_device_address = usb_drv_request_address(hc);
    418 
    419 
    420                                 usb_drv_release_default_address(hc);
    421                                  * */
    422                         }
    423                 }
    424 
    425183
    426184                /*
  • uspace/lib/usb/include/usb/classes/hub.h

    r7964475 rcdc1aa1  
    213213usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * sdescriptor);
    214214
     215/**
     216 * @brief create hub structure instance
     217 *
     218 * @param device
     219 * @return
     220 */
     221usb_hcd_hub_info_t * usb_create_hub_info(device_t * device);
    215222
    216223
  • uspace/lib/usb/include/usb/hcdhubd.h

    r7964475 rcdc1aa1  
    6565} usb_hcd_attached_device_info_t;
    6666
     67/** Information about attached hub. */
     68typedef struct {
     69        /** Number of ports. */
     70        size_t port_count;
     71        /** General device info. */
     72        usb_hcd_attached_device_info_t *device;
     73        /** Link to other hubs. */
     74        link_t link;
     75} usb_hcd_hub_info_t;
    6776
    6877/** Host controller device. */
Note: See TracChangeset for help on using the changeset viewer.