Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 56fd7cf in mainline for uspace/drv/block/ahci/ahci.c


Ignore:
Timestamp:
2012-08-17T11:37:03Z (9 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
1d5a540
Parents:
be2a38ad
Message:

Make ddf_dev_t and ddf_fun_t opaque. This further tighthens the DDF interface.

File:
1 edited

Legend:

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

    rbe2a38ad r56fd7cf  
    3434#include <errno.h>
    3535#include <stdio.h>
    36 #include <devman.h>
    3736#include <ddf/interrupt.h>
    3837#include <ddf/log.h>
     
    160159};
    161160
     161/** Get SATA structure from DDF function. */
     162static sata_dev_t *fun_sata_dev(ddf_fun_t *fun)
     163{
     164        return ddf_fun_data_get(fun);
     165}
     166
     167/** Get AHCI structure from DDF device. */
     168static ahci_dev_t *dev_ahci_dev(ddf_dev_t *dev)
     169{
     170        return ddf_dev_data_get(dev);
     171}
     172
    162173/** Get SATA device name.
    163174 *
     
    172183    size_t sata_dev_name_length, char *sata_dev_name)
    173184{
    174         sata_dev_t *sata = (sata_dev_t *) fun->driver_data;
     185        sata_dev_t *sata = fun_sata_dev(fun);
    175186        str_cpy(sata_dev_name, sata_dev_name_length, sata->model);
    176187        return EOK;
     
    187198static int ahci_get_num_blocks(ddf_fun_t *fun, uint64_t *num_blocks)
    188199{
    189         sata_dev_t *sata = (sata_dev_t *) fun->driver_data;
     200        sata_dev_t *sata = fun_sata_dev(fun);
    190201        *num_blocks = sata->blocks;
    191202        return EOK;
     
    202213static int ahci_get_block_size(ddf_fun_t *fun, size_t *block_size)
    203214{
    204         sata_dev_t *sata = (sata_dev_t *) fun->driver_data;
     215        sata_dev_t *sata = fun_sata_dev(fun);
    205216        *block_size = sata->block_size;
    206217        return EOK;
     
    220231    size_t count, void *buf)
    221232{
    222         sata_dev_t *sata = (sata_dev_t *) fun->driver_data;
     233        sata_dev_t *sata = fun_sata_dev(fun);
    223234       
    224235        void *phys;
     
    263274    size_t count, void *buf)
    264275{
    265         sata_dev_t *sata = (sata_dev_t *) fun->driver_data;
     276        sata_dev_t *sata = fun_sata_dev(fun);
    266277       
    267278        void *phys;
     
    885896static void ahci_interrupt(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *icall)
    886897{
    887         ahci_dev_t *ahci = (ahci_dev_t *) dev->driver_data;
     898        ahci_dev_t *ahci = dev_ahci_dev(dev);
    888899        unsigned int port = IPC_GET_ARG1(*icall);
    889900        ahci_port_is_t pxis = IPC_GET_ARG2(*icall);
     
    919930 *
    920931 */
    921 static sata_dev_t *ahci_sata_allocate(volatile ahci_port_t *port)
     932static sata_dev_t *ahci_sata_allocate(ahci_dev_t *ahci, volatile ahci_port_t *port)
    922933{
    923934        size_t size = 4096;
     
    926937        void *virt_cmd = NULL;
    927938        void *virt_table = NULL;
    928        
    929         sata_dev_t *sata = malloc(sizeof(sata_dev_t));
     939        ddf_fun_t *fun;
     940       
     941        fun = ddf_fun_create(ahci->dev, fun_exposed, NULL);
     942       
     943        sata_dev_t *sata = ddf_fun_data_alloc(fun, sizeof(sata_dev_t));
    930944        if (sata == NULL)
    931945                return NULL;
    932946       
    933         bzero(sata, sizeof(sata_dev_t));
    934        
     947        sata->fun = fun;
    935948        sata->port = port;
    936949       
     
    10291042{
    10301043        ddf_fun_t *fun = NULL;
    1031         sata_dev_t *sata = ahci_sata_allocate(port);
     1044        int rc;
     1045       
     1046        sata_dev_t *sata = ahci_sata_allocate(ahci, port);
    10321047        if (sata == NULL)
    10331048                return EINTR;
     
    10611076        fibril_mutex_unlock(&sata_devices_count_lock);
    10621077       
    1063         fun = ddf_fun_create(dev, fun_exposed, sata_dev_name);
    1064         if (fun == NULL) {
    1065                 ddf_msg(LVL_ERROR, "Failed creating function.");
     1078        rc= ddf_fun_set_name(sata->fun, sata_dev_name);
     1079        if (rc != EOK) {
     1080                ddf_msg(LVL_ERROR, "Failed setting function name.");
    10661081                goto error;
    10671082        }
    10681083       
    1069         fun->ops = &ahci_ops;
    1070         fun->driver_data = sata;
    1071         int rc = ddf_fun_bind(fun);
     1084        ddf_fun_set_ops(fun, &ahci_ops);
     1085       
     1086        rc = ddf_fun_bind(fun);
    10721087        if (rc != EOK) {
    10731088                ddf_msg(LVL_ERROR, "Failed binding function.");
     
    11191134static ahci_dev_t *ahci_ahci_create(ddf_dev_t *dev)
    11201135{
    1121         ahci_dev_t *ahci = malloc(sizeof(ahci_dev_t));
     1136        ahci_dev_t *ahci = ddf_dev_data_alloc(dev, sizeof(ahci_dev_t));
    11221137        if (!ahci)
    11231138                return NULL;
    11241139       
    1125         bzero(ahci, sizeof(ahci_dev_t));
     1140        /* Connect to parent device */
     1141        ahci->parent_sess = ddf_dev_parent_sess_create(dev, EXCHANGE_SERIALIZE);
     1142        if (ahci->parent_sess == NULL)
     1143                return NULL;
    11261144       
    11271145        ahci->dev = dev;
     
    11291147        hw_res_list_parsed_t hw_res_parsed;
    11301148        hw_res_list_parsed_init(&hw_res_parsed);
    1131         if (hw_res_get_list_parsed(dev->parent_sess, &hw_res_parsed, 0) != EOK)
     1149        if (hw_res_get_list_parsed(ahci->parent_sess, &hw_res_parsed, 0) != EOK)
    11321150                goto error_get_res_parsed;
    11331151       
     
    12111229       
    12121230        /* Set master latency timer. */
    1213         pci_config_space_write_8(ahci->dev->parent_sess, AHCI_PCI_MLT, 32);
     1231        pci_config_space_write_8(ahci->parent_sess, AHCI_PCI_MLT, 32);
    12141232       
    12151233        /* Enable PCI interrupt and bus mastering */
    12161234        ahci_pcireg_cmd_t cmd;
    12171235       
    1218         pci_config_space_read_16(ahci->dev->parent_sess, AHCI_PCI_CMD, &cmd.u16);
     1236        pci_config_space_read_16(ahci->parent_sess, AHCI_PCI_CMD, &cmd.u16);
    12191237        cmd.id = 0;
    12201238        cmd.bme = 1;
    1221         pci_config_space_write_16(ahci->dev->parent_sess, AHCI_PCI_CMD, cmd.u16);
     1239        pci_config_space_write_16(ahci->parent_sess, AHCI_PCI_CMD, cmd.u16);
    12221240       
    12231241        /* Enable AHCI and interrupt. */
     
    12371255static int ahci_dev_add(ddf_dev_t *dev)
    12381256{
    1239         /* Connect to parent device */
    1240         dev->parent_sess = devman_parent_device_connect(EXCHANGE_SERIALIZE,
    1241             dev->handle, IPC_FLAG_BLOCKING);
    1242         if (dev->parent_sess == NULL)
    1243                 return EINTR;
    1244        
    12451257        ahci_dev_t *ahci = ahci_ahci_create(dev);
    12461258        if (ahci == NULL)
    12471259                goto error;
    12481260       
    1249         dev->driver_data = ahci;
    1250        
    12511261        /* Start AHCI hardware. */
    12521262        ahci_ahci_hw_start(ahci);
     
    12581268       
    12591269error:
    1260         async_hangup(dev->parent_sess);
    12611270        return EINTR;
    12621271}
Note: See TracChangeset for help on using the changeset viewer.