Changeset 9ee87f6 in mainline


Ignore:
Timestamp:
2011-01-25T22:51:08Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7fc092a
Parents:
d03ade7
Message:

uhci initialization refactored

Added cleaner fibril(will handle callbacks and completed transfers)

Location:
uspace/drv/uhci
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci/uhci.c

    rd03ade7 r9ee87f6  
    99#include "uhci.h"
    1010
    11 static int uhci_init_tranfer_lists(transfer_list_t list[]);
    12 
     11static int uhci_init_transfer_lists(transfer_list_t list[]);
     12static int uhci_clean_finished(void *arg);
    1313static inline int uhci_add_transfer(
    1414  device_t *dev,
     
    2323int uhci_init(device_t *device, void *regs)
    2424{
    25         assert( device );
    26         uhci_print_info( "Initializing device at address %p\n", device);
     25        assert(device);
     26        uhci_print_info("Initializing device at address %p.\n", device);
     27
     28#define CHECK_RET_FREE_INSTANCE(message...) \
     29        if (ret != EOK) { \
     30                uhci_print_error(message); \
     31                if (instance) { \
     32                        free(instance); \
     33                } \
     34                return ret; \
     35        } else (void) 0
    2736
    2837        /* create instance */
    2938        uhci_t *instance = malloc( sizeof(uhci_t) );
    30         if (!instance)
    31                 { return ENOMEM; }
    32         bzero( instance, sizeof(uhci_t) );
     39        int ret = instance ? EOK : ENOMEM;
     40        CHECK_RET_FREE_INSTANCE("Failed to allocate uhci driver instance.\n");
     41
     42        bzero(instance, sizeof(uhci_t));
    3343
    3444        /* init address keeper(libusb) */
    35         usb_address_keeping_init( &instance->address_manager, USB11_ADDRESS_MAX );
     45        usb_address_keeping_init(&instance->address_manager, USB11_ADDRESS_MAX);
    3646
    3747        /* allow access to hc control registers */
    3848        regs_t *io;
    39         int ret = pio_enable( regs, sizeof(regs_t), (void**)&io);
    40         if (ret < 0) {
    41                 free( instance );
    42                 uhci_print_error("Failed to gain access to registers at %p\n", io);
    43                 return ret;
    44         }
     49        ret = pio_enable(regs, sizeof(regs_t), (void**)&io);
     50        CHECK_RET_FREE_INSTANCE("Failed to gain access to registers at %p.\n", io);
    4551        instance->registers = io;
     52
     53        /* init transfer lists */
     54        ret = uhci_init_transfer_lists(instance->transfers);
     55        CHECK_RET_FREE_INSTANCE("Failed to initialize transfer lists.\n");
    4656
    4757        /* init root hub */
    4858        ret = uhci_root_hub_init(&instance->root_hub, device,
    4959          (char*)regs + UHCI_ROOT_HUB_PORT_REGISTERS_OFFSET);
    50         if (ret < 0) {
    51                 free(instance);
    52                 uhci_print_error("Failed to initialize root hub driver.\n");
    53                 return ret;
    54         }
    55 
    56         instance->frame_list = trans_malloc(sizeof(frame_list_t));
     60        CHECK_RET_FREE_INSTANCE("Failed to initialize root hub driver.\n");
     61
     62        instance->frame_list =
     63          trans_malloc(sizeof(link_pointer_t) * UHCI_FRAME_LIST_COUNT);
    5764        if (instance->frame_list == NULL) {
    5865                uhci_print_error("Failed to allocate frame list pointer.\n");
     
    6269        }
    6370
     71        /* initialize all frames to point to the first queue head */
     72        unsigned i = 0;
     73        const uint32_t queue =
     74          instance->transfers[USB_TRANSFER_INTERRUPT].queue_head_pa
     75          | LINK_POINTER_QUEUE_HEAD_FLAG;
     76        for(; i < UHCI_FRAME_LIST_COUNT; ++i) {
     77                instance->frame_list[i] = queue;
     78        }
     79
    6480        const uintptr_t pa = (uintptr_t)addr_to_phys(instance->frame_list);
    6581
    6682        pio_write_32(&instance->registers->flbaseadd, (uint32_t)pa);
    6783
    68         ret = uhci_init_tranfer_lists(instance->transfers);
    69         if (ret != EOK) {
    70                 uhci_print_error("Transfer list initialization failed.\n");
    71                 uhci_root_hub_fini(&instance->root_hub);
    72                 free(instance);
    73                 return ret;
    74         }
     84        instance->cleaner = fibril_create(uhci_clean_finished, instance);
     85        fibril_add_ready(instance->cleaner);
    7586
    7687        device->driver_data = instance;
     
    129140}
    130141/*----------------------------------------------------------------------------*/
    131 int uhci_init_tranfer_lists(transfer_list_t transfers[])
     142int uhci_init_transfer_lists(transfer_list_t transfers[])
    132143{
    133144        //TODO:refactor
     
    220231        return EOK;
    221232}
     233/*----------------------------------------------------------------------------*/
     234int uhci_clean_finished(void* arg)
     235{
     236        uhci_print_verbose("Started cleaning fibril.\n");
     237        uhci_t *instance = (uhci_t*)arg;
     238        assert(instance);
     239        while(1) {
     240                uhci_print_verbose("Running cleaning fibril on %p.\n", instance);
     241
     242                async_usleep(1000000);
     243        }
     244        return EOK;
     245}
  • uspace/drv/uhci/uhci.h

    rd03ade7 r9ee87f6  
    4242
    4343#include "root_hub/root_hub.h"
    44 #include "uhci_struct/frame_list.h"
    4544#include "transfer_list.h"
    46 
    4745
    4846typedef struct uhci_regs {
     
    5654
    5755#define TRANSFER_QUEUES 4
     56#define UHCI_FRAME_LIST_COUNT 1024
    5857
    5958typedef struct uhci {
     
    6261        volatile regs_t *registers;
    6362
    64         frame_list_t *frame_list;
     63        link_pointer_t *frame_list;
    6564
    6665        transfer_list_t transfers[TRANSFER_QUEUES];
     66        fid_t cleaner;
    6767} uhci_t;
    6868
Note: See TracChangeset for help on using the changeset viewer.