Changeset eadaeae8 in mainline for uspace/drv


Ignore:
Timestamp:
2018-03-21T20:58:49Z (8 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.

Location:
uspace/drv
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/audio/hdaudio/hdaudio.c

    r874381a readaeae8  
    263263        }
    264264
    265         int irq_cap;
     265        cap_irq_handle_t irq_cap;
    266266        rc = register_interrupt_handler(dev, res.irqs.irqs[0],
    267267            hdaudio_interrupt, &irq_code, &irq_cap);
  • uspace/drv/audio/sb16/main.c

    r874381a readaeae8  
    9393        irq_cmd_t irq_cmds[irq_cmd_count];
    9494        irq_pio_range_t irq_ranges[1];
    95         int irq_cap;
     95        cap_irq_handle_t irq_cap;
    9696
    9797        sb16_t *soft_state = ddf_dev_data_alloc(device, sizeof(sb16_t));
  • uspace/drv/block/ahci/ahci.c

    r874381a readaeae8  
    11841184        ct.ranges = ahci_ranges;
    11851185
    1186         int irq_cap;
     1186        cap_irq_handle_t irq_cap;
    11871187        errno_t rc = register_interrupt_handler(dev,
    11881188            hw_res_parsed.irqs.irqs[0], ahci_interrupt, &ct, &irq_cap);
  • uspace/drv/block/ddisk/ddisk.c

    r874381a readaeae8  
    112112        ddisk_regs_t *ddisk_regs;
    113113
    114         int irq_cap;
     114        cap_irq_handle_t irq_cap;
    115115
    116116        bd_srvs_t bds;
     
    449449        ddisk->bds.sarg = ddisk;
    450450
    451         ddisk->irq_cap = -1;
     451        ddisk->irq_cap = CAP_NIL;
    452452
    453453        /*
  • uspace/drv/bus/usb/ohci/hc.c

    r874381a readaeae8  
    512512
    513513        /* Enable interrupts */
    514         if (instance->base.irq_cap >= 0) {
     514        if (CAP_HANDLE_VALID(instance->base.irq_handle)) {
    515515                OHCI_WR(instance->registers->interrupt_enable,
    516516                    OHCI_USED_INTERRUPTS);
  • uspace/drv/bus/usb/uhci/hc.c

    r874381a readaeae8  
    294294        pio_write_32(&registers->flbaseadd, pa);
    295295
    296         if (instance->base.irq_cap >= 0) {
     296        if (CAP_HANDLE_VALID(instance->base.irq_handle)) {
    297297                /* Enable all interrupts, but resume interrupt */
    298298                pio_write_16(&instance->registers->usbintr,
  • uspace/drv/bus/usb/xhci/hc.c

    r874381a readaeae8  
    495495        XHCI_REG_WR(intr0, XHCI_INTR_ERSTBA, erstba_phys);
    496496
    497         if (hc->base.irq_cap > 0) {
     497        if (CAP_HANDLE_VALID(hc->base.irq_handle)) {
    498498                XHCI_REG_SET(intr0, XHCI_INTR_IE, 1);
    499499                XHCI_REG_SET(hc->op_regs, XHCI_OP_INTE, 1);
  • uspace/drv/char/i8042/i8042.c

    r874381a readaeae8  
    281281        };
    282282
    283         int irq_kbd_cap;
     283        cap_irq_handle_t kbd_ihandle;
    284284        rc = register_interrupt_handler(ddf_dev, irq_kbd,
    285             i8042_irq_handler, &irq_code, &irq_kbd_cap);
     285            i8042_irq_handler, &irq_code, &kbd_ihandle);
    286286        if (rc != EOK) {
    287287                ddf_msg(LVL_ERROR, "Failed set handler for kbd: %s.",
     
    290290        }
    291291
    292         int irq_mouse_cap;
     292        cap_irq_handle_t mouse_ihandle;
    293293        rc = register_interrupt_handler(ddf_dev, irq_mouse,
    294             i8042_irq_handler, &irq_code, &irq_mouse_cap);
     294            i8042_irq_handler, &irq_code, &mouse_ihandle);
    295295        if (rc != EOK) {
    296296                ddf_msg(LVL_ERROR, "Failed set handler for mouse: %s.",
  • uspace/drv/char/msim-con/msim-con.c

    r874381a readaeae8  
    8383{
    8484        ddf_fun_t *fun = NULL;
    85         bool subscribed = false;
    8685        irq_cmd_t *msim_cmds = NULL;
    8786        errno_t rc;
     
    9089        fibril_mutex_initialize(&con->buf_lock);
    9190        fibril_condvar_initialize(&con->buf_cv);
     91
     92        con->irq_handle = CAP_NIL;
    9293
    9394        msim_cmds = malloc(sizeof(msim_cmds_proto));
     
    125126        con->irq_code.cmds = msim_cmds;
    126127
    127         async_irq_subscribe(res->irq, msim_irq_handler, con, &con->irq_code, NULL);
    128         subscribed = true;
     128        rc = async_irq_subscribe(res->irq, msim_irq_handler, con,
     129            &con->irq_code, &con->irq_handle);
     130        if (rc != EOK) {
     131                ddf_msg(LVL_ERROR, "Error registering IRQ code.");
     132                goto error;
     133        }
    129134
    130135        chardev_srvs_init(&con->cds);
     
    142147        return EOK;
    143148error:
    144         if (subscribed)
    145                 async_irq_unsubscribe(res->irq);
     149        if (CAP_HANDLE_VALID(con->irq_handle))
     150                async_irq_unsubscribe(con->irq_handle);
    146151        if (fun != NULL)
    147152                ddf_fun_destroy(fun);
  • uspace/drv/char/msim-con/msim-con.h

    r874381a readaeae8  
    6868        fibril_condvar_t buf_cv;
    6969        ioport8_t *out_reg;
     70        cap_irq_handle_t irq_handle;
    7071} msim_con_t;
    7172
  • uspace/drv/char/ns8250/ns8250.c

    r874381a readaeae8  
    165165        int irq;
    166166        /** IRQ capability handle */
    167         int irq_cap;
     167        cap_irq_handle_t irq_handle;
    168168        /** The base i/o address of the devices registers. */
    169169        uintptr_t io_addr;
     
    804804 */
    805805static inline errno_t ns8250_register_interrupt_handler(ns8250_t *ns,
    806     cap_handle_t *handle)
     806    cap_irq_handle_t *ihandle)
    807807{
    808808        return register_interrupt_handler(ns->dev, ns->irq,
    809             ns8250_interrupt_handler, NULL, handle);
     809            ns8250_interrupt_handler, NULL, ihandle);
    810810}
    811811
     
    816816static inline errno_t ns8250_unregister_interrupt_handler(ns8250_t *ns)
    817817{
    818         return unregister_interrupt_handler(ns->dev, ns->irq_cap);
     818        return unregister_interrupt_handler(ns->dev, ns->irq_handle);
    819819}
    820820
     
    876876
    877877        /* Register interrupt handler. */
    878         rc = ns8250_register_interrupt_handler(ns, &ns->irq_cap);
     878        ns->irq_handle = CAP_NIL;
     879        rc = ns8250_register_interrupt_handler(ns, &ns->irq_handle);
    879880        if (rc != EOK) {
    880881                ddf_msg(LVL_ERROR, "Failed to register interrupt handler.");
  • uspace/drv/char/pl050/pl050.c

    r874381a readaeae8  
    213213        pl050->regs = regs;
    214214
    215         int irq_cap;
     215        cap_irq_handle_t ihandle;
    216216        rc = register_interrupt_handler(pl050->dev,
    217             res.irqs.irqs[0], pl050_interrupt, &pl050_irq_code, &irq_cap);
     217            res.irqs.irqs[0], pl050_interrupt, &pl050_irq_code, &ihandle);
    218218        if (rc != EOK) {
    219219                ddf_msg(LVL_ERROR, "Failed registering interrupt handler. (%s)",
  • uspace/drv/nic/e1k/e1k.c

    r874381a readaeae8  
    12641264 *
    12651265 */
    1266 inline static errno_t e1000_register_int_handler(nic_t *nic, cap_handle_t *handle)
     1266inline static errno_t e1000_register_int_handler(nic_t *nic,
     1267    cap_irq_handle_t *handle)
    12671268{
    12681269        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     
    21652166        ddf_fun_set_ops(fun, &e1000_dev_ops);
    21662167
    2167         int irq_cap;
    2168         rc = e1000_register_int_handler(nic, &irq_cap);
     2168        cap_irq_handle_t irq_handle;
     2169        rc = e1000_register_int_handler(nic, &irq_handle);
    21692170        if (rc != EOK) {
    21702171                goto err_fun_create;
     
    22042205        e1000_uninitialize_rx_structure(nic);
    22052206err_irq:
    2206         unregister_interrupt_handler(dev, irq_cap);
     2207        unregister_interrupt_handler(dev, irq_handle);
    22072208err_fun_create:
    22082209        ddf_fun_destroy(fun);
  • uspace/drv/nic/ne2k/ne2k.c

    r874381a readaeae8  
    124124static void ne2k_interrupt_handler(ipc_call_t *, ddf_dev_t *);
    125125
    126 static errno_t ne2k_register_interrupt(nic_t *nic_data, cap_handle_t *handle)
     126static errno_t ne2k_register_interrupt(nic_t *nic_data,
     127    cap_irq_handle_t *handle)
    127128{
    128129        ne2k_t *ne2k = (ne2k_t *) nic_get_specific(nic_data);
  • uspace/drv/nic/rtl8139/driver.c

    r874381a readaeae8  
    846846 *  @return An error code otherwise.
    847847 */
    848 inline static errno_t rtl8139_register_int_handler(nic_t *nic_data, cap_handle_t *handle)
     848inline static errno_t rtl8139_register_int_handler(nic_t *nic_data,
     849    cap_irq_handle_t *handle)
    849850{
    850851        rtl8139_t *rtl8139 = nic_get_specific(nic_data);
     
    12881289
    12891290        /* Register interrupt handler */
    1290         int irq_cap;
    1291         rc = rtl8139_register_int_handler(nic_data, &irq_cap);
     1291        cap_irq_handle_t irq_handle;
     1292        rc = rtl8139_register_int_handler(nic_data, &irq_handle);
    12921293        if (rc != EOK) {
    12931294                goto err_pio;
     
    13241325        ddf_fun_destroy(fun);
    13251326err_srv:
    1326         unregister_interrupt_handler(dev, irq_cap);
     1327        unregister_interrupt_handler(dev, irq_handle);
    13271328err_pio:
    13281329        // rtl8139_pio_disable(dev);
  • uspace/drv/nic/rtl8169/driver.c

    r874381a readaeae8  
    7575static void rtl8169_send_frame(nic_t *nic_data, void *data, size_t size);
    7676static void rtl8169_irq_handler(ipc_call_t *icall, ddf_dev_t *dev);
    77 static inline errno_t rtl8169_register_int_handler(nic_t *nic_data, cap_handle_t *handle);
     77static inline errno_t rtl8169_register_int_handler(nic_t *nic_data,
     78    cap_irq_handle_t *handle);
    7879static inline void rtl8169_get_hwaddr(rtl8169_t *rtl8169, nic_address_t *addr);
    7980static inline void rtl8169_set_hwaddr(rtl8169_t *rtl8169, const nic_address_t *addr);
     
    361362}
    362363
    363 inline static errno_t rtl8169_register_int_handler(nic_t *nic_data, cap_handle_t *handle)
     364inline static errno_t rtl8169_register_int_handler(nic_t *nic_data,
     365    cap_irq_handle_t *handle)
    364366{
    365367        rtl8169_t *rtl8169 = nic_get_specific(nic_data);
     
    429431                goto err_pio;
    430432
    431         int irq_cap;
    432         rc = rtl8169_register_int_handler(nic_data, &irq_cap);
     433        cap_irq_handle_t irq_handle;
     434        rc = rtl8169_register_int_handler(nic_data, &irq_handle);
    433435        if (rc != EOK) {
    434436                ddf_msg(LVL_ERROR, "Failed to register IRQ handler (%s)", str_error_name(rc));
     
    472474err_srv:
    473475        /* XXX Disconnect from services */
    474         unregister_interrupt_handler(dev, irq_cap);
     476        unregister_interrupt_handler(dev, irq_handle);
    475477err_irq:
    476478err_pio:
Note: See TracChangeset for help on using the changeset viewer.