Changeset 0053fa38 in mainline for uspace/drv


Ignore:
Timestamp:
2011-04-02T15:37:53Z (15 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5542b83, d527a4e
Parents:
d773285f (diff), 969585f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Development branch changes

Location:
uspace/drv
Files:
13 edited

Legend:

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

    rd773285f r0053fa38  
    5353
    5454#include <ddf/driver.h>
     55#include <ddf/log.h>
    5556#include <ops/hw_res.h>
    5657
     
    134135        fd = open(conf_path, O_RDONLY);
    135136        if (fd < 0) {
    136                 printf(NAME ": unable to open %s\n", conf_path);
     137                ddf_msg(LVL_ERROR, "Unable to open %s", conf_path);
    137138                goto cleanup;
    138139        }
     
    141142
    142143        len = lseek(fd, 0, SEEK_END);
    143         lseek(fd, 0, SEEK_SET); 
     144        lseek(fd, 0, SEEK_SET);
    144145        if (len == 0) {
    145                 printf(NAME ": fun_conf_read error: configuration file '%s' "
    146                     "is empty.\n", conf_path);
     146                ddf_msg(LVL_ERROR, "Configuration file '%s' is empty.",
     147                    conf_path);
    147148                goto cleanup;
    148149        }
     
    150151        buf = malloc(len + 1);
    151152        if (buf == NULL) {
    152                 printf(NAME ": fun_conf_read error: memory allocation failed.\n");
     153                ddf_msg(LVL_ERROR, "Memory allocation failed.");
    153154                goto cleanup;
    154155        }
    155156
    156157        if (0 >= read(fd, buf, len)) {
    157                 printf(NAME ": fun_conf_read error: unable to read file '%s'.\n",
    158                     conf_path);
     158                ddf_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);
    159159                goto cleanup;
    160160        }
     
    252252                fun->hw_resources.count++;
    253253
    254                 printf(NAME ": added irq 0x%x to function %s\n", irq,
     254                ddf_msg(LVL_NOTE, "Added irq 0x%x to function %s", irq,
    255255                    fun->fnode->name);
    256256        }
     
    270270                fun->hw_resources.count++;
    271271
    272                 printf(NAME ": added io range (addr=0x%x, size=0x%x) to "
    273                     "function %s\n", (unsigned int) addr, (unsigned int) len,
     272                ddf_msg(LVL_NOTE, "Added io range (addr=0x%x, size=0x%x) to "
     273                    "function %s", (unsigned int) addr, (unsigned int) len,
    274274                    fun->fnode->name);
    275275        }
     
    331331        score = (int)strtol(val, &end, 10);
    332332        if (val == end) {
    333                 printf(NAME " : error - could not read match score for "
    334                     "function %s.\n", fun->fnode->name);
     333                ddf_msg(LVL_ERROR, "Cannot read match score for function "
     334                    "%s.", fun->fnode->name);
    335335                return;
    336336        }
     
    339339        get_match_id(&id, val);
    340340        if (id == NULL) {
    341                 printf(NAME " : error - could not read match id for "
    342                     "function %s.\n", fun->fnode->name);
     341                ddf_msg(LVL_ERROR, "Cannot read match ID for function %s.",
     342                    fun->fnode->name);
    343343                return;
    344344        }
    345345
    346         printf(NAME ": adding match id '%s' with score %d to function %s\n", id,
    347             score, fun->fnode->name);
     346        ddf_msg(LVL_DEBUG, "Adding match id '%s' with score %d to "
     347            "function %s", id, score, fun->fnode->name);
    348348
    349349        rc = ddf_fun_add_match_id(fun->fnode, id, score);
    350         if (rc != EOK)
    351                 printf(NAME ": error adding match ID: %s\n", str_error(rc));
     350        if (rc != EOK) {
     351                ddf_msg(LVL_ERROR, "Failed adding match ID: %s",
     352                    str_error(rc));
     353        }
    352354}
    353355
     
    375377        if (!prop_parse(fun, line, "io_range", &fun_parse_io_range) &&
    376378            !prop_parse(fun, line, "irq", &fun_parse_irq) &&
    377             !prop_parse(fun, line, "match", &fun_parse_match_id))
    378         {
    379             printf(NAME " error undefined device property at line '%s'\n",
    380                 line);
     379            !prop_parse(fun, line, "match", &fun_parse_match_id)) {
     380
     381                ddf_msg(LVL_ERROR, "Undefined device property at line '%s'",
     382                    line);
    381383        }
    382384}
     
    439441        fun->fnode->ops = &isa_fun_ops;
    440442
    441         printf(NAME ": Binding function %s.\n", fun->fnode->name);
     443        ddf_msg(LVL_DEBUG, "Binding function %s.", fun->fnode->name);
    442444
    443445        /* XXX Handle error */
     
    467469static int isa_add_device(ddf_dev_t *dev)
    468470{
    469         printf(NAME ": isa_add_device, device handle = %d\n",
     471        ddf_msg(LVL_DEBUG, "isa_add_device, device handle = %d",
    470472            (int) dev->handle);
    471473
    472474        /* Make the bus device more visible. Does not do anything. */
    473         printf(NAME ": adding a 'ctl' function\n");
     475        ddf_msg(LVL_DEBUG, "Adding a 'ctl' function");
    474476
    475477        ddf_fun_t *ctl = ddf_fun_create(dev, fun_exposed, "ctl");
    476478        if (ctl == NULL) {
    477                 printf(NAME ": Error creating control function.\n");
     479                ddf_msg(LVL_ERROR, "Failed creating control function.");
    478480                return EXDEV;
    479481        }
    480482
    481483        if (ddf_fun_bind(ctl) != EOK) {
    482                 printf(NAME ": Error binding control function.\n");
     484                ddf_msg(LVL_ERROR, "Failed binding control function.");
    483485                return EXDEV;
    484486        }
     
    486488        /* Add functions as specified in the configuration file. */
    487489        isa_functions_add(dev);
    488         printf(NAME ": finished the enumeration of legacy functions\n");
     490        ddf_msg(LVL_NOTE, "Finished enumerating legacy functions");
    489491
    490492        return EOK;
     
    493495static void isa_init()
    494496{
     497        ddf_log_init(NAME, LVL_ERROR);
    495498        isa_fun_ops.interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops;
    496499}
  • uspace/drv/ns8250/ns8250.c

    rd773285f r0053fa38  
    5555#include <ddf/driver.h>
    5656#include <ddf/interrupt.h>
     57#include <ddf/log.h>
    5758#include <ops/char_dev.h>
    5859
     
    275276static bool ns8250_pio_enable(ns8250_t *ns)
    276277{
    277         printf(NAME ": ns8250_pio_enable %s\n", ns->dev->name);
     278        ddf_msg(LVL_DEBUG, "ns8250_pio_enable %s", ns->dev->name);
    278279       
    279280        /* Gain control over port's registers. */
    280281        if (pio_enable((void *)(uintptr_t) ns->io_addr, REG_COUNT,
    281282            (void **) &ns->port)) {
    282                 printf(NAME ": error - cannot gain the port %#" PRIx32 " for device "
    283                     "%s.\n", ns->io_addr, ns->dev->name);
     283                ddf_msg(LVL_ERROR, "Cannot map the port %#" PRIx32
     284                    " for device %s.", ns->io_addr, ns->dev->name);
    284285                return false;
    285286        }
     
    295296static bool ns8250_dev_probe(ns8250_t *ns)
    296297{
    297         printf(NAME ": ns8250_dev_probe %s\n", ns->dev->name);
     298        ddf_msg(LVL_DEBUG, "ns8250_dev_probe %s", ns->dev->name);
    298299       
    299300        ioport8_t *port_addr = ns->port;
     
    313314        pio_write_8(port_addr + 4, olddata);
    314315       
    315         if (!res)
    316                 printf(NAME ": device %s is not present.\n", ns->dev->name);
     316        if (!res) {
     317                ddf_msg(LVL_DEBUG, "Device %s is not present.",
     318                    ns->dev->name);
     319        }
    317320       
    318321        return res;
     
    326329static int ns8250_dev_initialize(ns8250_t *ns)
    327330{
    328         printf(NAME ": ns8250_dev_initialize %s\n", ns->dev->name);
     331        ddf_msg(LVL_DEBUG, "ns8250_dev_initialize %s", ns->dev->name);
    329332       
    330333        int ret = EOK;
     
    337340            IPC_FLAG_BLOCKING);
    338341        if (ns->dev->parent_phone < 0) {
    339                 printf(NAME ": failed to connect to the parent driver of the "
    340                     "device %s.\n", ns->dev->name);
     342                ddf_msg(LVL_ERROR, "Failed to connect to parent driver of "
     343                    "device %s.", ns->dev->name);
    341344                ret = ns->dev->parent_phone;
    342345                goto failed;
     
    346349        ret = hw_res_get_resource_list(ns->dev->parent_phone, &hw_resources);
    347350        if (ret != EOK) {
    348                 printf(NAME ": failed to get hw resources for the device "
    349                     "%s.\n", ns->dev->name);
     351                ddf_msg(LVL_ERROR, "Failed to get HW resources for device "
     352                    "%s.", ns->dev->name);
    350353                goto failed;
    351354        }
     
    362365                        ns->irq = res->res.interrupt.irq;
    363366                        irq = true;
    364                         printf(NAME ": the %s device was asigned irq = 0x%x.\n",
     367                        ddf_msg(LVL_NOTE, "Device %s was asigned irq = 0x%x.",
    365368                            ns->dev->name, ns->irq);
    366369                        break;
     
    369372                        ns->io_addr = res->res.io_range.address;
    370373                        if (res->res.io_range.size < REG_COUNT) {
    371                                 printf(NAME ": i/o range assigned to the device "
    372                                     "%s is too small.\n", ns->dev->name);
     374                                ddf_msg(LVL_ERROR, "I/O range assigned to "
     375                                    "device %s is too small.", ns->dev->name);
    373376                                ret = ELIMIT;
    374377                                goto failed;
    375378                        }
    376379                        ioport = true;
    377                         printf(NAME ": the %s device was asigned i/o address = "
    378                             "0x%x.\n", ns->dev->name, ns->io_addr);
    379                         break;
     380                        ddf_msg(LVL_NOTE, "Device %s was asigned I/O address = "
     381                            "0x%x.", ns->dev->name, ns->io_addr);
     382                        break;
    380383                       
    381384                default:
     
    385388       
    386389        if (!irq || !ioport) {
    387                 printf(NAME ": missing hw resource(s) for the device %s.\n",
     390                ddf_msg(LVL_ERROR, "Missing HW resource(s) for device %s.",
    388391                    ns->dev->name);
    389392                ret = ENOENT;
     
    470473       
    471474        if (baud_rate < 50 || MAX_BAUD_RATE % baud_rate != 0) {
    472                 printf(NAME ": error - somebody tried to set invalid baud rate "
    473                     "%d\n", baud_rate);
     475                ddf_msg(LVL_ERROR, "Invalid baud rate %d requested.",
     476                    baud_rate);
    474477                return EINVAL;
    475478        }
     
    654657                        if (ns->client_connected) {
    655658                                if (!buf_push_back(&ns->input_buffer, val)) {
    656                                         printf(NAME ": buffer overflow on "
    657                                             "%s.\n", ns->dev->name);
     659                                        ddf_msg(LVL_WARN, "Buffer overflow on "
     660                                            "%s.", ns->dev->name);
    658661                                } else {
    659                                         printf(NAME ": the character %c saved "
    660                                             "to the buffer of %s.\n",
     662                                        ddf_msg(LVL_DEBUG2, "Character %c saved "
     663                                            "to the buffer of %s.",
    661664                                            val, ns->dev->name);
    662665                                }
     
    714717        int rc;
    715718       
    716         printf(NAME ": ns8250_add_device %s (handle = %d)\n",
     719        ddf_msg(LVL_DEBUG, "ns8250_add_device %s (handle = %d)",
    717720            dev->name, (int) dev->handle);
    718721       
     
    749752        /* Register interrupt handler. */
    750753        if (ns8250_register_interrupt_handler(ns) != EOK) {
    751                 printf(NAME ": failed to register interrupt handler.\n");
     754                ddf_msg(LVL_ERROR, "Failed to register interrupt handler.");
    752755                rc = EADDRNOTAVAIL;
    753756                goto fail;
     
    757760        rc = ns8250_interrupt_enable(ns);
    758761        if (rc != EOK) {
    759                 printf(NAME ": failed to enable the interrupt. Error code = "
    760                     "%d.\n", rc);
     762                ddf_msg(LVL_ERROR, "Failed to enable the interrupt. Error code = "
     763                    "%d.", rc);
    761764                goto fail;
    762765        }
     
    764767        fun = ddf_fun_create(dev, fun_exposed, "a");
    765768        if (fun == NULL) {
    766                 printf(NAME ": error creating function.\n");
     769                ddf_msg(LVL_ERROR, "Failed creating function.");
    767770                goto fail;
    768771        }
     
    772775        rc = ddf_fun_bind(fun);
    773776        if (rc != EOK) {
    774                 printf(NAME ": error binding function.\n");
     777                ddf_msg(LVL_ERROR, "Failed binding function.");
    775778                goto fail;
    776779        }
     
    780783        ddf_fun_add_to_class(fun, "serial");
    781784       
    782         printf(NAME ": the %s device has been successfully initialized.\n",
     785        ddf_msg(LVL_NOTE, "Device %s successfully initialized.",
    783786            dev->name);
    784787       
     
    862865        fibril_mutex_unlock(&data->mutex);
    863866       
    864         printf(NAME ": ns8250_get_props: baud rate %d, parity 0x%x, word "
    865             "length %d, stop bits %d\n", *baud_rate, *parity, *word_length,
     867        ddf_msg(LVL_DEBUG, "ns8250_get_props: baud rate %d, parity 0x%x, word "
     868            "length %d, stop bits %d", *baud_rate, *parity, *word_length,
    866869            *stop_bits);
    867870}
     
    879882    unsigned int parity, unsigned int word_length, unsigned int stop_bits)
    880883{
    881         printf(NAME ": ns8250_set_props: baud rate %d, parity 0x%x, word "
    882             "length %d, stop bits %d\n", baud_rate, parity, word_length,
     884        ddf_msg(LVL_DEBUG, "ns8250_set_props: baud rate %d, parity 0x%x, word "
     885            "length %d, stop bits %d", baud_rate, parity, word_length,
    883886            stop_bits);
    884887       
     
    940943static void ns8250_init(void)
    941944{
     945        ddf_log_init(NAME, LVL_ERROR);
     946       
    942947        ns8250_dev_ops.open = &ns8250_open;
    943948        ns8250_dev_ops.close = &ns8250_close;
  • uspace/drv/ohci/root_hub.c

    rd773285f r0053fa38  
    4040#include "root_hub.h"
    4141#include "usb/classes/classes.h"
     42#include "usb/devdrv.h"
    4243#include <usb/request.h>
    4344#include <usb/classes/hub.h>
     
    6162                /// \TODO these values migt be different
    6263                .str_serial_number = 0,
    63                 .usb_spec_version = 0,
     64                .usb_spec_version = 0x110,
    6465};
    6566
     
    110111};
    111112
    112 /** Root hub initialization
    113  * @return Error code.
    114  */
    115 int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs)
    116 {
    117         assert(instance);
    118         instance->address = -1;
    119         instance->registers = regs;
    120         instance->device = dev;
    121 
    122 
    123         usb_log_info("OHCI root hub with %d ports.\n", regs->rh_desc_a & 0xff);
    124 
    125         //start generic usb hub driver
    126        
    127         /* TODO: implement */
    128         return EOK;
    129 }
    130 /*----------------------------------------------------------------------------*/
    131 
    132 /**
    133  * create answer to port status_request
    134  *
    135  * Copy content of corresponding port status register to answer buffer.
    136  *
    137  * @param instance root hub instance
    138  * @param port port number, counted from 1
    139  * @param request structure containing both request and response information
    140  * @return error code
    141  */
    142 static int process_get_port_status_request(rh_t *instance, uint16_t port,
    143                 usb_transfer_batch_t * request){
    144         if(port<1 || port>instance->port_count)
    145                 return EINVAL;
    146         uint32_t * uint32_buffer = (uint32_t*)request->buffer;
    147         request->transfered_size = 4;
    148         uint32_buffer[0] = instance->registers->rh_port_status[port -1];
    149         return EOK;
    150 }
    151 
    152 /**
    153  * create answer to port status_request
    154  *
    155  * Copy content of hub status register to answer buffer.
    156  *
    157  * @param instance root hub instance
    158  * @param request structure containing both request and response information
    159  * @return error code
    160  */
    161 static int process_get_hub_status_request(rh_t *instance,
    162                 usb_transfer_batch_t * request){
    163         uint32_t * uint32_buffer = (uint32_t*)request->buffer;
    164         //bits, 0,1,16,17
    165         request->transfered_size = 4;
    166         uint32_t mask = 1 & (1<<1) & (1<<16) & (1<<17);
    167         uint32_buffer[0] = mask & instance->registers->rh_status;
    168         return EOK;
    169 
    170 }
    171 
    172113/**
    173114 * Create hub descriptor used in hub-driver <-> hub communication
    174  * 
     115 *
    175116 * This means creating byt array from data in root hub registers. For more
    176117 * info see usb hub specification.
     
    197138        result[2] = instance->port_count;
    198139        uint32_t hub_desc_reg = instance->registers->rh_desc_a;
    199         result[3] = 
     140        result[3] =
    200141                        ((hub_desc_reg >> 8) %2) +
    201142                        (((hub_desc_reg >> 9) %2) << 1) +
     
    219160        (*out_size) = size;
    220161}
     162
     163
     164/** initialize hub descriptors
     165 *
     166 * Initialized are device and full configuration descriptor. These need to
     167 * be initialized only once per hub.
     168 * @instance root hub instance
     169 */
     170static void rh_init_descriptors(rh_t *instance){
     171        memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor,
     172                sizeof(ohci_rh_device_descriptor)
     173        );
     174        usb_standard_configuration_descriptor_t descriptor;
     175        memcpy(&descriptor,&ohci_rh_conf_descriptor,
     176                        sizeof(ohci_rh_conf_descriptor));
     177        uint8_t * hub_descriptor;
     178        size_t hub_desc_size;
     179        usb_create_serialized_hub_descriptor(instance, &hub_descriptor,
     180                        &hub_desc_size);
     181
     182        descriptor.total_length =
     183                        sizeof(usb_standard_configuration_descriptor_t)+
     184                        sizeof(usb_standard_endpoint_descriptor_t)+
     185                        sizeof(usb_standard_interface_descriptor_t)+
     186                        hub_desc_size;
     187       
     188        uint8_t * full_config_descriptor =
     189                        (uint8_t*) malloc(descriptor.total_length);
     190        memcpy(full_config_descriptor, &descriptor, sizeof(descriptor));
     191        memcpy(full_config_descriptor + sizeof(descriptor),
     192                        &ohci_rh_iface_descriptor, sizeof(ohci_rh_iface_descriptor));
     193        memcpy(full_config_descriptor + sizeof(descriptor) +
     194                                sizeof(ohci_rh_iface_descriptor),
     195                        &ohci_rh_ep_descriptor, sizeof(ohci_rh_ep_descriptor));
     196        memcpy(full_config_descriptor + sizeof(descriptor) +
     197                                sizeof(ohci_rh_iface_descriptor) +
     198                                sizeof(ohci_rh_ep_descriptor),
     199                        hub_descriptor, hub_desc_size);
     200       
     201        instance->descriptors.configuration = full_config_descriptor;
     202        instance->descriptors.configuration_size = descriptor.total_length;
     203}
     204
     205/** Root hub initialization
     206 * @return Error code.
     207 */
     208int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs)
     209{
     210        assert(instance);
     211        instance->address = -1;
     212        instance->registers = regs;
     213        instance->device = dev;
     214        rh_init_descriptors(instance);
     215
     216
     217        usb_log_info("OHCI root hub with %d ports.\n", regs->rh_desc_a & 0xff);
     218
     219        //start generic usb hub driver
     220       
     221        /* TODO: implement */
     222        return EOK;
     223}
     224/*----------------------------------------------------------------------------*/
     225
     226/**
     227 * create answer to port status_request
     228 *
     229 * Copy content of corresponding port status register to answer buffer.
     230 *
     231 * @param instance root hub instance
     232 * @param port port number, counted from 1
     233 * @param request structure containing both request and response information
     234 * @return error code
     235 */
     236static int process_get_port_status_request(rh_t *instance, uint16_t port,
     237                usb_transfer_batch_t * request){
     238        if(port<1 || port>instance->port_count)
     239                return EINVAL;
     240        uint32_t * uint32_buffer = (uint32_t*)request->buffer;
     241        request->transfered_size = 4;
     242        uint32_buffer[0] = instance->registers->rh_port_status[port -1];
     243        return EOK;
     244}
     245
     246/**
     247 * create answer to port status_request
     248 *
     249 * Copy content of hub status register to answer buffer.
     250 *
     251 * @param instance root hub instance
     252 * @param request structure containing both request and response information
     253 * @return error code
     254 */
     255static int process_get_hub_status_request(rh_t *instance,
     256                usb_transfer_batch_t * request){
     257        uint32_t * uint32_buffer = (uint32_t*)request->buffer;
     258        //bits, 0,1,16,17
     259        request->transfered_size = 4;
     260        uint32_t mask = 1 & (1<<1) & (1<<16) & (1<<17);
     261        uint32_buffer[0] = mask & instance->registers->rh_status;
     262        return EOK;
     263
     264}
     265
    221266
    222267
     
    284329        }
    285330}
    286 
    287 /**
    288  * create standart configuration descriptor for the root hub instance
    289  * @param instance root hub instance
    290  * @return newly allocated descriptor
    291  */
    292 static usb_standard_configuration_descriptor_t *
    293 usb_ohci_rh_create_standart_configuration_descriptor(rh_t *instance){
    294         usb_standard_configuration_descriptor_t * descriptor =
    295                         malloc(sizeof(usb_standard_configuration_descriptor_t));
    296         memcpy(descriptor, &ohci_rh_conf_descriptor,
    297                 sizeof(usb_standard_configuration_descriptor_t));
    298         /// \TODO should this include device descriptor?
    299         const size_t hub_descriptor_size = 7 +
    300                         2* (instance->port_count / 8 +
    301                         ((instance->port_count % 8 > 0) ? 1 : 0));
    302         descriptor->total_length =
    303                         sizeof(usb_standard_configuration_descriptor_t)+
    304                         sizeof(usb_standard_endpoint_descriptor_t)+
    305                         sizeof(usb_standard_interface_descriptor_t)+
    306                         hub_descriptor_size;
    307         return descriptor;
    308 }
    309 
     331 
    310332/**
    311333 * create answer to a descriptor request
     
    344366                case USB_DESCTYPE_CONFIGURATION: {
    345367                        usb_log_debug("USB_DESCTYPE_CONFIGURATION\n");
    346                         usb_standard_configuration_descriptor_t * descriptor =
    347                                         usb_ohci_rh_create_standart_configuration_descriptor(
    348                                                 instance);
    349                         result_descriptor = descriptor;
    350                         size = sizeof(usb_standard_configuration_descriptor_t);
    351                         del = true;
     368                        result_descriptor = instance->descriptors.configuration;
     369                        size = instance->descriptors.configuration_size;
    352370                        break;
    353371                }
     
    380398        }
    381399        request->transfered_size = size;
    382         memcpy(request->buffer,result_descriptor,size);
     400        memcpy(request->transport_buffer,result_descriptor,size);
     401        usb_log_debug("sent desctiptor: %s\n",
     402                        usb_debug_str_buffer((uint8_t*)request->transport_buffer,size,size));
    383403        if (del)
    384404                free(result_descriptor);
  • uspace/drv/ohci/root_hub.h

    rd773285f r0053fa38  
    3737
    3838#include <usb/usb.h>
     39#include <usb/devdrv.h>
    3940
    4041#include "ohci_regs.h"
     
    5354        /** hub port count */
    5455        int port_count;
     56        /** hubs descriptors */
     57        usb_device_descriptors_t descriptors;
    5558} rh_t;
    5659
  • uspace/drv/pciintel/pci.c

    rd773285f r0053fa38  
    4848
    4949#include <ddf/driver.h>
     50#include <ddf/log.h>
    5051#include <devman.h>
    5152#include <ipc/devman.h>
     
    325326
    326327        if (match_id_str == NULL) {
    327                 printf(NAME ": out of memory creating match ID.\n");
     328                ddf_msg(LVL_ERROR, "Out of memory creating match ID.");
    328329                return;
    329330        }
     
    331332        rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 90);
    332333        if (rc != EOK) {
    333                 printf(NAME ": error adding match ID: %s\n",
     334                ddf_msg(LVL_ERROR, "Failed adding match ID: %s",
    334335                    str_error(rc));
    335336        }
     
    428429       
    429430        if (range_addr != 0) {
    430                 printf(NAME ": function %s : ", fun->fnode->name);
    431                 printf("address = %" PRIx64, range_addr);
    432                 printf(", size = %x\n", (unsigned int) range_size);
     431                ddf_msg(LVL_DEBUG, "Function %s : address = %" PRIx64
     432                    ", size = %x", fun->fnode->name, range_addr,
     433                    (unsigned int) range_size);
    433434        }
    434435       
     
    455456        hw_res_list->count++;
    456457       
    457         printf(NAME ": function %s uses irq %x.\n", fun->fnode->name, irq);
     458        ddf_msg(LVL_NOTE, "Function %s uses irq %x.", fun->fnode->name, irq);
    458459}
    459460
     
    511512                        char *fun_name = pci_fun_create_name(fun);
    512513                        if (fun_name == NULL) {
    513                                 printf(NAME ": out of memory.\n");
     514                                ddf_msg(LVL_ERROR, "Out of memory.");
    514515                                return;
    515516                        }
     
    517518                        fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name);
    518519                        if (fnode == NULL) {
    519                                 printf(NAME ": error creating function.\n");
     520                                ddf_msg(LVL_ERROR, "Failed creating function.");
    520521                                return;
    521522                        }
     
    531532                        fnode->driver_data = fun;
    532533                       
    533                         printf(NAME ": adding new function %s.\n",
     534                        ddf_msg(LVL_DEBUG, "Adding new function %s.",
    534535                            fnode->name);
    535536                       
     
    548549                                child_bus = pci_conf_read_8(fun,
    549550                                    PCI_BRIDGE_SEC_BUS_NUM);
    550                                 printf(NAME ": device is pci-to-pci bridge, "
    551                                     "secondary bus number = %d.\n", bus_num);
     551                                ddf_msg(LVL_DEBUG, "Device is pci-to-pci "
     552                                    "bridge, secondary bus number = %d.",
     553                                    bus_num);
    552554                                if (child_bus > bus_num)
    553555                                        pci_bus_scan(bus, child_bus);
     
    571573        int rc;
    572574       
    573         printf(NAME ": pci_add_device\n");
     575        ddf_msg(LVL_DEBUG, "pci_add_device");
    574576        dnode->parent_phone = -1;
    575577       
    576578        bus = pci_bus_new();
    577579        if (bus == NULL) {
    578                 printf(NAME ": pci_add_device allocation failed.\n");
     580                ddf_msg(LVL_ERROR, "pci_add_device allocation failed.");
    579581                rc = ENOMEM;
    580582                goto fail;
     
    586588            IPC_FLAG_BLOCKING);
    587589        if (dnode->parent_phone < 0) {
    588                 printf(NAME ": pci_add_device failed to connect to the "
    589                     "parent's driver.\n");
     590                ddf_msg(LVL_ERROR, "pci_add_device failed to connect to the "
     591                    "parent's driver.");
    590592                rc = dnode->parent_phone;
    591593                goto fail;
     
    596598        rc = hw_res_get_resource_list(dnode->parent_phone, &hw_resources);
    597599        if (rc != EOK) {
    598                 printf(NAME ": pci_add_device failed to get hw resources for "
    599                     "the device.\n");
     600                ddf_msg(LVL_ERROR, "pci_add_device failed to get hw resources "
     601                    "for the device.");
    600602                goto fail;
    601603        }
    602604        got_res = true;
    603605       
    604         printf(NAME ": conf_addr = %" PRIx64 ".\n",
     606        ddf_msg(LVL_DEBUG, "conf_addr = %" PRIx64 ".",
    605607            hw_resources.resources[0].res.io_range.address);
    606608       
     
    614616        if (pio_enable((void *)(uintptr_t)bus->conf_io_addr, 8,
    615617            &bus->conf_addr_port)) {
    616                 printf(NAME ": failed to enable configuration ports.\n");
     618                ddf_msg(LVL_ERROR, "Failed to enable configuration ports.");
    617619                rc = EADDRNOTAVAIL;
    618620                goto fail;
     
    621623       
    622624        /* Make the bus device more visible. It has no use yet. */
    623         printf(NAME ": adding a 'ctl' function\n");
     625        ddf_msg(LVL_DEBUG, "Adding a 'ctl' function");
    624626       
    625627        ctl = ddf_fun_create(bus->dnode, fun_exposed, "ctl");
    626628        if (ctl == NULL) {
    627                 printf(NAME ": error creating control function.\n");
     629                ddf_msg(LVL_ERROR, "Failed creating control function.");
    628630                rc = ENOMEM;
    629631                goto fail;
     
    632634        rc = ddf_fun_bind(ctl);
    633635        if (rc != EOK) {
    634                 printf(NAME ": error binding control function.\n");
     636                ddf_msg(LVL_ERROR, "Failed binding control function.");
    635637                goto fail;
    636638        }
    637639       
    638640        /* Enumerate functions. */
    639         printf(NAME ": scanning the bus\n");
     641        ddf_msg(LVL_DEBUG, "Scanning the bus");
    640642        pci_bus_scan(bus, 0);
    641643       
     
    659661static void pciintel_init(void)
    660662{
     663        ddf_log_init(NAME, LVL_ERROR);
    661664        pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops;
    662665        pci_fun_ops.interfaces[PCI_DEV_IFACE] = &pci_dev_ops;
     
    738741int main(int argc, char *argv[])
    739742{
    740         printf(NAME ": HelenOS pci bus driver (intel method 1).\n");
     743        printf(NAME ": HelenOS PCI bus driver (Intel method 1).\n");
    741744        pciintel_init();
    742745        return ddf_driver_main(&pci_driver);
  • uspace/drv/root/root.c

    rd773285f r0053fa38  
    5252
    5353#include <ddf/driver.h>
     54#include <ddf/log.h>
    5455#include <devman.h>
    5556#include <ipc/devman.h>
     
    8990        int rc;
    9091
    91         printf(NAME ": adding new function for virtual devices.\n");
    92         printf(NAME ":   function node is `%s' (%d %s)\n", name,
     92        ddf_msg(LVL_DEBUG, "Adding new function for virtual devices. "
     93            "Function node is `%s' (%d %s)", name,
    9394            VIRTUAL_FUN_MATCH_SCORE, VIRTUAL_FUN_MATCH_ID);
    9495
    9596        fun = ddf_fun_create(dev, fun_inner, name);
    9697        if (fun == NULL) {
    97                 printf(NAME ": error creating function %s\n", name);
     98                ddf_msg(LVL_ERROR, "Failed creating function %s", name);
    9899                return ENOMEM;
    99100        }
     
    102103            VIRTUAL_FUN_MATCH_SCORE);
    103104        if (rc != EOK) {
    104                 printf(NAME ": error adding match IDs to function %s\n", name);
     105                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
     106                    name);
    105107                ddf_fun_destroy(fun);
    106108                return rc;
     
    109111        rc = ddf_fun_bind(fun);
    110112        if (rc != EOK) {
    111                 printf(NAME ": error binding function %s: %s\n", name,
     113                ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
    112114                    str_error(rc));
    113115                ddf_fun_destroy(fun);
     
    136138        platform = sysinfo_get_data("platform", &platform_size);
    137139        if (platform == NULL) {
    138                 printf(NAME ": Failed to obtain platform name.\n");
     140                ddf_msg(LVL_ERROR, "Failed to obtain platform name.");
    139141                return ENOENT;
    140142        }
     
    143145        platform = realloc(platform, platform_size + 1);
    144146        if (platform == NULL) {
    145                 printf(NAME ": Memory allocation failed.\n");
     147                ddf_msg(LVL_ERROR, "Memory allocation failed.");
    146148                return ENOMEM;
    147149        }
     
    151153        /* Construct match ID. */
    152154        if (asprintf(&match_id, PLATFORM_FUN_MATCH_ID_FMT, platform) == -1) {
    153                 printf(NAME ": Memory allocation failed.\n");
     155                ddf_msg(LVL_ERROR, "Memory allocation failed.");
    154156                return ENOMEM;
    155157        }
    156158
    157159        /* Add function. */
    158         printf(NAME ": adding platform function\n");
    159         printf(NAME ":   function node is `%s' (%d %s)\n", PLATFORM_FUN_NAME,
    160             PLATFORM_FUN_MATCH_SCORE, match_id);
     160        ddf_msg(LVL_DEBUG, "Adding platform function. Function node is `%s' "
     161            " (%d %s)", PLATFORM_FUN_NAME, PLATFORM_FUN_MATCH_SCORE,
     162            match_id);
    161163
    162164        fun = ddf_fun_create(dev, fun_inner, name);
    163165        if (fun == NULL) {
    164                 printf(NAME ": error creating function %s\n", name);
     166                ddf_msg(LVL_ERROR, "Error creating function %s", name);
    165167                return ENOMEM;
    166168        }
     
    168170        rc = ddf_fun_add_match_id(fun, match_id, PLATFORM_FUN_MATCH_SCORE);
    169171        if (rc != EOK) {
    170                 printf(NAME ": error adding match IDs to function %s\n", name);
     172                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
     173                    name);
    171174                ddf_fun_destroy(fun);
    172175                return rc;
     
    175178        rc = ddf_fun_bind(fun);
    176179        if (rc != EOK) {
    177                 printf(NAME ": error binding function %s: %s\n", name,
     180                ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
    178181                    str_error(rc));
    179182                ddf_fun_destroy(fun);
     
    191194static int root_add_device(ddf_dev_t *dev)
    192195{
    193         printf(NAME ": root_add_device, device handle=%" PRIun "\n",
     196        ddf_msg(LVL_DEBUG, "root_add_device, device handle=%" PRIun,
    194197            dev->handle);
    195198
     
    204207        int res = add_platform_fun(dev);
    205208        if (EOK != res)
    206                 printf(NAME ": failed to add child device for platform.\n");
     209                ddf_msg(LVL_ERROR, "Failed adding child device for platform.");
    207210
    208211        return res;
     
    212215{
    213216        printf(NAME ": HelenOS root device driver\n");
     217
     218        ddf_log_init(NAME, LVL_ERROR);
    214219        return ddf_driver_main(&root_driver);
    215220}
  • uspace/drv/rootpc/rootpc.c

    rd773285f r0053fa38  
    4747
    4848#include <ddf/driver.h>
     49#include <ddf/log.h>
    4950#include <devman.h>
    5051#include <ipc/devman.h>
     
    119120    rootpc_fun_t *fun)
    120121{
    121         printf(NAME ": adding new function '%s'.\n", name);
     122        ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
    122123       
    123124        ddf_fun_t *fnode = NULL;
     
    145146        /* Register function. */
    146147        if (ddf_fun_bind(fnode) != EOK) {
    147                 printf(NAME ": error binding function %s.\n", name);
     148                ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
    148149                goto failure;
    149150        }
     
    158159                ddf_fun_destroy(fnode);
    159160       
    160         printf(NAME ": failed to add function '%s'.\n", name);
     161        ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
    161162       
    162163        return false;
     
    176177static int rootpc_add_device(ddf_dev_t *dev)
    177178{
    178         printf(NAME ": rootpc_add_device, device handle = %d\n",
     179        ddf_msg(LVL_DEBUG, "rootpc_add_device, device handle = %d",
    179180            (int)dev->handle);
    180181       
    181182        /* Register functions. */
    182183        if (!rootpc_add_functions(dev)) {
    183                 printf(NAME ": failed to add functions for PC platform.\n");
     184                ddf_msg(LVL_ERROR, "Failed to add functions for PC platform.");
    184185        }
    185186       
     
    189190static void root_pc_init(void)
    190191{
     192        ddf_log_init(NAME, LVL_ERROR);
    191193        rootpc_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
    192194}
  • uspace/drv/rootvirt/rootvirt.c

    rd773285f r0053fa38  
    4040#include <str_error.h>
    4141#include <ddf/driver.h>
     42#include <ddf/log.h>
    4243
    4344#define NAME "rootvirt"
     
    8384        int rc;
    8485
    85         printf(NAME ": registering function `%s' (match \"%s\")\n",
     86        ddf_msg(LVL_DEBUG, "Registering function `%s' (match \"%s\")",
    8687            vfun->name, vfun->match_id);
    8788
    8889        fun = ddf_fun_create(vdev, fun_inner, vfun->name);
    8990        if (fun == NULL) {
    90                 printf(NAME ": error creating function %s\n", vfun->name);
     91                ddf_msg(LVL_ERROR, "Failed creating function %s", vfun->name);
    9192                return ENOMEM;
    9293        }
     
    9495        rc = ddf_fun_add_match_id(fun, vfun->match_id, 10);
    9596        if (rc != EOK) {
    96                 printf(NAME ": error adding match IDs to function %s\n",
     97                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
    9798                    vfun->name);
    9899                ddf_fun_destroy(fun);
     
    102103        rc = ddf_fun_bind(fun);
    103104        if (rc != EOK) {
    104                 printf(NAME ": error binding function %s: %s\n", vfun->name,
    105                     str_error(rc));
     105                ddf_msg(LVL_ERROR, "Failed binding function %s: %s",
     106                    vfun->name, str_error(rc));
    106107                ddf_fun_destroy(fun);
    107108                return rc;
    108109        }
    109110
    110         printf(NAME ": registered child device `%s'\n", vfun->name);
     111        ddf_msg(LVL_NOTE, "Registered child device `%s'", vfun->name);
    111112        return EOK;
    112113}
     
    124125        }
    125126
    126         printf(NAME ": add_device(handle=%d)\n", (int)dev->handle);
     127        ddf_msg(LVL_DEBUG, "add_device(handle=%d)", (int)dev->handle);
    127128
    128129        /*
     
    142143{
    143144        printf(NAME ": HelenOS virtual devices root driver\n");
     145
     146        ddf_log_init(NAME, LVL_ERROR);
    144147        return ddf_driver_main(&rootvirt_driver);
    145148}
  • uspace/drv/test1/test1.c

    rd773285f r0053fa38  
    3535#include <str_error.h>
    3636#include <ddf/driver.h>
     37#include <ddf/log.h>
    3738
    3839#include "test1.h"
     
    5859 */
    5960static int register_fun_verbose(ddf_dev_t *parent, const char *message,
    60     const char *name, const char *match_id, int match_score)
     61    const char *name, const char *match_id, int match_score,
     62    int expected_rc)
    6163{
    62         ddf_fun_t *fun;
     64        ddf_fun_t *fun = NULL;
    6365        int rc;
    6466
    65         printf(NAME ": registering function `%s': %s.\n", name, message);
     67        ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message);
    6668
    6769        fun = ddf_fun_create(parent, fun_inner, name);
    6870        if (fun == NULL) {
    69                 printf(NAME ": error creating function %s\n", name);
    70                 return ENOMEM;
     71                ddf_msg(LVL_ERROR, "Failed creating function %s", name);
     72                rc = ENOMEM;
     73                goto leave;
    7174        }
    7275
    73         rc = ddf_fun_add_match_id(fun, match_id, match_score);
     76        rc = ddf_fun_add_match_id(fun, str_dup(match_id), match_score);
    7477        if (rc != EOK) {
    75                 printf(NAME ": error adding match IDs to function %s\n", name);
    76                 ddf_fun_destroy(fun);
    77                 return rc;
     78                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
     79                    name);
     80                goto leave;
    7881        }
    7982
    8083        rc = ddf_fun_bind(fun);
    8184        if (rc != EOK) {
    82                 printf(NAME ": error binding function %s: %s\n", name,
     85                ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
    8386                    str_error(rc));
    84                 ddf_fun_destroy(fun);
    85                 return rc;
     87                goto leave;
    8688        }
    8789
    88         printf(NAME ": registered child device `%s'\n", name);
    89         return EOK;
     90        ddf_msg(LVL_NOTE, "Registered child device `%s'", name);
     91        rc = EOK;
     92
     93leave:
     94        if (rc != expected_rc) {
     95                fprintf(stderr,
     96                    NAME ": Unexpected error registering function `%s'.\n"
     97                    NAME ":     Expected \"%s\" but got \"%s\".\n",
     98                    name, str_error(expected_rc), str_error(rc));
     99        }
     100
     101        if ((rc != EOK) && (fun != NULL)) {
     102                ddf_fun_destroy(fun);
     103        }
     104
     105        return rc;
    90106}
    91107
     
    112128        int rc;
    113129
    114         printf(NAME ": add_device(name=\"%s\", handle=%d)\n",
     130        ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)",
    115131            dev->name, (int) dev->handle);
    116132
    117133        fun_a = ddf_fun_create(dev, fun_exposed, "a");
    118134        if (fun_a == NULL) {
    119                 printf(NAME ": error creating function 'a'.\n");
     135                ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
    120136                return ENOMEM;
    121137        }
     
    123139        rc = ddf_fun_bind(fun_a);
    124140        if (rc != EOK) {
    125                 printf(NAME ": error binding function 'a'.\n");
     141                ddf_msg(LVL_ERROR, "Failed binding function 'a'.");
    126142                return rc;
    127143        }
     
    133149                ddf_fun_add_to_class(fun_a, "virt-null");
    134150        } else if (str_cmp(dev->name, "test1") == 0) {
    135                 (void) register_fun_verbose(dev, "cloning myself ;-)", "clone",
    136                     "virtual&test1", 10);
     151                (void) register_fun_verbose(dev,
     152                    "cloning myself ;-)", "clone",
     153                    "virtual&test1", 10, EOK);
     154                (void) register_fun_verbose(dev,
     155                    "cloning myself twice ;-)", "clone",
     156                    "virtual&test1", 10, EEXISTS);
    137157        } else if (str_cmp(dev->name, "clone") == 0) {
    138                 (void) register_fun_verbose(dev, "run by the same task", "child",
    139                     "virtual&test1&child", 10);
     158                (void) register_fun_verbose(dev,
     159                    "run by the same task", "child",
     160                    "virtual&test1&child", 10, EOK);
    140161        }
    141162
    142         printf(NAME ": device `%s' accepted.\n", dev->name);
     163        ddf_msg(LVL_DEBUG, "Device `%s' accepted.", dev->name);
    143164
    144165        return EOK;
     
    148169{
    149170        printf(NAME ": HelenOS test1 virtual device driver\n");
     171        ddf_log_init(NAME, LVL_ERROR);
    150172        return ddf_driver_main(&test1_driver);
    151173}
  • uspace/drv/test2/test2.c

    rd773285f r0053fa38  
    3636#include <str_error.h>
    3737#include <ddf/driver.h>
     38#include <ddf/log.h>
    3839
    3940#define NAME "test2"
     
    6465        int rc;
    6566
    66         printf(NAME ": registering function `%s': %s.\n", name, message);
     67        ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message);
    6768
    6869        fun = ddf_fun_create(parent, fun_inner, name);
    6970        if (fun == NULL) {
    70                 printf(NAME ": error creating function %s\n", name);
     71                ddf_msg(LVL_ERROR, "Failed creating function %s", name);
    7172                return ENOMEM;
    7273        }
     
    7475        rc = ddf_fun_add_match_id(fun, match_id, match_score);
    7576        if (rc != EOK) {
    76                 printf(NAME ": error adding match IDs to function %s\n", name);
     77                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
     78                    name);
    7779                ddf_fun_destroy(fun);
    7880                return rc;
     
    8183        rc = ddf_fun_bind(fun);
    8284        if (rc != EOK) {
    83                 printf(NAME ": error binding function %s: %s\n", name,
     85                ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
    8486                    str_error(rc));
    8587                ddf_fun_destroy(fun);
     
    8789        }
    8890
    89         printf(NAME ": registered child device `%s'\n", name);
     91        ddf_msg(LVL_NOTE, "Registered child device `%s'", name);
    9092        return EOK;
    9193}
     
    111113        fun_a = ddf_fun_create(dev, fun_exposed, "a");
    112114        if (fun_a == NULL) {
    113                 printf(NAME ": error creating function 'a'.\n");
     115                ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
    114116                return ENOMEM;
    115117        }
     
    117119        rc = ddf_fun_bind(fun_a);
    118120        if (rc != EOK) {
    119                 printf(NAME ": error binding function 'a'.\n");
     121                ddf_msg(LVL_ERROR, "Failed binding function 'a'.");
    120122                return rc;
    121123        }
     
    128130static int test2_add_device(ddf_dev_t *dev)
    129131{
    130         printf(NAME ": test2_add_device(name=\"%s\", handle=%d)\n",
     132        ddf_msg(LVL_DEBUG, "test2_add_device(name=\"%s\", handle=%d)",
    131133            dev->name, (int) dev->handle);
    132134
     
    134136                fid_t postpone = fibril_create(postponed_birth, dev);
    135137                if (postpone == 0) {
    136                         printf(NAME ": fibril_create() error\n");
     138                        ddf_msg(LVL_ERROR, "fibril_create() failed.");
    137139                        return ENOMEM;
    138140                }
     
    149151{
    150152        printf(NAME ": HelenOS test2 virtual device driver\n");
     153        ddf_log_init(NAME, LVL_ERROR);
    151154        return ddf_driver_main(&test2_driver);
    152155}
  • uspace/drv/usbhub/usbhub.c

    rd773285f r0053fa38  
    7474
    7575        while(errorCode == EOK){
     76                async_usleep(1000 * 1000 * 10 );/// \TODO proper number once
    7677                errorCode = usb_hub_check_hub_changes(hub_info);
    77                 async_usleep(1000 * 1000 );/// \TODO proper number once
    7878        }
    7979        usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode);
  • uspace/drv/usbkbd/kbddev.c

    rd773285f r0053fa38  
    5656#include <usb/classes/hidreq.h>
    5757#include <usb/classes/hidreport.h>
     58#include <usb/classes/hid/utled.h>
    5859
    5960#include <usb/devdrv.h>
     
    6970static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK;
    7071
    71 /** Boot protocol report size (key part). */
    72 static const size_t BOOTP_REPORT_SIZE = 6;
    73 
    74 /** Boot protocol total report size. */
    75 static const size_t BOOTP_BUFFER_SIZE = 8;
    76 
    77 /** Boot protocol output report size. */
    78 static const size_t BOOTP_BUFFER_OUT_SIZE = 1;
    79 
    80 /** Boot protocol error key code. */
    81 static const uint8_t BOOTP_ERROR_ROLLOVER = 1;
     72///** Boot protocol report size (key part). */
     73//static const size_t BOOTP_REPORT_SIZE = 6;
     74
     75///** Boot protocol total report size. */
     76//static const size_t BOOTP_BUFFER_SIZE = 8;
     77
     78///** Boot protocol output report size. */
     79//static const size_t BOOTP_BUFFER_OUT_SIZE = 1;
     80
     81///** Boot protocol error key code. */
     82//static const uint8_t BOOTP_ERROR_ROLLOVER = 1;
     83static const uint8_t ERROR_ROLLOVER = 1;
    8284
    8385/** Default idle rate for keyboards. */
     
    263265static void usb_kbd_set_led(usb_kbd_t *kbd_dev)
    264266{
    265         uint8_t buffer[BOOTP_BUFFER_OUT_SIZE];
    266         int rc= 0;
    267        
    268         memset(buffer, 0, BOOTP_BUFFER_OUT_SIZE);
    269         uint8_t leds = 0;
    270 
    271         if (kbd_dev->mods & KM_NUM_LOCK) {
    272                 leds |= USB_HID_LED_NUM_LOCK;
    273         }
    274        
    275         if (kbd_dev->mods & KM_CAPS_LOCK) {
    276                 leds |= USB_HID_LED_CAPS_LOCK;
    277         }
    278        
    279         if (kbd_dev->mods & KM_SCROLL_LOCK) {
    280                 leds |= USB_HID_LED_SCROLL_LOCK;
     267        unsigned i = 0;
     268       
     269        /* Reset the LED data. */
     270        memset(kbd_dev->led_data, 0, kbd_dev->led_output_size * sizeof(int32_t));
     271       
     272        if ((kbd_dev->mods & KM_NUM_LOCK) && (i < kbd_dev->led_output_size)) {
     273                kbd_dev->led_data[i++] = USB_HID_LED_NUM_LOCK;
     274        }
     275       
     276        if ((kbd_dev->mods & KM_CAPS_LOCK) && (i < kbd_dev->led_output_size)) {
     277                kbd_dev->led_data[i++] = USB_HID_LED_CAPS_LOCK;
     278        }
     279       
     280        if ((kbd_dev->mods & KM_SCROLL_LOCK)
     281            && (i < kbd_dev->led_output_size)) {
     282                kbd_dev->led_data[i++] = USB_HID_LED_SCROLL_LOCK;
    281283        }
    282284
     
    284286       
    285287        usb_log_debug("Creating output report.\n");
    286         usb_log_debug("Leds: 0x%x\n", leds);
    287         if ((rc = usb_hid_boot_keyboard_output_report(
    288             leds, buffer, BOOTP_BUFFER_OUT_SIZE)) != EOK) {
    289                 usb_log_warning("Error composing output report to the keyboard:"
    290                     "%s.\n", str_error(rc));
     288       
     289        int rc = usb_hid_report_output_translate(kbd_dev->parser,
     290            kbd_dev->led_path, USB_HID_PATH_COMPARE_END, kbd_dev->output_buffer,
     291            kbd_dev->output_size, kbd_dev->led_data, kbd_dev->led_output_size);
     292       
     293        if (rc != EOK) {
     294                usb_log_warning("Error translating LED output to output report"
     295                    ".\n");
    291296                return;
    292297        }
    293298       
    294299        usb_log_debug("Output report buffer: %s\n",
    295             usb_debug_str_buffer(buffer, BOOTP_BUFFER_OUT_SIZE, 0));
    296        
    297         assert(kbd_dev->usb_dev != NULL);
     300            usb_debug_str_buffer(kbd_dev->output_buffer, kbd_dev->output_size,
     301                0));
    298302       
    299303        usbhid_req_set_report(&kbd_dev->usb_dev->ctrl_pipe,
    300304            kbd_dev->usb_dev->interface_no, USB_HID_REPORT_TYPE_OUTPUT,
    301             buffer, BOOTP_BUFFER_OUT_SIZE);
     305            kbd_dev->output_buffer, kbd_dev->output_size);
    302306}
    303307
     
    450454         * First of all, check if the kbd have reported phantom state.
    451455         *
    452          *  this must be changed as we don't know which keys are modifiers
    453          *       and which are regular keys.
     456         * As there is no way to distinguish keys from modifiers, we do not have
     457         * a way to check that 'all keys report Error Rollover'. We thus check
     458         * if there is at least one such error and in such case we ignore the
     459         * whole input report.
    454460         */
    455461        i = 0;
    456         // all fields should report Error Rollover
    457         while (i < count &&
    458             key_codes[i] == BOOTP_ERROR_ROLLOVER) {
     462        while (i < count && key_codes[i] != ERROR_ROLLOVER) {
    459463                ++i;
    460464        }
    461         if (i == count) {
     465        if (i != count) {
    462466                usb_log_debug("Phantom state occured.\n");
    463467                // phantom state, do nothing
     
    586590 */
    587591static void usb_kbd_process_data(usb_kbd_t *kbd_dev,
    588                                     uint8_t *buffer, size_t actual_size)
     592                                 uint8_t *buffer, size_t actual_size)
    589593{
    590594        assert(kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED);
     
    760764        usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
    761765       
    762         kbd_dev->keys = (uint8_t *)calloc(
    763             kbd_dev->key_count, sizeof(uint8_t));
     766        kbd_dev->keys = (uint8_t *)calloc(kbd_dev->key_count, sizeof(uint8_t));
    764767       
    765768        if (kbd_dev->keys == NULL) {
     
    768771        }
    769772       
     773        /*
     774         * Output report
     775         */
     776        kbd_dev->output_size = 0;
     777        kbd_dev->output_buffer = usb_hid_report_output(kbd_dev->parser,
     778            &kbd_dev->output_size);
     779        if (kbd_dev->output_buffer == NULL) {
     780                usb_log_warning("Error creating output report buffer.\n");
     781                free(kbd_dev->keys);
     782                return ENOMEM;  /* TODO: other error code */
     783        }
     784       
     785        usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size);
     786       
     787        kbd_dev->led_path = usb_hid_report_path();
     788        usb_hid_report_path_append_item(
     789            kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
     790       
     791        kbd_dev->led_output_size = usb_hid_report_output_size(kbd_dev->parser,
     792            kbd_dev->led_path, USB_HID_PATH_COMPARE_END);
     793       
     794        usb_log_debug("Output report size (in items): %zu\n",
     795            kbd_dev->led_output_size);
     796       
     797        kbd_dev->led_data = (int32_t *)calloc(
     798            kbd_dev->led_output_size, sizeof(int32_t));
     799       
     800        if (kbd_dev->led_data == NULL) {
     801                usb_log_warning("Error creating buffer for LED output report."
     802                    "\n");
     803                free(kbd_dev->keys);
     804                usb_hid_report_output_free(kbd_dev->output_buffer);
     805                return ENOMEM;
     806        }
     807       
     808        /*
     809         * Modifiers and locks
     810         */     
    770811        kbd_dev->modifiers = 0;
    771812        kbd_dev->mods = DEFAULT_ACTIVE_MODS;
    772813        kbd_dev->lock_keys = 0;
    773814       
     815        /*
     816         * Autorepeat
     817         */     
    774818        kbd_dev->repeat.key_new = 0;
    775819        kbd_dev->repeat.key_repeated = 0;
     
    879923        }
    880924       
     925        // free the output buffer
     926        usb_hid_report_output_free((*kbd_dev)->output_buffer);
     927       
    881928        /* TODO: what about the USB device structure?? */
    882929
  • uspace/drv/usbkbd/kbddev.h

    rd773285f r0053fa38  
    9494        /** Report descriptor size. */
    9595        size_t report_desc_size;
     96       
     97        uint8_t *output_buffer;
     98       
     99        size_t output_size;
     100       
     101        size_t led_output_size;
     102       
     103        usb_hid_report_path_t *led_path;
     104       
     105        int32_t *led_data;
    96106
    97107        /** HID Report parser. */
Note: See TracChangeset for help on using the changeset viewer.