Changeset 60744cb in mainline


Ignore:
Timestamp:
2024-05-17T17:51:56Z (7 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
1801005
Parents:
646849b3
Message:

Let driver specify any argument to IRQ handler

This allows the driver to register a single handler for multiple
interrupts and still distinguish between them. It also removes
the extra step of having to get softstate from ddf_dev_t.

Location:
uspace
Files:
18 edited

Legend:

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

    r646849b3 r60744cb  
    5858static errno_t hda_fun_offline(ddf_fun_t *fun);
    5959
    60 static void hdaudio_interrupt(ipc_call_t *, ddf_dev_t *);
     60static void hdaudio_interrupt(ipc_call_t *, void *);
    6161
    6262static driver_ops_t driver_ops = {
     
    266266        cap_irq_handle_t irq_cap;
    267267        rc = register_interrupt_handler(dev, res.irqs.irqs[0],
    268             hdaudio_interrupt, &irq_code, &irq_cap);
     268            hdaudio_interrupt, (void *)hda, &irq_code, &irq_cap);
    269269        if (rc != EOK) {
    270270                ddf_msg(LVL_ERROR, "Failed registering interrupt handler: %s",
     
    377377}
    378378
    379 static void hdaudio_interrupt(ipc_call_t *icall, ddf_dev_t *dev)
    380 {
    381         hda_t *hda = (hda_t *)ddf_dev_data_get(dev);
     379/** HD Audio interrupt handler.
     380 *
     381 * @param icall IRQ event notification
     382 * @param arg Argument (hda_t *)
     383 */
     384static void hdaudio_interrupt(ipc_call_t *icall, void *arg)
     385{
     386        hda_t *hda = (hda_t *)arg;
    382387
    383388        if (0)
  • uspace/drv/audio/sb16/main.c

    r646849b3 r60744cb  
    7676}
    7777
    78 static void irq_handler(ipc_call_t *call, ddf_dev_t *dev)
    79 {
    80         sb16_t *sb16_dev = ddf_dev_data_get(dev);
     78/** SB16 IRQ handler.
     79 *
     80 * @param call IRQ event notification
     81 * @param arg Argument (sb16_t *)
     82 */
     83static void irq_handler(ipc_call_t *call, void *arg)
     84{
     85        sb16_t *sb16_dev = (sb16_t *)arg;
    8186        sb16_interrupt(sb16_dev);
    8287}
     
    124129
    125130        rc = register_interrupt_handler(device, irq, irq_handler,
    126             &irq_code, &irq_cap);
     131            (void *)soft_state, &irq_code, &irq_cap);
    127132        if (rc != EOK) {
    128133                ddf_log_error("Failed to register irq handler: %s.",
  • uspace/drv/block/ahci/ahci.c

    r646849b3 r60744cb  
    162162}
    163163
    164 /** Get AHCI structure from DDF device. */
    165 static ahci_dev_t *dev_ahci_dev(ddf_dev_t *dev)
    166 {
    167         return ddf_dev_data_get(dev);
    168 }
    169 
    170164/** Get SATA device name.
    171165 *
     
    891885 *
    892886 * @param icall The IPC call structure.
    893  * @param dev   DDF device structure.
    894  *
    895  */
    896 static void ahci_interrupt(ipc_call_t *icall, ddf_dev_t *dev)
    897 {
    898         ahci_dev_t *ahci = dev_ahci_dev(dev);
     887 * @param arg   Argument (ahci_dev_t *)
     888 */
     889static void ahci_interrupt(ipc_call_t *icall, void *arg)
     890{
     891        ahci_dev_t *ahci = (ahci_dev_t *)arg;
    899892        unsigned int port = ipc_get_arg1(icall);
    900893        ahci_port_is_t pxis = ipc_get_arg2(icall);
     
    11861179        cap_irq_handle_t irq_cap;
    11871180        errno_t rc = register_interrupt_handler(dev,
    1188             hw_res_parsed.irqs.irqs[0], ahci_interrupt, &ct, &irq_cap);
     1181            hw_res_parsed.irqs.irqs[0], ahci_interrupt, (void *)ahci, &ct,
     1182            &irq_cap);
    11891183        if (rc != EOK) {
    11901184                ddf_msg(LVL_ERROR, "Failed registering interrupt handler.");
  • uspace/drv/block/ddisk/ddisk.c

    r646849b3 r60744cb  
    6464static void ddisk_bd_connection(ipc_call_t *, void *);
    6565
    66 static void ddisk_irq_handler(ipc_call_t *, ddf_dev_t *);
     66static void ddisk_irq_handler(ipc_call_t *, void *);
    6767
    6868static driver_ops_t driver_ops = {
     
    176176};
    177177
    178 void ddisk_irq_handler(ipc_call_t *icall, ddf_dev_t *dev)
     178/** Ddisk IRQ handler.
     179 *
     180 * @param icall IRQ event notification
     181 * @param arg Argument (ddisk_t *)
     182 */
     183void ddisk_irq_handler(ipc_call_t *icall, void *arg)
    179184{
    180185        ddf_msg(LVL_DEBUG, "ddisk_irq_handler(), status=%" PRIx32,
    181186            (uint32_t) ipc_get_arg1(icall));
    182187
    183         ddisk_t *ddisk = (ddisk_t *) ddf_dev_data_get(dev);
     188        ddisk_t *ddisk = (ddisk_t *)arg;
    184189
    185190        fibril_mutex_lock(&ddisk->lock);
     
    512517        ddisk_irq_commands[3].addr = (void *) &res_phys->command;
    513518        rc = register_interrupt_handler(dev, ddisk->ddisk_res.irq,
    514             ddisk_irq_handler, &ddisk_irq_code, &ddisk->irq_cap);
     519            ddisk_irq_handler, (void *)ddisk, &ddisk_irq_code, &ddisk->irq_cap);
    515520        if (rc != EOK) {
    516521                ddf_msg(LVL_ERROR, "Failed to register interrupt handler.");
  • uspace/drv/block/isa-ide/isa-ide.c

    r646849b3 r60744cb  
    5959static errno_t isa_ide_init_irq(isa_ide_channel_t *);
    6060static void isa_ide_fini_irq(isa_ide_channel_t *);
    61 static void isa_ide_irq_handler(ipc_call_t *, ddf_dev_t *);
     61static void isa_ide_irq_handler(ipc_call_t *, void *);
    6262
    6363static void isa_ide_write_data_16(void *, uint16_t *, size_t);
     
    256256
    257257        ddf_msg(LVL_NOTE, "IRQ %d", chan->irq);
    258         rc = register_interrupt_handler_arg(chan->ctrl->dev, chan->irq,
     258        rc = register_interrupt_handler(chan->ctrl->dev, chan->irq,
    259259            isa_ide_irq_handler, (void *)chan, &irq_code, &chan->ihandle);
    260260        if (rc != EOK) {
     
    291291 *
    292292 * @param call Call data
    293  * @param dev Device that caused the interrupt
    294  */
    295 static void isa_ide_irq_handler(ipc_call_t *call, ddf_dev_t *xdev)
    296 {
    297         isa_ide_channel_t *chan = (isa_ide_channel_t *)(void *)xdev; // XXX
     293 * @param arg Argument (isa_ide_channel_t *)
     294 */
     295static void isa_ide_irq_handler(ipc_call_t *call, void *arg)
     296{
     297        isa_ide_channel_t *chan = (isa_ide_channel_t *)arg;
    298298        uint8_t status;
    299299        async_sess_t *parent_sess;
  • uspace/drv/block/virtio-blk/virtio-blk.c

    r646849b3 r60744cb  
    7373};
    7474
    75 static void virtio_blk_irq_handler(ipc_call_t *icall, ddf_dev_t *dev)
    76 {
    77         virtio_blk_t *virtio_blk = (virtio_blk_t *) ddf_dev_data_get(dev);
     75/** VirtIO block IRQ handler.
     76 *
     77 * @param icall IRQ event notification
     78 * @param arg Argument (virtio_blk_t *)
     79 */
     80static void virtio_blk_irq_handler(ipc_call_t *icall, void *arg)
     81{
     82        virtio_blk_t *virtio_blk = (virtio_blk_t *)arg;
    7883        virtio_dev_t *vdev = &virtio_blk->virtio_dev;
    7984
     
    145150
    146151        return register_interrupt_handler(dev, virtio_blk->irq,
    147             virtio_blk_irq_handler, &irq_code, &virtio_blk->irq_handle);
     152            virtio_blk_irq_handler, (void *)virtio_blk, &irq_code,
     153            &virtio_blk->irq_handle);
    148154}
    149155
  • uspace/drv/char/i8042/i8042.c

    r646849b3 r60744cb  
    123123 * Write new data to the corresponding buffer.
    124124 *
    125  * @param call pointerr to call data.
    126  * @param dev  Device that caued the interrupt.
    127  *
    128  */
    129 static void i8042_irq_handler(ipc_call_t *call, ddf_dev_t *dev)
    130 {
    131         i8042_t *controller = ddf_dev_data_get(dev);
     125 * @param call Pointer to call data.
     126 * @param arg  Argument (i8042_t *)
     127 */
     128static void i8042_irq_handler(ipc_call_t *call, void *arg)
     129{
     130        i8042_t *controller = (i8042_t *)arg;
    132131        errno_t rc;
    133132
     
    147146        fibril_condvar_broadcast(&port->buf_cv);
    148147
    149         async_sess_t *parent_sess = ddf_dev_parent_sess_get(dev);
     148        async_sess_t *parent_sess = ddf_dev_parent_sess_get(controller->dev);
    150149        hw_res_clear_interrupt(parent_sess, port->irq);
    151150}
     
    178177        bool aux_bound = false;
    179178
     179        dev->dev = ddf_dev;
     180
    180181        if (regs->size < sizeof(i8042_regs_t)) {
    181182                rc = EINVAL;
     
    288289        cap_irq_handle_t kbd_ihandle;
    289290        rc = register_interrupt_handler(ddf_dev, irq_kbd,
    290             i8042_irq_handler, &irq_code, &kbd_ihandle);
     291            i8042_irq_handler, (void *)dev, &irq_code, &kbd_ihandle);
    291292        if (rc != EOK) {
    292293                ddf_msg(LVL_ERROR, "Failed set handler for kbd: %s.",
     
    297298        cap_irq_handle_t mouse_ihandle;
    298299        rc = register_interrupt_handler(ddf_dev, irq_mouse,
    299             i8042_irq_handler, &irq_code, &mouse_ihandle);
     300            i8042_irq_handler, (void *)dev, &irq_code, &mouse_ihandle);
    300301        if (rc != EOK) {
    301302                ddf_msg(LVL_ERROR, "Failed set handler for mouse: %s.",
  • uspace/drv/char/i8042/i8042.h

    r646849b3 r60744cb  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * Copyright (c) 2006 Josef Cejka
    44 * Copyright (c) 2011 Jan Vesely
     
    8282/** i8042 Controller. */
    8383typedef struct i8042 {
     84        /** DDF device */
     85        ddf_dev_t *dev;
    8486        /** I/O registers. */
    8587        i8042_regs_t *regs;
  • uspace/drv/char/ns8250/ns8250.c

    r646849b3 r60744cb  
    783783 * data and reading the line status register.
    784784 *
    785  * @param dev The serial port device.
    786  *
    787  */
    788 static inline void ns8250_interrupt_handler(ipc_call_t *icall, ddf_dev_t *dev)
    789 {
    790         ns8250_t *ns = dev_ns8250(dev);
     785 * @pram icall IRQ event notificatoin
     786 * @param arg Argument (ns8250_t *)
     787 */
     788static inline void ns8250_interrupt_handler(ipc_call_t *icall, void *arg)
     789{
     790        ns8250_t *ns = (ns8250_t *)arg;
    791791        uint8_t iir = pio_read_8(&ns->regs->iid);
    792792        if ((iir & NS8250_IID_CAUSE_MASK) == NS8250_IID_CAUSE_RXSTATUS) {
     
    809809{
    810810        return register_interrupt_handler(ns->dev, ns->irq,
    811             ns8250_interrupt_handler, NULL, ihandle);
     811            ns8250_interrupt_handler, (void *)ns, NULL, ihandle);
    812812}
    813813
  • uspace/drv/char/pl050/pl050.c

    r646849b3 r60744cb  
    143143}
    144144
    145 static void pl050_interrupt(ipc_call_t *call, ddf_dev_t *dev)
    146 {
    147         pl050_t *pl050 = (pl050_t *)ddf_dev_data_get(dev);
     145/** PL050 interrupt handler
     146 *
     147 * @param call IRQ event notification
     148 * @param arg Argument (pl050_t *)
     149 */
     150static void pl050_interrupt(ipc_call_t *call, void *arg)
     151{
     152        pl050_t *pl050 = (pl050_t *)arg;
    148153        size_t nidx;
    149154
     
    220225        cap_irq_handle_t ihandle;
    221226        rc = register_interrupt_handler(pl050->dev,
    222             res.irqs.irqs[0], pl050_interrupt, &pl050_irq_code, &ihandle);
     227            res.irqs.irqs[0], pl050_interrupt, (void *)pl050, &pl050_irq_code,
     228            &ihandle);
    223229        if (rc != EOK) {
    224230                ddf_msg(LVL_ERROR, "Failed registering interrupt handler. (%s)",
  • uspace/drv/nic/e1k/e1k.c

    r646849b3 r60744cb  
    12441244 *
    12451245 * @param icall IPC call structure
    1246  * @param dev   E1000 device
    1247  *
    1248  */
    1249 static void e1000_interrupt_handler(ipc_call_t *icall,
    1250     ddf_dev_t *dev)
     1246 * @param arg   Argument (nic_t *)
     1247 *
     1248 */
     1249static void e1000_interrupt_handler(ipc_call_t *icall, void *arg)
    12511250{
    12521251        uint32_t icr = (uint32_t) ipc_get_arg2(icall);
    1253         nic_t *nic = NIC_DATA_DEV(dev);
     1252        nic_t *nic = (nic_t *)arg;
    12541253        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    12551254
     
    12831282
    12841283        errno_t rc = register_interrupt_handler(nic_get_ddf_dev(nic), e1000->irq,
    1285             e1000_interrupt_handler, &e1000_irq_code, handle);
     1284            e1000_interrupt_handler, (void *)nic, &e1000_irq_code, handle);
    12861285
    12871286        fibril_mutex_unlock(&irq_reg_mutex);
  • uspace/drv/nic/ne2k/ne2k.c

    r646849b3 r60744cb  
    121121};
    122122
    123 static void ne2k_interrupt_handler(ipc_call_t *, ddf_dev_t *);
     123static void ne2k_interrupt_handler(ipc_call_t *, void *);
    124124
    125125static errno_t ne2k_register_interrupt(nic_t *nic_data,
     
    161161
    162162        return register_interrupt_handler(nic_get_ddf_dev(nic_data),
    163             ne2k->irq, ne2k_interrupt_handler, &ne2k->code, handle);
     163            ne2k->irq, ne2k_interrupt_handler, (void *)nic_data, &ne2k->code,
     164            handle);
    164165}
    165166
     
    237238}
    238239
    239 void ne2k_interrupt_handler(ipc_call_t *call, ddf_dev_t *dev)
    240 {
    241         nic_t *nic_data = DRIVER_DATA(dev);
     240/** NE2K interrupt handler
     241 *
     242 * @param call IRQ event notification
     243 * @param arg Argument (nic_t *)
     244 */
     245void ne2k_interrupt_handler(ipc_call_t *call, void *arg)
     246{
     247        nic_t *nic_data = (nic_t *)arg;
    242248        ne2k_interrupt(nic_data, IRQ_GET_ISR(*call), IRQ_GET_TSR(*call));
    243249}
  • uspace/drv/nic/rtl8139/driver.c

    r646849b3 r60744cb  
    819819 *
    820820 * @param icall  The IPC call structure
    821  * @param dev    The rtl8139 device
    822  *
    823  */
    824 static void rtl8139_interrupt_handler(ipc_call_t *icall, ddf_dev_t *dev)
    825 {
    826         assert(dev);
    827         assert(icall);
    828 
     821 * @param arg    Argument (nic_t *)
     822 *
     823 */
     824static void rtl8139_interrupt_handler(ipc_call_t *icall, void *arg)
     825{
    829826        uint16_t isr = (uint16_t) ipc_get_arg2(icall);
    830         nic_t *nic_data = nic_get_from_ddf_dev(dev);
     827        nic_t *nic_data = (nic_t *)arg;
    831828        rtl8139_t *rtl8139 = nic_get_specific(nic_data);
    832829
     
    861858        rtl8139_irq_code.cmds[3].addr = rtl8139->io_addr + IMR;
    862859        errno_t rc = register_interrupt_handler(nic_get_ddf_dev(nic_data),
    863             rtl8139->irq, rtl8139_interrupt_handler, &rtl8139_irq_code, handle);
     860            rtl8139->irq, rtl8139_interrupt_handler, (void *)nic_data,
     861            &rtl8139_irq_code, handle);
    864862
    865863        RTL8139_IRQ_STRUCT_UNLOCK();
  • uspace/drv/nic/rtl8169/driver.c

    r646849b3 r60744cb  
    7474static errno_t rtl8169_on_stopped(nic_t *nic_data);
    7575static void rtl8169_send_frame(nic_t *nic_data, void *data, size_t size);
    76 static void rtl8169_irq_handler(ipc_call_t *icall, ddf_dev_t *dev);
     76static void rtl8169_irq_handler(ipc_call_t *icall, void *);
    7777static inline errno_t rtl8169_register_int_handler(nic_t *nic_data,
    7878    cap_irq_handle_t *handle);
     
    372372        rtl8169_irq_code.cmds[3].addr = rtl8169->regs + IMR;
    373373        errno_t rc = register_interrupt_handler(nic_get_ddf_dev(nic_data),
    374             rtl8169->irq, rtl8169_irq_handler, &rtl8169_irq_code, handle);
     374            rtl8169->irq, rtl8169_irq_handler, (void *)rtl8169,
     375            &rtl8169_irq_code, handle);
    375376
    376377        return rc;
     
    10331034}
    10341035
    1035 static void rtl8169_irq_handler(ipc_call_t *icall, ddf_dev_t *dev)
    1036 {
    1037         assert(dev);
    1038         assert(icall);
    1039 
     1036/** RTL8169 IRQ handler.
     1037 *
     1038 * @param icall IRQ event notification
     1039 * @param arg Argument (rtl8169_t *)
     1040 */
     1041static void rtl8169_irq_handler(ipc_call_t *icall, void *arg)
     1042{
    10401043        uint16_t isr = (uint16_t) ipc_get_arg2(icall) & INT_KNOWN;
    1041         nic_t *nic_data = nic_get_from_ddf_dev(dev);
    1042         rtl8169_t *rtl8169 = nic_get_specific(nic_data);
     1044        rtl8169_t *rtl8169 = (rtl8169_t *)arg;
    10431045
    10441046        ddf_msg(LVL_DEBUG, "rtl8169_irq_handler(): isr=0x%04x", isr);
     
    10501052                /* Packet underrun or link change */
    10511053                if (isr & INT_PUN) {
    1052                         rtl8169_link_change(dev);
     1054                        rtl8169_link_change(rtl8169->dev);
    10531055                        pio_write_16(rtl8169->regs + ISR, INT_PUN);
    10541056                }
     
    10561058                /* Transmit notification */
    10571059                if (isr & (INT_TER | INT_TOK | INT_TDU)) {
    1058                         rtl8169_transmit_done(dev);
     1060                        rtl8169_transmit_done(rtl8169->dev);
    10591061                        pio_write_16(rtl8169->regs + ISR, (INT_TER | INT_TOK | INT_TDU));
    10601062                }
     
    10721074
    10731075                if (isr & (INT_RER | INT_ROK)) {
    1074                         rtl8169_receive_done(dev);
     1076                        rtl8169_receive_done(rtl8169->dev);
    10751077                        pio_write_16(rtl8169->regs + ISR, (INT_RER | INT_ROK));
    10761078                }
  • uspace/drv/nic/virtio-net/virtio-net.c

    r646849b3 r60744cb  
    7070};
    7171
    72 static void virtio_net_irq_handler(ipc_call_t *icall, ddf_dev_t *dev)
    73 {
    74         nic_t *nic = ddf_dev_data_get(dev);
     72/** VirtIO net IRQ handler.
     73 *
     74 * @param icall IRQ event notification
     75 * @param arg Argument (nic_t *)
     76 */
     77static void virtio_net_irq_handler(ipc_call_t *icall, void *arg)
     78{
     79        nic_t *nic = (nic_t *)arg;
    7580        virtio_net_t *virtio_net = nic_get_specific(nic);
    7681        virtio_dev_t *vdev = &virtio_net->virtio_dev;
     
    164169
    165170        return register_interrupt_handler(dev, virtio_net->irq,
    166             virtio_net_irq_handler, &irq_code, &virtio_net->irq_handle);
     171            virtio_net_irq_handler, (void *)nic, &irq_code,
     172            &virtio_net->irq_handle);
    167173}
    168174
  • uspace/lib/drv/generic/interrupt.c

    r646849b3 r60744cb  
    4444
    4545errno_t register_interrupt_handler(ddf_dev_t *dev, int irq,
    46     interrupt_handler_t *handler, const irq_code_t *irq_code,
    47     cap_irq_handle_t *handle)
    48 {
    49         return async_irq_subscribe(irq, (async_notification_handler_t) handler,
    50             dev, irq_code, handle);
    51 }
    52 
    53 errno_t register_interrupt_handler_arg(ddf_dev_t *dev, int irq,
    5446    interrupt_handler_t *handler, void *arg, const irq_code_t *irq_code,
    5547    cap_irq_handle_t *handle)
  • uspace/lib/drv/include/ddf/interrupt.h

    r646849b3 r60744cb  
    4949 */
    5050
    51 typedef void interrupt_handler_t(ipc_call_t *, ddf_dev_t *);
     51typedef void interrupt_handler_t(ipc_call_t *, void *);
    5252
    53 extern errno_t register_interrupt_handler(ddf_dev_t *, int, interrupt_handler_t *,
    54     const irq_code_t *, cap_irq_handle_t *);
    55 extern errno_t register_interrupt_handler_arg(ddf_dev_t *, int,
     53extern errno_t register_interrupt_handler(ddf_dev_t *, int,
    5654    interrupt_handler_t *, void *, const irq_code_t *, cap_irq_handle_t *);
    5755extern errno_t unregister_interrupt_handler(ddf_dev_t *, cap_irq_handle_t);
  • uspace/lib/usbhost/src/hcd.c

    r646849b3 r60744cb  
    9595 * TODO: Make the bus mechanism less flexible in irq handling and remove the
    9696 * lookup.
    97  */
    98 static void irq_handler(ipc_call_t *call, ddf_dev_t *dev)
    99 {
    100         assert(dev);
    101         hc_device_t *hcd = dev_to_hcd(dev);
     97 *
     98 * @param call Interrupt notification
     99 * @param arg Argument (hc_device_t *)
     100 */
     101static void irq_handler(ipc_call_t *call, void *arg)
     102{
     103        hc_device_t *hcd = (hc_device_t *)arg;
    102104
    103105        const uint32_t status = ipc_get_arg1(call);
     
    178180        cap_irq_handle_t ihandle;
    179181        ret = register_interrupt_handler(hcd->ddf_dev, irq, irq_handler,
    180             &irq_code, &ihandle);
     182            (void *)hcd, &irq_code, &ihandle);
    181183        irq_code_clean(&irq_code);
    182184        if (ret != EOK) {
Note: See TracChangeset for help on using the changeset viewer.