Changeset 53738d3 in mainline


Ignore:
Timestamp:
2011-09-17T22:23:11Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7a69340
Parents:
2fc487f
Message:

sb16: Get hw resources.

Location:
uspace/drv/audio/sb16
Files:
3 added
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/audio/sb16/main.c

    r2fc487f r53738d3  
    3636#include <ddf/interrupt.h>
    3737#include <ddf/log.h>
     38#include <device/hw_res.h>
     39#include <devman.h>
     40#include <assert.h>
    3841#include <stdio.h>
    3942#include <errno.h>
    4043
    41 //#include <device/hw_res.h>
    4244//#include <str_error.h>
    4345
    44 
    45 //#include "pci.h"
     46#include "ddf_log.h"
     47#include "sb16.h"
    4648
    4749#define NAME "sb16"
    4850
    4951static int sb_add_device(ddf_dev_t *device);
     52static int sb_get_res(const ddf_dev_t *device, uintptr_t *sb_regs,
     53    size_t *sb_regs_size, uintptr_t *mpu_regs, size_t *mpu_regs_size, int *irq);
    5054/*----------------------------------------------------------------------------*/
    5155static driver_ops_t sb_driver_ops = {
     
    5862};
    5963//static ddf_dev_ops_t sb_ops = {};
    60 /*----------------------------------------------------------------------------*/
    61 /** Initializes a new ddf driver instance of SB16.
    62  *
    63  * @param[in] device DDF instance of the device to initialize.
    64  * @return Error code.
    65  */
    66 static int sb_add_device(ddf_dev_t *device)
    67 {
    68         assert(device);
    69         return ENOTSUP;
    70 }
    7164/*----------------------------------------------------------------------------*/
    7265/** Initializes global driver structures (NONE).
     
    8477        return ddf_driver_main(&sb_driver);
    8578}
     79/*----------------------------------------------------------------------------*/
     80/** Initializes a new ddf driver instance of SB16.
     81 *
     82 * @param[in] device DDF instance of the device to initialize.
     83 * @return Error code.
     84 */
     85static int sb_add_device(ddf_dev_t *device)
     86{
     87        assert(device);
     88        uintptr_t sb_regs = 0, mpu_regs = 0;
     89        size_t sb_regs_size = 0, mpu_regs_size = 0;
     90        int irq = 0;
     91        int ret = sb_get_res(device, &sb_regs, &sb_regs_size, &mpu_regs,
     92            &mpu_regs_size, &irq);
     93
     94        return ret;
     95}
     96/*----------------------------------------------------------------------------*/
     97static int sb_get_res(const ddf_dev_t *device, uintptr_t *sb_regs,
     98    size_t *sb_regs_size, uintptr_t *mpu_regs, size_t *mpu_regs_size, int *irq)
     99{
     100        assert(device);
     101        assert(sb_regs);
     102        assert(sb_regs_size);
     103        assert(mpu_regs);
     104        assert(mpu_regs_size);
     105        assert(irq);
     106
     107        async_sess_t *parent_sess =
     108            devman_parent_device_connect(EXCHANGE_SERIALIZE, device->handle,
     109            IPC_FLAG_BLOCKING);
     110        if (!parent_sess)
     111                return ENOMEM;
     112
     113        hw_resource_list_t hw_resources;
     114        const int rc = hw_res_get_resource_list(parent_sess, &hw_resources);
     115        if (rc != EOK) {
     116                async_hangup(parent_sess);
     117                return rc;
     118        }
     119
     120        size_t i;
     121        for (i = 0; i < hw_resources.count; i++) {
     122                const hw_resource_t *res = &hw_resources.resources[i];
     123                switch (res->type) {
     124                case INTERRUPT:
     125                        *irq = res->res.interrupt.irq;
     126                        ddf_log_debug("Found interrupt: %d.\n", *irq);
     127                        break;
     128                case IO_RANGE:
     129                        ddf_log_debug("Found io: %" PRIx64" %zu.\n",
     130                            res->res.io_range.address, res->res.io_range.size);
     131                        if (res->res.io_range.size >= sizeof(sb16_regs_t)) {
     132                                *sb_regs = res->res.io_range.address;
     133                                *sb_regs_size = res->res.io_range.size;
     134                        } else {
     135                                *mpu_regs = res->res.io_range.address;
     136                                *mpu_regs_size = res->res.io_range.size;
     137                        }
     138                        break;
     139                default:
     140                        break;
     141                }
     142        }
     143
     144        async_hangup(parent_sess);
     145        free(hw_resources.resources);
     146        return EOK;
     147}
    86148/**
    87149 * @}
Note: See TracChangeset for help on using the changeset viewer.