Changeset 5c55eb7 in mainline


Ignore:
Timestamp:
2025-06-10T09:39:41Z (5 days ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
c44b399
Parents:
0f5c4e4
git-author:
Jiri Svoboda <jiri@…> (2025-06-09 17:39:30)
git-committer:
Jiri Svoboda <jiri@…> (2025-06-10 09:39:41)
Message:

Fold uspace/srv/bd/sata_bd into uspace/drv/block/ahci.

Location:
uspace
Files:
6 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/block/ahci/ahci.c

    r0f5c4e4 r5c55eb7  
    3333
    3434#include <as.h>
     35#include <bd_srv.h>
    3536#include <errno.h>
    3637#include <stdio.h>
     
    4041#include <device/hw_res_parsed.h>
    4142#include <pci_dev_iface.h>
    42 #include <ahci_iface.h>
    4343#include "ahci.h"
    4444#include "ahci_hw.h"
     
    110110        }
    111111
    112 static errno_t get_sata_device_name(ddf_fun_t *, size_t, char *);
    113 static errno_t get_num_blocks(ddf_fun_t *, uint64_t *);
    114 static errno_t get_block_size(ddf_fun_t *, size_t *);
    115 static errno_t read_blocks(ddf_fun_t *, uint64_t, size_t, void *);
    116 static errno_t write_blocks(ddf_fun_t *, uint64_t, size_t, void *);
     112static errno_t ahci_read_blocks(sata_dev_t *, uint64_t, size_t, void *);
     113static errno_t ahci_write_blocks(sata_dev_t *, uint64_t, size_t, void *);
    117114
    118115static errno_t ahci_identify_device(sata_dev_t *);
     
    132129static int sata_devices_count = 0;
    133130
    134 /*
    135  * AHCI Interface
    136  */
    137 
    138 static ahci_iface_t ahci_interface = {
    139         .get_sata_device_name = &get_sata_device_name,
    140         .get_num_blocks = &get_num_blocks,
    141         .get_block_size = &get_block_size,
    142         .read_blocks = &read_blocks,
    143         .write_blocks = &write_blocks
    144 };
    145 
    146 static ddf_dev_ops_t ahci_ops = {
    147         .interfaces[AHCI_DEV_IFACE] = &ahci_interface
     131static errno_t ahci_bd_open(bd_srvs_t *, bd_srv_t *);
     132static errno_t ahci_bd_close(bd_srv_t *);
     133static errno_t ahci_bd_read_blocks(bd_srv_t *, aoff64_t, size_t, void *, size_t);
     134static errno_t ahci_bd_write_blocks(bd_srv_t *, aoff64_t, size_t, const void *, size_t);
     135static errno_t ahci_bd_get_block_size(bd_srv_t *, size_t *);
     136static errno_t ahci_bd_get_num_blocks(bd_srv_t *, aoff64_t *);
     137
     138static void ahci_bd_connection(ipc_call_t *, void *);
     139
     140static bd_ops_t ahci_bd_ops = {
     141        .open = ahci_bd_open,
     142        .close = ahci_bd_close,
     143        .read_blocks = ahci_bd_read_blocks,
     144        .write_blocks = ahci_bd_write_blocks,
     145        .get_block_size = ahci_bd_get_block_size,
     146        .get_num_blocks = ahci_bd_get_num_blocks
    148147};
    149148
     
    157156};
    158157
    159 /** Get SATA structure from DDF function. */
    160 static sata_dev_t *fun_sata_dev(ddf_fun_t *fun)
    161 {
    162         return ddf_fun_data_get(fun);
    163 }
    164 
    165 /** Get SATA device name.
    166  *
    167  * @param fun                  Device function handling the call.
    168  * @param sata_dev_name_length Length of the sata_dev_name buffer.
    169  * @param sata_dev_name        Buffer for SATA device name.
    170  *
    171  * @return EOK.
    172  *
    173  */
    174 static errno_t get_sata_device_name(ddf_fun_t *fun,
    175     size_t sata_dev_name_length, char *sata_dev_name)
    176 {
    177         sata_dev_t *sata = fun_sata_dev(fun);
    178         str_cpy(sata_dev_name, sata_dev_name_length, sata->model);
    179         return EOK;
    180 }
    181 
    182 /** Get Number of blocks in SATA device.
    183  *
    184  * @param fun    Device function handling the call.
    185  * @param blocks Return number of blocks in SATA device.
    186  *
    187  * @return EOK.
    188  *
    189  */
    190 static errno_t get_num_blocks(ddf_fun_t *fun, uint64_t *num_blocks)
    191 {
    192         sata_dev_t *sata = fun_sata_dev(fun);
    193         *num_blocks = sata->blocks;
    194         return EOK;
    195 }
    196 
    197 /** Get SATA device block size.
    198  *
    199  * @param fun        Device function handling the call.
    200  * @param block_size Return block size.
    201  *
    202  * @return EOK.
    203  *
    204  */
    205 static errno_t get_block_size(ddf_fun_t *fun, size_t *block_size)
    206 {
    207         sata_dev_t *sata = fun_sata_dev(fun);
    208         *block_size = sata->block_size;
    209         return EOK;
    210 }
    211 
    212 /** Read data blocks into SATA device.
    213  *
    214  * @param fun      Device function handling the call.
     158/** Get SATA structure from block device service structure. */
     159static sata_dev_t *bd_srv_sata(bd_srv_t *bd)
     160{
     161        return (sata_dev_t *) bd->srvs->sarg;
     162}
     163
     164/** Read data blocks from SATA device.
     165 *
     166 * @param sata     SATA device
    215167 * @param blocknum Number of first block.
    216168 * @param count    Number of blocks to read.
    217169 * @param buf      Buffer for data.
    218170 *
    219  * @return EOK if succeed, error code otherwise
    220  *
    221  */
    222 static errno_t read_blocks(ddf_fun_t *fun, uint64_t blocknum,
     171 * @return EOK on success, error code otherwise
     172 *
     173 */
     174static errno_t ahci_read_blocks(sata_dev_t *sata, uint64_t blocknum,
    223175    size_t count, void *buf)
    224176{
    225         sata_dev_t *sata = fun_sata_dev(fun);
    226 
    227177        uintptr_t phys;
    228178        void *ibuf = AS_AREA_ANY;
     
    253203}
    254204
    255 /** Write data blocks into SATA device.
    256  *
    257  * @param fun      Device function handling the call.
     205/** Write data blocks to SATA device.
     206 *
     207 * @param sata     SATA device
    258208 * @param blocknum Number of first block.
    259209 * @param count    Number of blocks to write.
    260210 * @param buf      Buffer with data.
    261211 *
    262  * @return EOK if succeed, error code otherwise
    263  *
    264  */
    265 static errno_t write_blocks(ddf_fun_t *fun, uint64_t blocknum,
     212 * @return EOK on success, error code otherwise
     213 */
     214static errno_t ahci_write_blocks(sata_dev_t *sata, uint64_t blocknum,
    266215    size_t count, void *buf)
    267216{
    268         sata_dev_t *sata = fun_sata_dev(fun);
    269 
    270217        uintptr_t phys;
    271218        void *ibuf = AS_AREA_ANY;
     
    291238
    292239        return rc;
     240}
     241
     242/** Open device. */
     243static errno_t ahci_bd_open(bd_srvs_t *bds, bd_srv_t *bd)
     244{
     245        return EOK;
     246}
     247
     248/** Close device. */
     249static errno_t ahci_bd_close(bd_srv_t *bd)
     250{
     251        return EOK;
     252}
     253
     254/** Read blocks from partition. */
     255static errno_t ahci_bd_read_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt,
     256    void *buf, size_t size)
     257{
     258        sata_dev_t *sata = bd_srv_sata(bd);
     259
     260        if (size < cnt * sata->block_size)
     261                return EINVAL;
     262
     263        return ahci_read_blocks(sata, ba, cnt, buf);
     264}
     265
     266/** Write blocks to partition. */
     267static errno_t ahci_bd_write_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt,
     268    const void *buf, size_t size)
     269{
     270        sata_dev_t *sata = bd_srv_sata(bd);
     271
     272        if (size < cnt * sata->block_size)
     273                return EINVAL;
     274
     275        return ahci_write_blocks(sata, ba, cnt, (void *)buf);
     276}
     277
     278/** Get device block size. */
     279static errno_t ahci_bd_get_block_size(bd_srv_t *bd, size_t *rsize)
     280{
     281        sata_dev_t *sata = bd_srv_sata(bd);
     282
     283        *rsize = sata->block_size;
     284        return EOK;
     285}
     286
     287/** Get number of blocks on device. */
     288static errno_t ahci_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb)
     289{
     290        sata_dev_t *sata = bd_srv_sata(bd);
     291
     292        *rnb = sata->blocks;
     293        return EOK;
     294}
     295
     296static void ahci_bd_connection(ipc_call_t *icall, void *arg)
     297{
     298        sata_dev_t *sata;
     299
     300        sata = (sata_dev_t *) ddf_fun_data_get((ddf_fun_t *)arg);
     301        bd_conn(icall, &sata->bds);
    293302}
    294303
     
    416425 * @param sata SATA device structure.
    417426 *
    418  * @return EOK if succeed, error code otherwise.
     427 * @return EOK on success, error code otherwise.
    419428 *
    420429 */
     
    597606 * @param sata SATA device structure.
    598607 *
    599  * @return EOK if succeed, error code otherwise
     608 * @return EOK on success, error code otherwise
    600609 *
    601610 */
     
    726735 * @param blocknum Block number to read.
    727736 *
    728  * @return EOK if succeed, error code otherwise
     737 * @return EOK on success, error code otherwise
    729738 *
    730739 */
     
    755764 * @param blocknum Block number to write.
    756765 *
    757  * @return EOK if succeed, error code otherwise
     766 * @return EOK on success, error code otherwise
    758767 *
    759768 */
     
    814823 * @param blocknum Block number to write.
    815824 *
    816  * @return EOK if succeed, error code otherwise
     825 * @return EOK on success, error code otherwise
    817826 *
    818827 */
     
    921930 * @param port AHCI port structure
    922931 *
    923  * @return SATA device structure if succeed, NULL otherwise.
     932 * @return SATA device structure on success, NULL otherwise.
    924933 *
    925934 */
     
    10291038 * @param port_num Number of AHCI port with existing SATA device.
    10301039 *
    1031  * @return EOK if succeed, error code otherwise.
     1040 * @return EOK on success, error code otherwise.
    10321041 *
    10331042 */
     
    10361045{
    10371046        ddf_fun_t *fun = NULL;
     1047        bool bound = false;
    10381048        errno_t rc;
    10391049
     
    10771087
    10781088        fun = sata->fun;
    1079         ddf_fun_set_ops(fun, &ahci_ops);
     1089
     1090        bd_srvs_init(&sata->bds);
     1091        sata->bds.ops = &ahci_bd_ops;
     1092        sata->bds.sarg = (void *)sata;
     1093
     1094        /* Set up a connection handler. */
     1095        ddf_fun_set_conn_handler(fun, ahci_bd_connection);
     1096
     1097        ddf_msg(LVL_NOTE, "Device %s - %s, blocks: %" PRIu64
     1098            " block_size: %zu\n", sata_dev_name, sata->model, sata->blocks,
     1099            sata->block_size);
    10801100
    10811101        rc = ddf_fun_bind(fun);
     
    10851105        }
    10861106
     1107        bound = true;
     1108
     1109        rc = ddf_fun_add_to_category(fun, "disk");
     1110        if (rc != EOK) {
     1111                ddf_msg(LVL_ERROR, "Failed adding function %s to category "
     1112                    "'disk'.", sata_dev_name);
     1113                goto error;
     1114        }
     1115
    10871116        return EOK;
    10881117
    10891118error:
     1119        if (bound)
     1120                ddf_fun_unbind(fun);
    10901121        sata->is_invalid_device = true;
    10911122        if (fun != NULL)
     
    11241155 * @param dev DDF device structure.
    11251156 *
    1126  * @return AHCI device structure if succeed, NULL otherwise.
     1157 * @return AHCI device structure on success, NULL otherwise.
    11271158 *
    11281159 */
     
    12481279 * @param dev DDF device structure.
    12491280 *
    1250  * @return EOK if succeed, error code otherwise.
     1281 * @return EOK on success, error code otherwise.
    12511282 *
    12521283 */
  • uspace/drv/block/ahci/ahci.h

    r0f5c4e4 r5c55eb7  
    11/*
     2 * Copyright (c) 2025 Jiri Svoboda
    23 * Copyright (c) 2012 Petr Jerman
    34 * All rights reserved.
     
    3132 */
    3233
    33 #ifndef __AHCI_H__
    34 #define __AHCI_H__
     34#ifndef AHCI_H
     35#define AHCI_H
    3536
    3637#include <async.h>
     38#include <bd_srv.h>
    3739#include <ddf/interrupt.h>
    3840#include <stdio.h>
     
    105107        /** Highest UDMA mode supported. */
    106108        uint8_t highest_udma_mode;
     109
     110        /** Block device service structure */
     111        bd_srvs_t bds;
    107112} sata_dev_t;
    108113
  • uspace/drv/block/ahci/ahci_hw.h

    r0f5c4e4 r5c55eb7  
    11/*
     2 * Copyright (c) 2025 Jiri Svoboda
    23 * Copyright (c) 2012 Petr Jerman
    34 * All rights reserved.
     
    3132 */
    3233
    33 #ifndef __AHCI_HW_H__
    34 #define __AHCI_HW_H__
     34#ifndef AHCI_HW_H
     35#define AHCI_HW_H
    3536
    3637#include <stdint.h>
  • uspace/drv/block/ahci/ahci_sata.h

    r0f5c4e4 r5c55eb7  
    11/*
     2 * Copyright (c) 2025 Jiri Svoboda
    23 * Copyright (c) 2012 Petr Jerman
    34 * All rights reserved.
     
    3132 */
    3233
    33 #ifndef __AHCI_SATA_H__
    34 #define __AHCI_SATA_H__
     34#ifndef AHCI_SATA_H
     35#define AHCI_SATA_H
    3536
    3637#include <stdint.h>
  • uspace/lib/drv/generic/dev_iface.c

    r0f5c4e4 r5c55eb7  
    11/*
     2 * Copyright (c) 2025 Jiri Svoboda
    23 * Copyright (c) 2010 Lenka Trochtova
    34 * All rights reserved.
     
    5354#include "remote_audio_mixer.h"
    5455#include "remote_audio_pcm.h"
    55 #include "remote_ahci.h"
    5656
    5757static const iface_dipatch_table_t remote_ifaces = {
     
    7171                [LED_DEV_IFACE] = &remote_led_dev_iface,
    7272                [BATTERY_DEV_IFACE] = &remote_battery_dev_iface,
    73                 [AHCI_DEV_IFACE] = &remote_ahci_iface,
    7473        }
    7574};
  • uspace/lib/drv/meson.build

    r0f5c4e4 r5c55eb7  
    11#
     2# Copyright (c) 2025 Jiri Svoboda
    23# Copyright (c) 2005 Martin Decky
    34# Copyright (c) 2007 Jakub Jermar
     
    5051        'generic/remote_led_dev.c',
    5152        'generic/remote_battery_dev.c',
    52         'generic/remote_ahci.c',
    5353)
  • uspace/srv/meson.build

    r0f5c4e4 r5c55eb7  
    11#
    2 # Copyright (c) 2024 Jiri Svoboda
     2# Copyright (c) 2025 Jiri Svoboda
    33# Copyright (c) 2019 Jiří Zárevúcky
    44# All rights reserved.
     
    3232        'bd/file_bd',
    3333        'bd/rd',
    34         'bd/sata_bd',
    3534        'bd/vbd',
    3635        'clipboard',
Note: See TracChangeset for help on using the changeset viewer.