Changeset eadaeae8 in mainline for uspace/lib/usbhost/src/hcd.c


Ignore:
Timestamp:
2018-03-21T20:58:49Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3be9d10
Parents:
874381a
Message:

Make capability handles type-safe

Define distinct pointer types for the handles of the supported
capability types and use them instead of integer handles. This makes it
virtually impossible to pass a non-handle or a handle of different type
instead of the proper handle. Also turn cap_handle_t into an "untyped"
capability handle that can be assigned to and from the "typed" handles.

This commit also fixes a bug in msim-con driver, which wrongly used the
IRQ number instead of the IRQ capability handle to unregister the IRQ.

This commit also fixes the wrong use of the capability handle instead
of error code in libusbhost.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/hcd.c

    r874381a readaeae8  
    149149 * If this method fails, a polling fibril is started instead.
    150150 *
    151  * @param[in] hcd Host controller device.
    152  * @param[in] hw_res Resources to be used.
    153  *
    154  * @return IRQ capability handle on success.
    155  * @return Negative error code.
     151 * @param[in]  hcd        Host controller device.
     152 * @param[in]  hw_res      Resources to be used.
     153 * @param[out] irq_handle  Storage for the returned IRQ handle
     154 *
     155 * @return Error code.
    156156 */
    157157static errno_t hcd_ddf_setup_interrupts(hc_device_t *hcd,
    158     const hw_res_list_parsed_t *hw_res)
     158    const hw_res_list_parsed_t *hw_res, cap_irq_handle_t *irq_handle)
    159159{
    160160        assert(hcd);
     
    169169        if (ret != EOK) {
    170170                usb_log_error("Failed to generate IRQ code: %s.",
    171                     str_error(irq));
    172                 return irq;
     171                    str_error(ret));
     172                return ret;
    173173        }
    174174
    175175        /* Register handler to avoid interrupt lockup */
    176         int irq_cap;
     176        cap_irq_handle_t ihandle;
    177177        ret = register_interrupt_handler(hcd->ddf_dev, irq, irq_handler,
    178             &irq_code, &irq_cap);
     178            &irq_code, &ihandle);
    179179        irq_code_clean(&irq_code);
    180180        if (ret != EOK) {
    181181                usb_log_error("Failed to register interrupt handler: %s.",
    182                     str_error(irq_cap));
    183                 return irq_cap;
     182                    str_error(ret));
     183                return ret;
    184184        }
    185185
     
    189189                usb_log_error("Failed to enable interrupts: %s.",
    190190                    str_error(ret));
    191                 unregister_interrupt_handler(hcd->ddf_dev, irq_cap);
     191                unregister_interrupt_handler(hcd->ddf_dev, ihandle);
    192192                return ret;
    193193        }
    194         return irq_cap;
     194
     195        *irq_handle = ihandle;
     196        return EOK;
    195197}
    196198
     
    245247
    246248        /* Setup interrupts  */
    247         hcd->irq_cap = hcd_ddf_setup_interrupts(hcd, &hw_res);
    248         if (hcd->irq_cap >= 0) {
     249        hcd->irq_handle = CAP_NIL;
     250        errno_t irqerr = hcd_ddf_setup_interrupts(hcd, &hw_res,
     251            &hcd->irq_handle);
     252        if (irqerr == EOK) {
    249253                usb_log_debug("Hw interrupts enabled.");
    250254        }
     
    270274
    271275        /* Need working irq replacement to setup root hub */
    272         if (hcd->irq_cap < 0 && ops->status) {
     276        if (irqerr != EOK && ops->status) {
    273277                hcd->polling_fibril = fibril_create(interrupt_polling, hcd->bus);
    274278                if (!hcd->polling_fibril) {
     
    279283                fibril_add_ready(hcd->polling_fibril);
    280284                usb_log_warning("Failed to enable interrupts: %s."
    281                     " Falling back to polling.", str_error(hcd->irq_cap));
     285                    " Falling back to polling.", str_error(irqerr));
    282286        }
    283287
     
    305309                hc_driver->stop(hcd);
    306310err_irq:
    307         unregister_interrupt_handler(device, hcd->irq_cap);
     311        unregister_interrupt_handler(device, hcd->irq_handle);
    308312        if (hc_driver->hc_remove)
    309313                hc_driver->hc_remove(hcd);
     
    324328                        return err;
    325329
    326         unregister_interrupt_handler(dev, hcd->irq_cap);
     330        unregister_interrupt_handler(dev, hcd->irq_handle);
    327331
    328332        if (hc_driver->hc_remove)
Note: See TracChangeset for help on using the changeset viewer.