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

Changeset c5be39b in mainline


Ignore:
Timestamp:
2011-08-29T21:53:18Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
5f6e25e
Parents:
bfe7867
Message:

Add interface for allocating driver-specific device and function data.

Location:
uspace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/test/test1/test1.c

    rbfe7867 rc5be39b  
    148148            dev->name, (int) dev->handle);
    149149
    150         test1 = calloc(1, sizeof(test1_t));
     150        test1 = ddf_dev_data_alloc(dev, sizeof(test1_t));
    151151        if (test1 == NULL) {
    152                 ddf_msg(LVL_ERROR, "Failed allocating softstate.\n");
     152                ddf_msg(LVL_ERROR, "Failed allocating soft state.\n");
    153153                return ENOMEM;
    154154        }
     
    159159                return ENOMEM;
    160160        }
     161
     162        test1->fun_a = fun_a;
    161163
    162164        rc = ddf_fun_bind(fun_a);
     
    187189        ddf_msg(LVL_DEBUG, "Device `%s' accepted.", dev->name);
    188190
    189         test1->fun_a = fun_a;
    190         dev->driver_data = test1;
    191191        return EOK;
    192192}
  • uspace/lib/drv/generic/driver.c

    rbfe7867 rc5be39b  
    699699}
    700700
     701/** Allocate driver-specific device data. */
     702extern void *ddf_dev_data_alloc(ddf_dev_t *dev, size_t size)
     703{
     704        void *data;
     705
     706        assert(dev->driver_data == NULL);
     707
     708        data = calloc(1, size);
     709        if (data == NULL)
     710                return NULL;
     711
     712        dev->driver_data = data;
     713        return data;
     714}
     715
    701716/** Create a DDF function node.
    702717 *
     
    744759
    745760        return fun;
     761}
     762
     763/** Allocate driver-specific function data. */
     764extern void *ddf_fun_data_alloc(ddf_fun_t *fun, size_t size)
     765{
     766        void *data;
     767
     768        assert(fun->bound == false);
     769        assert(fun->driver_data == NULL);
     770
     771        data = calloc(1, size);
     772        if (data == NULL)
     773                return NULL;
     774
     775        fun->driver_data = data;
     776        return data;
    746777}
    747778
  • uspace/lib/drv/include/ddf/driver.h

    rbfe7867 rc5be39b  
    155155extern int ddf_driver_main(driver_t *);
    156156
     157extern void *ddf_dev_data_alloc(ddf_dev_t *, size_t);
    157158extern ddf_fun_t *ddf_fun_create(ddf_dev_t *, fun_type_t, const char *);
    158159extern void ddf_fun_destroy(ddf_fun_t *);
     160extern void *ddf_fun_data_alloc(ddf_fun_t *, size_t);
    159161extern int ddf_fun_bind(ddf_fun_t *);
    160162extern int ddf_fun_unbind(ddf_fun_t *);
Note: See TracChangeset for help on using the changeset viewer.