Changes in uspace/drv/root/root.c [ebcb05a:eff1f033] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/root/root.c
rebcb05a reff1f033 2 2 * Copyright (c) 2010 Lenka Trochtova 3 3 * Copyright (c) 2010 Vojtech Horky 4 * Copyright (c) 2011 Jiri Svoboda5 4 * All rights reserved. 6 5 * … … 45 44 #include <stdlib.h> 46 45 #include <str.h> 47 #include <str_error.h>48 46 #include <ctype.h> 49 47 #include <macros.h> … … 51 49 #include <sysinfo.h> 52 50 53 #include <ddf/driver.h> 54 #include <ddf/log.h> 51 #include <driver.h> 55 52 #include <devman.h> 56 53 #include <ipc/devman.h> … … 58 55 #define NAME "root" 59 56 60 #define PLATFORM_ FUN_NAME "hw"61 #define PLATFORM_ FUN_MATCH_ID_FMT "platform/%s"62 #define PLATFORM_ FUN_MATCH_SCORE 10057 #define PLATFORM_DEVICE_NAME "hw" 58 #define PLATFORM_DEVICE_MATCH_ID_FMT "platform/%s" 59 #define PLATFORM_DEVICE_MATCH_SCORE 100 63 60 64 #define VIRTUAL_ FUN_NAME "virt"65 #define VIRTUAL_ FUN_MATCH_ID "rootvirt"66 #define VIRTUAL_ FUN_MATCH_SCORE 10061 #define VIRTUAL_DEVICE_NAME "virt" 62 #define VIRTUAL_DEVICE_MATCH_ID "rootvirt" 63 #define VIRTUAL_DEVICE_MATCH_SCORE 100 67 64 68 static int root_add_device(d df_dev_t *dev);65 static int root_add_device(device_t *dev); 69 66 70 67 /** The root device driver's standard operations. */ … … 79 76 }; 80 77 81 /** Create the functionwhich represents the root of virtual device tree.78 /** Create the device which represents the root of virtual device tree. 82 79 * 83 * @param dev Device84 * @return EOK on success or negative error code80 * @param parent Parent of the newly created device. 81 * @return Error code. 85 82 */ 86 static int add_virtual_root_ fun(ddf_dev_t *dev)83 static int add_virtual_root_child(device_t *parent) 87 84 { 88 const char *name = VIRTUAL_FUN_NAME;89 ddf_fun_t *fun;90 int rc;85 printf(NAME ": adding new child for virtual devices.\n"); 86 printf(NAME ": device node is `%s' (%d %s)\n", VIRTUAL_DEVICE_NAME, 87 VIRTUAL_DEVICE_MATCH_SCORE, VIRTUAL_DEVICE_MATCH_ID); 91 88 92 ddf_msg(LVL_DEBUG, "Adding new function for virtual devices. " 93 "Function node is `%s' (%d %s)", name, 94 VIRTUAL_FUN_MATCH_SCORE, VIRTUAL_FUN_MATCH_ID); 89 int res = child_device_register_wrapper(parent, VIRTUAL_DEVICE_NAME, 90 VIRTUAL_DEVICE_MATCH_ID, VIRTUAL_DEVICE_MATCH_SCORE); 95 91 96 fun = ddf_fun_create(dev, fun_inner, name); 97 if (fun == NULL) { 98 ddf_msg(LVL_ERROR, "Failed creating function %s", name); 99 return ENOMEM; 100 } 101 102 rc = ddf_fun_add_match_id(fun, VIRTUAL_FUN_MATCH_ID, 103 VIRTUAL_FUN_MATCH_SCORE); 104 if (rc != EOK) { 105 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s", 106 name); 107 ddf_fun_destroy(fun); 108 return rc; 109 } 110 111 rc = ddf_fun_bind(fun); 112 if (rc != EOK) { 113 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name, 114 str_error(rc)); 115 ddf_fun_destroy(fun); 116 return rc; 117 } 118 119 return EOK; 92 return res; 120 93 } 121 94 122 /** Create the functionwhich represents the root of HW device tree.95 /** Create the device which represents the root of HW device tree. 123 96 * 124 * @param dev Device125 * @return EOK on success or negative error code97 * @param parent Parent of the newly created device. 98 * @return 0 on success, negative error number otherwise. 126 99 */ 127 static int add_platform_ fun(ddf_dev_t *dev)100 static int add_platform_child(device_t *parent) 128 101 { 129 102 char *match_id; 130 103 char *platform; 131 104 size_t platform_size; 132 133 const char *name = PLATFORM_FUN_NAME; 134 ddf_fun_t *fun; 135 int rc; 105 int res; 136 106 137 107 /* Get platform name from sysinfo. */ 108 138 109 platform = sysinfo_get_data("platform", &platform_size); 139 110 if (platform == NULL) { 140 ddf_msg(LVL_ERROR, "Failed to obtain platform name.");111 printf(NAME ": Failed to obtain platform name.\n"); 141 112 return ENOENT; 142 113 } … … 145 116 platform = realloc(platform, platform_size + 1); 146 117 if (platform == NULL) { 147 ddf_msg(LVL_ERROR, "Memory allocation failed.");118 printf(NAME ": Memory allocation failed.\n"); 148 119 return ENOMEM; 149 120 } … … 152 123 153 124 /* Construct match ID. */ 154 if (asprintf(&match_id, PLATFORM_FUN_MATCH_ID_FMT, platform) == -1) { 155 ddf_msg(LVL_ERROR, "Memory allocation failed."); 125 126 if (asprintf(&match_id, PLATFORM_DEVICE_MATCH_ID_FMT, platform) == -1) { 127 printf(NAME ": Memory allocation failed.\n"); 156 128 return ENOMEM; 157 129 } 158 130 159 /* Add function. */ 160 ddf_msg(LVL_DEBUG, "Adding platform function. Function node is `%s' " 161 " (%d %s)", PLATFORM_FUN_NAME, PLATFORM_FUN_MATCH_SCORE, 162 match_id); 131 /* Add child. */ 163 132 164 fun = ddf_fun_create(dev, fun_inner, name); 165 if (fun == NULL) { 166 ddf_msg(LVL_ERROR, "Error creating function %s", name); 167 return ENOMEM; 168 } 133 printf(NAME ": adding new child for platform device.\n"); 134 printf(NAME ": device node is `%s' (%d %s)\n", PLATFORM_DEVICE_NAME, 135 PLATFORM_DEVICE_MATCH_SCORE, match_id); 169 136 170 rc = ddf_fun_add_match_id(fun, match_id, PLATFORM_FUN_MATCH_SCORE); 171 if (rc != EOK) { 172 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s", 173 name); 174 ddf_fun_destroy(fun); 175 return rc; 176 } 137 res = child_device_register_wrapper(parent, PLATFORM_DEVICE_NAME, 138 match_id, PLATFORM_DEVICE_MATCH_SCORE); 177 139 178 rc = ddf_fun_bind(fun); 179 if (rc != EOK) { 180 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name, 181 str_error(rc)); 182 ddf_fun_destroy(fun); 183 return rc; 184 } 185 186 return EOK; 140 return res; 187 141 } 188 142 … … 192 146 * of HW and pseudo devices). 193 147 */ 194 static int root_add_device(d df_dev_t *dev)148 static int root_add_device(device_t *dev) 195 149 { 196 ddf_msg(LVL_DEBUG, "root_add_device, device handle=%" PRIun,150 printf(NAME ": root_add_device, device handle=%" PRIun "\n", 197 151 dev->handle); 198 152 199 153 /* 200 154 * Register virtual devices root. … … 202 156 * vital for the system. 203 157 */ 204 add_virtual_root_ fun(dev);158 add_virtual_root_child(dev); 205 159 206 160 /* Register root device's children. */ 207 int res = add_platform_ fun(dev);161 int res = add_platform_child(dev); 208 162 if (EOK != res) 209 ddf_msg(LVL_ERROR, "Failed adding child device for platform.");210 163 printf(NAME ": failed to add child device for platform.\n"); 164 211 165 return res; 212 166 } … … 215 169 { 216 170 printf(NAME ": HelenOS root device driver\n"); 217 218 ddf_log_init(NAME, LVL_ERROR); 219 return ddf_driver_main(&root_driver); 171 return driver_main(&root_driver); 220 172 } 221 173
Note:
See TracChangeset
for help on using the changeset viewer.