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