00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00037 #include <assert.h>
00038 #include <stdio.h>
00039 #include <errno.h>
00040 #include <str_error.h>
00041 #include <ddf/driver.h>
00042 #include <ddf/log.h>
00043
00044 #define NAME "rootvirt"
00045
00047 typedef struct {
00049 const char *name;
00051 const char *match_id;
00052 } virtual_function_t;
00053
00055 virtual_function_t virtual_functions[] = {
00056 #include "devices.def"
00057
00058 {
00059 .name = NULL,
00060 .match_id = NULL
00061 }
00062 };
00063
00064 static int rootvirt_add_device(ddf_dev_t *dev);
00065
00066 static driver_ops_t rootvirt_ops = {
00067 .add_device = &rootvirt_add_device
00068 };
00069
00070 static driver_t rootvirt_driver = {
00071 .name = NAME,
00072 .driver_ops = &rootvirt_ops
00073 };
00074
00081 static int rootvirt_add_fun(ddf_dev_t *vdev, virtual_function_t *vfun)
00082 {
00083 ddf_fun_t *fun;
00084 int rc;
00085
00086 ddf_msg(LVL_DEBUG, "Registering function `%s' (match \"%s\")",
00087 vfun->name, vfun->match_id);
00088
00089 fun = ddf_fun_create(vdev, fun_inner, vfun->name);
00090 if (fun == NULL) {
00091 ddf_msg(LVL_ERROR, "Failed creating function %s", vfun->name);
00092 return ENOMEM;
00093 }
00094
00095 rc = ddf_fun_add_match_id(fun, vfun->match_id, 10);
00096 if (rc != EOK) {
00097 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
00098 vfun->name);
00099 ddf_fun_destroy(fun);
00100 return rc;
00101 }
00102
00103 rc = ddf_fun_bind(fun);
00104 if (rc != EOK) {
00105 ddf_msg(LVL_ERROR, "Failed binding function %s: %s",
00106 vfun->name, str_error(rc));
00107 ddf_fun_destroy(fun);
00108 return rc;
00109 }
00110
00111 ddf_msg(LVL_NOTE, "Registered child device `%s'", vfun->name);
00112 return EOK;
00113 }
00114
00115 static int rootvirt_add_device(ddf_dev_t *dev)
00116 {
00117 static int instances = 0;
00118
00119
00120
00121
00122 instances++;
00123 if (instances > 1) {
00124 return ELIMIT;
00125 }
00126
00127 ddf_msg(LVL_DEBUG, "add_device(handle=%d)", (int)dev->handle);
00128
00129
00130
00131
00132
00133 virtual_function_t *vfun = virtual_functions;
00134 while (vfun->name != NULL) {
00135 (void) rootvirt_add_fun(dev, vfun);
00136 vfun++;
00137 }
00138
00139 return EOK;
00140 }
00141
00142 int main(int argc, char *argv[])
00143 {
00144 printf(NAME ": HelenOS virtual devices root driver\n");
00145
00146 ddf_log_init(NAME, LVL_ERROR);
00147 return ddf_driver_main(&rootvirt_driver);
00148 }
00149