Changeset 443695e in mainline


Ignore:
Timestamp:
2024-05-21T11:33:56Z (2 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
3526f4f3
Parents:
1801005
git-author:
Jiri Svoboda <jiri@…> (2024-05-20 17:33:43)
git-committer:
Jiri Svoboda <jiri@…> (2024-05-21 11:33:56)
Message:

Basic PCI-IDE driver (no DMA support)

Also, make sure we avoid attaching ISA IDE and PCI IDE
at the same time. For simplicity, use ISA IDE on ISA systems
and PCI IDE on PCI-based systems.

Files:
8 added
10 edited

Legend:

Unmodified
Added
Removed
  • meson/arch/amd64/meson.build

    r1801005 r443695e  
    7777        'drv/block/ahci',
    7878        'drv/block/isa-ide',
     79        'drv/block/pci-ide',
    7980        'drv/block/usbmast',
    8081        'drv/block/virtio-blk',
  • meson/arch/ia32/meson.build

    r1801005 r443695e  
    8383        'drv/block/ahci',
    8484        'drv/block/isa-ide',
     85        'drv/block/pci-ide',
    8586        'drv/block/usbmast',
    8687        'drv/block/virtio-blk',
  • uspace/drv/block/isa-ide/isa-ide.c

    r1801005 r443695e  
    3434 * @file
    3535 * @brief ISA IDE driver
    36  *
    37  * The driver services a single IDE channel.
    3836 */
    3937
  • uspace/drv/block/isa-ide/main.c

    r1801005 r443695e  
    6666};
    6767
    68 static errno_t ata_get_res(ddf_dev_t *dev, isa_ide_hwres_t *ata_res)
     68static errno_t isa_ide_get_res(ddf_dev_t *dev, isa_ide_hwres_t *res)
    6969{
    7070        async_sess_t *parent_sess;
    7171        hw_res_list_parsed_t hw_res;
     72        hw_res_flags_t flags;
    7273        errno_t rc;
    7374
     
    7576        if (parent_sess == NULL)
    7677                return ENOMEM;
     78
     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;
     94        }
    7795
    7896        hw_res_list_parsed_init(&hw_res);
     
    92110        addr_range_t *cmd2_rng = &hw_res.io_ranges.ranges[2];
    93111        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);
     112        res->cmd1 = RNGABS(*cmd1_rng);
     113        res->ctl1 = RNGABS(*ctl1_rng);
     114        res->cmd2 = RNGABS(*cmd2_rng);
     115        res->ctl2 = RNGABS(*ctl2_rng);
    98116
    99117        if (RNGSZ(*ctl1_rng) < sizeof(ata_ctl_t)) {
     
    119137        /* IRQ */
    120138        if (hw_res.irqs.count > 0) {
    121                 ata_res->irq1 = hw_res.irqs.irqs[0];
     139                res->irq1 = hw_res.irqs.irqs[0];
    122140        } else {
    123                 ata_res->irq1 = -1;
     141                res->irq1 = -1;
    124142        }
    125143
    126144        if (hw_res.irqs.count > 1) {
    127                 ata_res->irq2 = hw_res.irqs.irqs[1];
     145                res->irq2 = hw_res.irqs.irqs[1];
    128146        } else {
    129                 ata_res->irq2 = -1;
     147                res->irq2 = -1;
    130148        }
    131149
     
    147165        errno_t rc;
    148166
    149         rc = ata_get_res(dev, &res);
     167        rc = isa_ide_get_res(dev, &res);
    150168        if (rc != EOK) {
    151169                ddf_msg(LVL_ERROR, "Invalid HW resource configuration.");
  • uspace/drv/bus/isa/isa.c

    r1801005 r443695e  
    7676typedef struct {
    7777        fibril_mutex_t mutex;
     78        bool pci_isa_bridge;
    7879        uint16_t pci_vendor_id;
    7980        uint16_t pci_device_id;
     
    9293        hw_resource_list_t hw_resources;
    9394        link_t bus_link;
     95        isa_bus_t *bus;
    9496} isa_fun_t;
    9597
     
    204206}
    205207
     208static errno_t isa_fun_get_flags(ddf_fun_t *fnode, hw_res_flags_t *rflags)
     209{
     210        isa_fun_t *fun = isa_fun(fnode);
     211        hw_res_flags_t flags;
     212
     213        flags = 0;
     214        if (fun->bus->pci_isa_bridge)
     215                flags |= hwf_isa_bridge;
     216
     217        ddf_msg(LVL_NOTE, "isa_fun_get_flags: returning 0x%x", flags);
     218        *rflags = flags;
     219        return EOK;
     220}
     221
    206222static hw_res_ops_t isa_fun_hw_res_ops = {
    207223        .get_resource_list = isa_fun_get_resources,
     
    211227        .dma_channel_setup = isa_fun_setup_dma,
    212228        .dma_channel_remain = isa_fun_remain_dma,
     229        .get_flags = isa_fun_get_flags
    213230};
    214231
     
    264281        fibril_mutex_initialize(&fun->mutex);
    265282        fun->hw_resources.resources = fun->resources;
     283        fun->bus = isa;
    266284
    267285        fun->fnode = fnode;
     
    743761        if (rc != EOK) {
    744762                ddf_msg(LVL_NOTE, "Cannot read PCI config. Assuming ISA classic.");
     763                isa->pci_isa_bridge = false;
    745764                isa->pci_vendor_id = 0;
    746765                isa->pci_device_id = 0;
    747766                isa->pci_class = BASE_CLASS_BRIDGE;
    748767                isa->pci_subclass = SUB_CLASS_BRIDGE_ISA;
     768        } else {
     769                ddf_msg(LVL_NOTE, "ISA Bridge");
     770                isa->pci_isa_bridge = true;
    749771        }
    750772
  • uspace/drv/meson.build

    r1801005 r443695e  
    3535        'block/ddisk',
    3636        'block/isa-ide',
     37        'block/pci-ide',
    3738        'block/usbmast',
    3839        'block/virtio-blk',
  • uspace/lib/c/generic/device/hw_res.c

    r1801005 r443695e  
    11/*
     2 * Copyright (c) 2024 Jiri Svoboda
    23 * Copyright (c) 2010 Lenka Trochtova
    34 * All rights reserved.
     
    161162}
    162163
     164/** Get bus flags.
     165 *
     166 * @param sess HW res session
     167 * @param rflags Place to store the flags
     168 *
     169 * @return Error code.
     170 *
     171 */
     172errno_t hw_res_get_flags(async_sess_t *sess, hw_res_flags_t *rflags)
     173{
     174        async_exch_t *exch = async_exchange_begin(sess);
     175
     176        sysarg_t flags;
     177        const errno_t ret = async_req_1_1(exch, DEV_IFACE_ID(HW_RES_DEV_IFACE),
     178            HW_RES_GET_FLAGS, &flags);
     179
     180        async_exchange_end(exch);
     181
     182        if (ret == EOK)
     183                *rflags = flags;
     184
     185        return ret;
     186}
     187
    163188/** @}
    164189 */
  • uspace/lib/c/include/device/hw_res.h

    r1801005 r443695e  
    11/*
     2 * Copyright (c) 2024 Jiri Svoboda
    23 * Copyright (c) 2010 Lenka Trochtova
    34 * All rights reserved.
     
    5657        HW_RES_DMA_CHANNEL_SETUP,
    5758        HW_RES_DMA_CHANNEL_REMAIN,
     59        HW_RES_GET_FLAGS
    5860} hw_res_method_t;
    5961
     
    116118}
    117119
     120typedef enum {
     121        /** This is an PCI/ISA bridge, not 'classic' ISA bus */
     122        hwf_isa_bridge = 0x1
     123} hw_res_flags_t;
     124
    118125extern errno_t hw_res_get_resource_list(async_sess_t *, hw_resource_list_t *);
    119126extern errno_t hw_res_enable_interrupt(async_sess_t *, int);
     
    124131    uint32_t, uint8_t);
    125132extern errno_t hw_res_dma_channel_remain(async_sess_t *, unsigned, size_t *);
     133extern errno_t hw_res_get_flags(async_sess_t *, hw_res_flags_t *);
    126134
    127135#endif
  • uspace/lib/drv/generic/remote_hw_res.c

    r1801005 r443695e  
    11/*
     2 * Copyright (c) 2024 Jiri Svoboda
    23 * Copyright (c) 2010 Lenka Trochtova
    34 * Copyright (c) 2011 Jan Vesely
     
    4748static void remote_hw_res_dma_channel_setup(ddf_fun_t *, void *, ipc_call_t *);
    4849static void remote_hw_res_dma_channel_remain(ddf_fun_t *, void *, ipc_call_t *);
     50static void remote_hw_res_get_flags(ddf_fun_t *, void *, ipc_call_t *);
    4951
    5052static const remote_iface_func_ptr_t remote_hw_res_iface_ops [] = {
     
    5557        [HW_RES_DMA_CHANNEL_SETUP] = &remote_hw_res_dma_channel_setup,
    5658        [HW_RES_DMA_CHANNEL_REMAIN] = &remote_hw_res_dma_channel_remain,
     59        [HW_RES_GET_FLAGS] = &remote_hw_res_get_flags
    5760};
    5861
     
    171174}
    172175
     176static void remote_hw_res_get_flags(ddf_fun_t *fun, void *ops,
     177    ipc_call_t *call)
     178{
     179        hw_res_ops_t *hw_res_ops = ops;
     180
     181        if (hw_res_ops->get_flags == NULL) {
     182                async_answer_0(call, ENOTSUP);
     183                return;
     184        }
     185
     186        hw_res_flags_t flags = 0;
     187        const errno_t ret = hw_res_ops->get_flags(fun, &flags);
     188        async_answer_1(call, ret, flags);
     189}
     190
    173191/**
    174192 * @}
  • uspace/lib/drv/include/ops/hw_res.h

    r1801005 r443695e  
    11/*
     2 * Copyright (c) 2024 Jiri Svoboda
    23 * Copyright (c) 2010 Lenka Trochtova
    34 * Copyright (c) 2011 Jan Vesely
     
    4950        errno_t (*dma_channel_setup)(ddf_fun_t *, unsigned, uint32_t, uint32_t, uint8_t);
    5051        errno_t (*dma_channel_remain)(ddf_fun_t *, unsigned, size_t *);
     52        errno_t (*get_flags)(ddf_fun_t *, hw_res_flags_t *);
    5153} hw_res_ops_t;
    5254
Note: See TracChangeset for help on using the changeset viewer.