Ignore:
File:
1 edited

Legend:

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

    r443695e r2a5d4649  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4343
    4444#include "isa-ide.h"
     45#include "isa-ide_hw.h"
    4546#include "main.h"
    4647
     
    4849static errno_t isa_ide_dev_remove(ddf_dev_t *dev);
    4950static errno_t isa_ide_dev_gone(ddf_dev_t *dev);
     51static errno_t isa_ide_dev_quiesce(ddf_dev_t *dev);
    5052static errno_t isa_ide_fun_online(ddf_fun_t *fun);
    5153static errno_t isa_ide_fun_offline(ddf_fun_t *fun);
     
    5456
    5557static driver_ops_t driver_ops = {
    56         .dev_add = &isa_ide_dev_add,
    57         .dev_remove = &isa_ide_dev_remove,
    58         .dev_gone = &isa_ide_dev_gone,
    59         .fun_online = &isa_ide_fun_online,
    60         .fun_offline = &isa_ide_fun_offline
     58        .dev_add = isa_ide_dev_add,
     59        .dev_remove = isa_ide_dev_remove,
     60        .dev_gone = isa_ide_dev_gone,
     61        .dev_quiesce = isa_ide_dev_quiesce,
     62        .fun_online = isa_ide_fun_online,
     63        .fun_offline = isa_ide_fun_offline
    6164};
    6265
     
    7073        async_sess_t *parent_sess;
    7174        hw_res_list_parsed_t hw_res;
    72         hw_res_flags_t flags;
     75        hw_res_claims_t claims;
    7376        errno_t rc;
    7477
     
    7780                return ENOMEM;
    7881
    79         rc = hw_res_get_flags(parent_sess, &flags);
    80         if (rc != EOK)
    81                 return rc;
    82 
    83         /*
    84          * Prevent attaching to the legacy ISA IDE register block
    85          * on a system with PCI not to conflict with PCI IDE.
    86          *
    87          * XXX This is a simplification. If we had a PCI-based system without
    88          * PCI-IDE or with PCI-IDE disabled and would still like to use
    89          * an ISA IDE controller, this would prevent us from doing so.
    90          */
    91         if (flags & hwf_isa_bridge) {
    92                 ddf_msg(LVL_NOTE, "Will not attach to PCI/ISA bridge.");
    93                 return EIO;
     82        rc = hw_res_query_legacy_io(parent_sess, &claims);
     83        if (rc != EOK) {
     84                ddf_msg(LVL_NOTE, "Error getting HW resource flags.");
     85                return rc;
    9486        }
    9587
    9688        hw_res_list_parsed_init(&hw_res);
    9789        rc = hw_res_get_list_parsed(parent_sess, &hw_res, 0);
    98         if (rc != EOK)
    99                 return rc;
     90        if (rc != EOK) {
     91                ddf_msg(LVL_NOTE, "Error getting HW resource list.");
     92                return rc;
     93        }
    10094
    10195        if (hw_res.io_ranges.count != 4) {
     
    148142        }
    149143
     144        /*
     145         * Only attach to legacy ISA IDE register block if it
     146         * is not claimed by PCI IDE driver.
     147         */
     148        if (res->cmd1 == leg_ide_ata_cmd_p &&
     149            res->cmd2 == leg_ide_ata_cmd_s &&
     150            (claims & hwc_isa_ide) != 0) {
     151                ddf_msg(LVL_NOTE, "Will not attach to ISA legacy ports "
     152                    "since they are already handled by PCI.");
     153                return EBUSY;
     154        }
     155
    150156        return EOK;
    151157error:
     
    163169        isa_ide_ctrl_t *ctrl;
    164170        isa_ide_hwres_t res;
     171        unsigned chans;
    165172        errno_t rc;
    166173
    167174        rc = isa_ide_get_res(dev, &res);
    168175        if (rc != EOK) {
    169                 ddf_msg(LVL_ERROR, "Invalid HW resource configuration.");
     176                if (rc == EINVAL)
     177                        ddf_msg(LVL_ERROR, "Invalid HW resource configuration.");
    170178                return EINVAL;
    171179        }
     
    180188        ctrl->dev = dev;
    181189
     190        chans = 0;
     191
    182192        rc = isa_ide_channel_init(ctrl, &ctrl->channel[0], 0, &res);
    183         if (rc == ENOENT)
     193        if (rc == EOK)
     194                ++chans;
     195        else if (rc != ENOENT)
    184196                goto error;
    185197
    186198        rc = isa_ide_channel_init(ctrl, &ctrl->channel[1], 1, &res);
    187         if (rc == ENOENT)
    188                 goto error;
    189 
    190         if (rc != EOK) {
    191                 ddf_msg(LVL_ERROR, "Failed initializing ATA controller.");
     199        if (rc == EOK)
     200                ++chans;
     201        else if (rc != ENOENT)
     202                goto error;
     203
     204        if (chans == 0) {
     205                ddf_msg(LVL_ERROR, "No ISA IDE devices found.");
    192206                rc = EIO;
    193207                goto error;
     
    374388}
    375389
     390static errno_t isa_ide_dev_quiesce(ddf_dev_t *dev)
     391{
     392        isa_ide_ctrl_t *ctrl = (isa_ide_ctrl_t *)ddf_dev_data_get(dev);
     393
     394        ddf_msg(LVL_DEBUG, "isa_ide_dev_quiesce(%p)", dev);
     395
     396        isa_ide_channel_quiesce(&ctrl->channel[0]);
     397        isa_ide_channel_quiesce(&ctrl->channel[1]);
     398        return EOK;
     399}
     400
    376401static errno_t isa_ide_fun_online(ddf_fun_t *fun)
    377402{
Note: See TracChangeset for help on using the changeset viewer.