Ignore:
File:
1 edited

Legend:

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

    r56fd7cf r76c07e4  
    3434#include <errno.h>
    3535#include <stdio.h>
     36#include <devman.h>
    3637#include <ddf/interrupt.h>
    3738#include <ddf/log.h>
     
    159160};
    160161
    161 /** Get SATA structure from DDF function. */
    162 static 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. */
    168 static ahci_dev_t *dev_ahci_dev(ddf_dev_t *dev)
    169 {
    170         return ddf_dev_data_get(dev);
    171 }
    172 
    173162/** Get SATA device name.
    174163 *
     
    183172    size_t sata_dev_name_length, char *sata_dev_name)
    184173{
    185         sata_dev_t *sata = fun_sata_dev(fun);
     174        sata_dev_t *sata = (sata_dev_t *) fun->driver_data;
    186175        str_cpy(sata_dev_name, sata_dev_name_length, sata->model);
    187176        return EOK;
     
    198187static int ahci_get_num_blocks(ddf_fun_t *fun, uint64_t *num_blocks)
    199188{
    200         sata_dev_t *sata = fun_sata_dev(fun);
     189        sata_dev_t *sata = (sata_dev_t *) fun->driver_data;
    201190        *num_blocks = sata->blocks;
    202191        return EOK;
     
    213202static int ahci_get_block_size(ddf_fun_t *fun, size_t *block_size)
    214203{
    215         sata_dev_t *sata = fun_sata_dev(fun);
     204        sata_dev_t *sata = (sata_dev_t *) fun->driver_data;
    216205        *block_size = sata->block_size;
    217206        return EOK;
     
    231220    size_t count, void *buf)
    232221{
    233         sata_dev_t *sata = fun_sata_dev(fun);
     222        sata_dev_t *sata = (sata_dev_t *) fun->driver_data;
    234223       
    235224        void *phys;
     
    274263    size_t count, void *buf)
    275264{
    276         sata_dev_t *sata = fun_sata_dev(fun);
     265        sata_dev_t *sata = (sata_dev_t *) fun->driver_data;
    277266       
    278267        void *phys;
     
    896885static void ahci_interrupt(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *icall)
    897886{
    898         ahci_dev_t *ahci = dev_ahci_dev(dev);
     887        ahci_dev_t *ahci = (ahci_dev_t *) dev->driver_data;
    899888        unsigned int port = IPC_GET_ARG1(*icall);
    900889        ahci_port_is_t pxis = IPC_GET_ARG2(*icall);
     
    930919 *
    931920 */
    932 static sata_dev_t *ahci_sata_allocate(ahci_dev_t *ahci, volatile ahci_port_t *port)
     921static sata_dev_t *ahci_sata_allocate(volatile ahci_port_t *port)
    933922{
    934923        size_t size = 4096;
     
    937926        void *virt_cmd = NULL;
    938927        void *virt_table = NULL;
    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));
     928       
     929        sata_dev_t *sata = malloc(sizeof(sata_dev_t));
    944930        if (sata == NULL)
    945931                return NULL;
    946932       
    947         sata->fun = fun;
     933        bzero(sata, sizeof(sata_dev_t));
     934       
    948935        sata->port = port;
    949936       
     
    10421029{
    10431030        ddf_fun_t *fun = NULL;
    1044         int rc;
    1045        
    1046         sata_dev_t *sata = ahci_sata_allocate(ahci, port);
     1031        sata_dev_t *sata = ahci_sata_allocate(port);
    10471032        if (sata == NULL)
    10481033                return EINTR;
     
    10761061        fibril_mutex_unlock(&sata_devices_count_lock);
    10771062       
    1078         rc= ddf_fun_set_name(sata->fun, sata_dev_name);
    1079         if (rc != EOK) {
    1080                 ddf_msg(LVL_ERROR, "Failed setting function name.");
     1063        fun = ddf_fun_create(dev, fun_exposed, sata_dev_name);
     1064        if (fun == NULL) {
     1065                ddf_msg(LVL_ERROR, "Failed creating function.");
    10811066                goto error;
    10821067        }
    10831068       
    1084         ddf_fun_set_ops(fun, &ahci_ops);
    1085        
    1086         rc = ddf_fun_bind(fun);
     1069        fun->ops = &ahci_ops;
     1070        fun->driver_data = sata;
     1071        int rc = ddf_fun_bind(fun);
    10871072        if (rc != EOK) {
    10881073                ddf_msg(LVL_ERROR, "Failed binding function.");
     
    11341119static ahci_dev_t *ahci_ahci_create(ddf_dev_t *dev)
    11351120{
    1136         ahci_dev_t *ahci = ddf_dev_data_alloc(dev, sizeof(ahci_dev_t));
     1121        ahci_dev_t *ahci = malloc(sizeof(ahci_dev_t));
    11371122        if (!ahci)
    11381123                return NULL;
    11391124       
    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;
     1125        bzero(ahci, sizeof(ahci_dev_t));
    11441126       
    11451127        ahci->dev = dev;
     
    11471129        hw_res_list_parsed_t hw_res_parsed;
    11481130        hw_res_list_parsed_init(&hw_res_parsed);
    1149         if (hw_res_get_list_parsed(ahci->parent_sess, &hw_res_parsed, 0) != EOK)
     1131        if (hw_res_get_list_parsed(dev->parent_sess, &hw_res_parsed, 0) != EOK)
    11501132                goto error_get_res_parsed;
    11511133       
     
    12291211       
    12301212        /* Set master latency timer. */
    1231         pci_config_space_write_8(ahci->parent_sess, AHCI_PCI_MLT, 32);
     1213        pci_config_space_write_8(ahci->dev->parent_sess, AHCI_PCI_MLT, 32);
    12321214       
    12331215        /* Enable PCI interrupt and bus mastering */
    12341216        ahci_pcireg_cmd_t cmd;
    12351217       
    1236         pci_config_space_read_16(ahci->parent_sess, AHCI_PCI_CMD, &cmd.u16);
     1218        pci_config_space_read_16(ahci->dev->parent_sess, AHCI_PCI_CMD, &cmd.u16);
    12371219        cmd.id = 0;
    12381220        cmd.bme = 1;
    1239         pci_config_space_write_16(ahci->parent_sess, AHCI_PCI_CMD, cmd.u16);
     1221        pci_config_space_write_16(ahci->dev->parent_sess, AHCI_PCI_CMD, cmd.u16);
    12401222       
    12411223        /* Enable AHCI and interrupt. */
     
    12551237static int ahci_dev_add(ddf_dev_t *dev)
    12561238{
     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       
    12571245        ahci_dev_t *ahci = ahci_ahci_create(dev);
    12581246        if (ahci == NULL)
    12591247                goto error;
    12601248       
     1249        dev->driver_data = ahci;
     1250       
    12611251        /* Start AHCI hardware. */
    12621252        ahci_ahci_hw_start(ahci);
     
    12681258       
    12691259error:
     1260        async_hangup(dev->parent_sess);
    12701261        return EINTR;
    12711262}
Note: See TracChangeset for help on using the changeset viewer.