Changeset 9600516 in mainline


Ignore:
Timestamp:
2011-01-21T16:49:47Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
643b983
Parents:
1062c8d
Message:

Added transfer queues for interrupt, control and bulk transfers.

UHCI structures refactoring

Location:
uspace/drv/uhci
Files:
3 added
2 edited
4 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci/callback.h

    r1062c8d r9600516  
    1 
    21/*
    32 * Copyright (c) 2010 Jan Vesely
     
    3332 * @brief UHCI driver
    3433 */
    35 #ifndef DRV_UHCI_QH_H
    36 #define DRV_UHCI_QH_H
     34#ifndef DRV_UHCI_CALLBACK_H
     35#define DRV_UHCI_CALLBACK_H
    3736
    38 #include "link_ptr.h"
     37#include <usbhc_iface.h>
    3938
    40 typedef struct qh {
    41         link_ptr_t
    42 } __attribute__(("packed")) link_ptr_t;
     39typedef struct callback
     40{
     41        union {
     42                usbhc_iface_transfer_in_callback_t callback_in;
     43                usbhc_iface_transfer_out_callback_t callback_out;
     44        };
     45        void* buffer;
     46} callback_t;
    4347
    4448#endif
  • uspace/drv/uhci/uhci.c

    r1062c8d r9600516  
    33#include <usb/usb.h>
    44
     5#include "translating_malloc.h"
     6
    57#include "debug.h"
    68#include "name.h"
    79#include "uhci.h"
     10
     11static int init_tranfer_lists(transfer_list_t list[]);
    812
    913int uhci_init(device_t *device, void *regs)
     
    2630        if (ret < 0) {
    2731                free( instance );
    28                 printf(NAME": Failed to gain access to registers at %p\n", io);
     32                uhci_print_error("Failed to gain access to registers at %p\n", io);
    2933                return ret;
    3034        }
     
    3236
    3337        /* init root hub */
    34         ret = uhci_root_hub_init( &instance->root_hub, device,
    35           (char*)regs + UHCI_ROOT_HUB_PORT_REGISTERS_OFFSET );
     38        ret = uhci_root_hub_init(&instance->root_hub, device,
     39          (char*)regs + UHCI_ROOT_HUB_PORT_REGISTERS_OFFSET);
    3640        if (ret < 0) {
    37                 free( instance );
    38                 printf(NAME": Failed to initialize root hub driver.\n");
     41                free(instance);
     42                uhci_print_error("Failed to initialize root hub driver.\n");
     43                return ret;
     44        }
     45
     46        instance->frame_list = trans_malloc(sizeof(frame_list_t));
     47        if (instance->frame_list == NULL) {
     48                uhci_print_error("Failed to allocate frame list pointer.\n");
     49                uhci_root_hub_fini(&instance->root_hub);
     50                free(instance);
     51                return ENOMEM;
     52        }
     53
     54        const uintptr_t pa = (uintptr_t)addr_to_phys(instance->frame_list);
     55
     56        pio_write_32(&instance->registers->flbaseadd, (uint32_t)pa);
     57
     58        ret = init_tranfer_lists(instance->transfers);
     59        if (ret != EOK) {
     60                uhci_print_error("Transfer list initialization failed.\n");
     61                uhci_root_hub_fini(&instance->root_hub);
     62                free(instance);
    3963                return ret;
    4064        }
    4165
    4266        device->driver_data = instance;
     67        return EOK;
     68}
     69/*----------------------------------------------------------------------------*/
     70int init_tranfer_lists(transfer_list_t transfers[])
     71{
     72        //TODO:refactor
     73        int ret;
     74        ret = transfer_list_init(&transfers[USB_TRANSFER_BULK], NULL);
     75        if (ret != EOK) {
     76                uhci_print_error("Failed to inititalize bulk queue.\n");
     77                return ret;
     78        }
     79
     80        ret = transfer_list_init(
     81          &transfers[USB_TRANSFER_CONTROL], &transfers[USB_TRANSFER_BULK]);
     82        if (ret != EOK) {
     83                uhci_print_error("Failed to inititalize control queue.\n");
     84                transfer_list_fini(&transfers[USB_TRANSFER_BULK]);
     85                return ret;
     86        }
     87
     88        ret = transfer_list_init(
     89          &transfers[USB_TRANSFER_INTERRUPT], &transfers[USB_TRANSFER_CONTROL]);
     90        if (ret != EOK) {
     91                uhci_print_error("Failed to interrupt control queue.\n");
     92                transfer_list_fini(&transfers[USB_TRANSFER_CONTROL]);
     93                transfer_list_fini(&transfers[USB_TRANSFER_BULK]);
     94                return ret;
     95        }
     96
    4397        return EOK;
    4498}
  • uspace/drv/uhci/uhci.h

    r1062c8d r9600516  
    4242
    4343#include "root_hub/root_hub.h"
     44#include "uhci_struct/frame_list.h"
     45#include "transfer_list.h"
     46
    4447
    4548typedef struct uhci_regs {
     
    5255} regs_t;
    5356
     57#define TRANSFER_QUEUES 4
     58
    5459typedef struct uhci {
    5560        usb_address_keeping_t address_manager;
    5661        uhci_root_hub_t root_hub;
    57         volatile regs_t* registers;
    58 } uhci_t ;
     62        volatile regs_t *registers;
     63
     64        frame_list_t *frame_list;
     65
     66        transfer_list_t transfers[TRANSFER_QUEUES];
     67} uhci_t;
    5968
    6069/* init uhci specifics in device.driver_data */
  • uspace/drv/uhci/uhci_struct/frame_list.h

    r1062c8d r9600516  
    3232 * @brief UHCI driver
    3333 */
    34 #ifndef DRV_UHCI_LINK_PTR_H
    35 #define DRV_UHCI_LINK_PTR_H
     34#ifndef DRV_UHCI_FRAME_LIST_H
     35#define DRV_UHCI_FRAME_LIST_H
    3636
    37 #include "td_ptr.h"
     37#include "link_pointer.h"
    3838
    39 /** Links in Frame List */
    40 typedef td_ptr_t link_ptr_t;
     39#define UHCI_FRAME_LIST_COUNT 1024
    4140
     41typedef link_pointer_t frame_list_t[UHCI_FRAME_LIST_COUNT];
    4242#endif
    4343/**
  • uspace/drv/uhci/uhci_struct/link_pointer.h

    r1062c8d r9600516  
    3232 * @brief UHCI driver
    3333 */
    34 #ifndef DRV_UHCI_TD_PTR_H
    35 #define DRV_UHCI_TD_PTR_H
     34#ifndef DRV_UHCI_LINK_POINTER_H
     35#define DRV_UHCI_LINK_POINTER_H
    3636
    37 /** UHCI Transfer Descriptor pointer */
    38 typedef struct td_ptr {
    39         uint32_t fpl:28;
    40         char :2;
     37/* UHCI link pointer, used by many data structures */
     38typedef struct link_pointer {
     39        uint32_t addr:28;
     40        uint8_t zero:1;
     41        uint8_t reserved:1;
    4142        uint8_t qh:1;
    4243        uint8_t terminate:1;
    43 } __attribute__(("packed")) td_ptr_t;
     44} __attribute__((packed)) link_pointer_t;
    4445
    4546#endif
     
    4748 * @}
    4849 */
     50
  • uspace/drv/uhci/uhci_struct/transfer_descriptor.h

    r1062c8d r9600516  
    3232 * @brief UHCI driver
    3333 */
    34 #ifndef DRV_UHCI_TRANSFER_H
    35 #define DRV_UHCI_TRANSFER_H
     34#ifndef DRV_UHCI_TRANSFER_DESCRIPTOR_H
     35#define DRV_UHCI_TRANSFER_DESCRIPTOR_H
     36
     37#include "callback.h"
    3638
    3739/** Status field in UHCI Transfer Descriptor (TD) */
     
    4547        uint8_t bitstuff:1;
    4648        uint8_t :1; /* reserved */
    47 } status_t
     49} status_t;
    4850
    4951/** UHCI Transfer Descriptor */
    50 typedef struct td {
     52typedef struct transfer_descriptor {
    5153        uint32_t fpl:28;
    5254        char :1; /* reserved */
     
    7375
    7476        uint32_t buffer_ptr;
    75 } __attribute__(("packed")) td_t;
    7677
     78        /* there is 16 byte of data available here
     79         * those are used to store callback pointer
     80         * and next pointer. Thus there is some free space
     81         * on 32bits systems.
     82         */
     83        struct transfer_descriptor *next;
     84        callback_t *callback;
     85} __attribute__((packed)) transfer_descriptor_t;
    7786
    7887#endif
Note: See TracChangeset for help on using the changeset viewer.