Changeset 646849b3 in mainline for uspace/drv/block/isa-ide/main.c


Ignore:
Timestamp:
2024-05-17T12:25:26Z (10 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
60744cb
Parents:
59c0f478
git-author:
Jiri Svoboda <jiri@…> (2024-05-16 19:25:07)
git-committer:
Jiri Svoboda <jiri@…> (2024-05-17 12:25:26)
Message:

Handle both IDE channels in the same driver instance

We need to work around libdrv not allowing us to distinguish
between two interrupts registered with the same device.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/block/isa-ide/main.c

    r59c0f478 r646849b3  
    8181                return rc;
    8282
    83         if (hw_res.io_ranges.count != 2) {
     83        if (hw_res.io_ranges.count != 4) {
    8484                rc = EINVAL;
    8585                goto error;
     
    8888        /* I/O ranges */
    8989
    90         addr_range_t *cmd_rng = &hw_res.io_ranges.ranges[0];
    91         addr_range_t *ctl_rng = &hw_res.io_ranges.ranges[1];
    92         ata_res->cmd = RNGABS(*cmd_rng);
    93         ata_res->ctl = RNGABS(*ctl_rng);
    94 
    95         if (RNGSZ(*ctl_rng) < sizeof(ata_ctl_t)) {
    96                 rc = EINVAL;
    97                 goto error;
    98         }
    99 
    100         if (RNGSZ(*cmd_rng) < sizeof(ata_cmd_t)) {
     90        addr_range_t *cmd1_rng = &hw_res.io_ranges.ranges[0];
     91        addr_range_t *ctl1_rng = &hw_res.io_ranges.ranges[1];
     92        addr_range_t *cmd2_rng = &hw_res.io_ranges.ranges[2];
     93        addr_range_t *ctl2_rng = &hw_res.io_ranges.ranges[3];
     94        ata_res->cmd1 = RNGABS(*cmd1_rng);
     95        ata_res->ctl1 = RNGABS(*ctl1_rng);
     96        ata_res->cmd2 = RNGABS(*cmd2_rng);
     97        ata_res->ctl2 = RNGABS(*ctl2_rng);
     98
     99        if (RNGSZ(*ctl1_rng) < sizeof(ata_ctl_t)) {
     100                rc = EINVAL;
     101                goto error;
     102        }
     103
     104        if (RNGSZ(*cmd1_rng) < sizeof(ata_cmd_t)) {
     105                rc = EINVAL;
     106                goto error;
     107        }
     108
     109        if (RNGSZ(*ctl2_rng) < sizeof(ata_ctl_t)) {
     110                rc = EINVAL;
     111                goto error;
     112        }
     113
     114        if (RNGSZ(*cmd2_rng) < sizeof(ata_cmd_t)) {
    101115                rc = EINVAL;
    102116                goto error;
     
    105119        /* IRQ */
    106120        if (hw_res.irqs.count > 0) {
    107                 ata_res->irq = hw_res.irqs.irqs[0];
     121                ata_res->irq1 = hw_res.irqs.irqs[0];
    108122        } else {
    109                 ata_res->irq = -1;
     123                ata_res->irq1 = -1;
     124        }
     125
     126        if (hw_res.irqs.count > 1) {
     127                ata_res->irq2 = hw_res.irqs.irqs[1];
     128        } else {
     129                ata_res->irq2 = -1;
    110130        }
    111131
     
    142162        ctrl->dev = dev;
    143163
    144         rc = isa_ide_ctrl_init(ctrl, &res);
     164        rc = isa_ide_channel_init(ctrl, &ctrl->channel[0], 0, &res);
     165        if (rc == ENOENT)
     166                goto error;
     167
     168        rc = isa_ide_channel_init(ctrl, &ctrl->channel[1], 1, &res);
    145169        if (rc == ENOENT)
    146170                goto error;
     
    157181}
    158182
    159 static char *isa_ide_fun_name(unsigned idx)
     183static char *isa_ide_fun_name(isa_ide_channel_t *chan, unsigned idx)
    160184{
    161185        char *fun_name;
    162186
    163         if (asprintf(&fun_name, "d%u", idx) < 0)
     187        if (asprintf(&fun_name, "c%ud%u", chan->chan_id, idx) < 0)
    164188                return NULL;
    165189
     
    167191}
    168192
    169 errno_t isa_ide_fun_create(isa_ide_ctrl_t *ctrl, unsigned idx, void *charg)
     193errno_t isa_ide_fun_create(isa_ide_channel_t *chan, unsigned idx, void *charg)
    170194{
    171195        errno_t rc;
     
    175199        bool bound = false;
    176200
    177         fun_name = isa_ide_fun_name(idx);
     201        fun_name = isa_ide_fun_name(chan, idx);
    178202        if (fun_name == NULL) {
    179203                ddf_msg(LVL_ERROR, "Out of memory.");
     
    182206        }
    183207
    184         fun = ddf_fun_create(ctrl->dev, fun_exposed, fun_name);
     208        fun = ddf_fun_create(chan->ctrl->dev, fun_exposed, fun_name);
    185209        if (fun == NULL) {
    186210                ddf_msg(LVL_ERROR, "Failed creating DDF function.");
     
    232256}
    233257
    234 errno_t isa_ide_fun_remove(isa_ide_ctrl_t *ctrl, unsigned idx)
     258errno_t isa_ide_fun_remove(isa_ide_channel_t *chan, unsigned idx)
    235259{
    236260        errno_t rc;
    237261        char *fun_name;
    238         isa_ide_fun_t *ifun = ctrl->fun[idx];
    239 
    240         fun_name = isa_ide_fun_name(idx);
     262        isa_ide_fun_t *ifun = chan->fun[idx];
     263
     264        fun_name = isa_ide_fun_name(chan, idx);
    241265        if (fun_name == NULL) {
    242266                ddf_msg(LVL_ERROR, "Out of memory.");
     
    267291}
    268292
    269 errno_t isa_ide_fun_unbind(isa_ide_ctrl_t *ctrl, unsigned idx)
     293errno_t isa_ide_fun_unbind(isa_ide_channel_t *chan, unsigned idx)
    270294{
    271295        errno_t rc;
    272296        char *fun_name;
    273         isa_ide_fun_t *ifun = ctrl->fun[idx];
    274 
    275         fun_name = isa_ide_fun_name(idx);
     297        isa_ide_fun_t *ifun = chan->fun[idx];
     298
     299        fun_name = isa_ide_fun_name(chan, idx);
    276300        if (fun_name == NULL) {
    277301                ddf_msg(LVL_ERROR, "Out of memory.");
     
    299323{
    300324        isa_ide_ctrl_t *ctrl = (isa_ide_ctrl_t *)ddf_dev_data_get(dev);
     325        errno_t rc;
    301326
    302327        ddf_msg(LVL_DEBUG, "isa_ide_dev_remove(%p)", dev);
    303328
    304         return isa_ide_ctrl_remove(ctrl);
     329        rc = isa_ide_channel_fini(&ctrl->channel[0]);
     330        if (rc != EOK)
     331                return rc;
     332
     333        rc = isa_ide_channel_fini(&ctrl->channel[1]);
     334        if (rc != EOK)
     335                return rc;
     336
     337        return EOK;
    305338}
    306339
     
    308341{
    309342        isa_ide_ctrl_t *ctrl = (isa_ide_ctrl_t *)ddf_dev_data_get(dev);
     343        errno_t rc;
    310344
    311345        ddf_msg(LVL_DEBUG, "isa_ide_dev_gone(%p)", dev);
    312346
    313         return isa_ide_ctrl_gone(ctrl);
     347        rc = isa_ide_channel_fini(&ctrl->channel[0]);
     348        if (rc != EOK)
     349                return rc;
     350
     351        rc = isa_ide_channel_fini(&ctrl->channel[1]);
     352        if (rc != EOK)
     353                return rc;
     354
     355        return EOK;
    314356}
    315357
Note: See TracChangeset for help on using the changeset viewer.