Changes in uspace/drv/root/root.c [af6b5157:eff1f033] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/root/root.c
raf6b5157 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 <d df/driver.h>51 #include <driver.h> 54 52 #include <devman.h> 55 53 #include <ipc/devman.h> … … 57 55 #define NAME "root" 58 56 59 #define PLATFORM_ FUN_NAME "hw"60 #define PLATFORM_ FUN_MATCH_ID_FMT "platform/%s"61 #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 62 60 63 #define VIRTUAL_ FUN_NAME "virt"64 #define VIRTUAL_ FUN_MATCH_ID "rootvirt"65 #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 66 64 67 static int root_add_device(d df_dev_t *dev);65 static int root_add_device(device_t *dev); 68 66 69 67 /** The root device driver's standard operations. */ … … 78 76 }; 79 77 80 /** Create the functionwhich represents the root of virtual device tree.78 /** Create the device which represents the root of virtual device tree. 81 79 * 82 * @param dev Device83 * @return EOK on success or negative error code80 * @param parent Parent of the newly created device. 81 * @return Error code. 84 82 */ 85 static int add_virtual_root_ fun(ddf_dev_t *dev)83 static int add_virtual_root_child(device_t *parent) 86 84 { 87 const char *name = VIRTUAL_FUN_NAME;88 ddf_fun_t *fun;89 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); 90 88 91 printf(NAME ": adding new function for virtual devices.\n"); 92 printf(NAME ": function node is `%s' (%d %s)\n", name, 93 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); 94 91 95 fun = ddf_fun_create(dev, fun_inner, name); 96 if (fun == NULL) { 97 printf(NAME ": error creating function %s\n", name); 98 return ENOMEM; 99 } 100 101 rc = ddf_fun_add_match_id(fun, VIRTUAL_FUN_MATCH_ID, 102 VIRTUAL_FUN_MATCH_SCORE); 103 if (rc != EOK) { 104 printf(NAME ": error adding match IDs to function %s\n", name); 105 ddf_fun_destroy(fun); 106 return rc; 107 } 108 109 rc = ddf_fun_bind(fun); 110 if (rc != EOK) { 111 printf(NAME ": error binding function %s: %s\n", name, 112 str_error(rc)); 113 ddf_fun_destroy(fun); 114 return rc; 115 } 116 117 return EOK; 92 return res; 118 93 } 119 94 120 /** Create the functionwhich represents the root of HW device tree.95 /** Create the device which represents the root of HW device tree. 121 96 * 122 * @param dev Device123 * @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. 124 99 */ 125 static int add_platform_ fun(ddf_dev_t *dev)100 static int add_platform_child(device_t *parent) 126 101 { 127 102 char *match_id; 128 103 char *platform; 129 104 size_t platform_size; 130 131 const char *name = PLATFORM_FUN_NAME; 132 ddf_fun_t *fun; 133 int rc; 105 int res; 134 106 135 107 /* Get platform name from sysinfo. */ 108 136 109 platform = sysinfo_get_data("platform", &platform_size); 137 110 if (platform == NULL) { … … 150 123 151 124 /* Construct match ID. */ 152 if (asprintf(&match_id, PLATFORM_FUN_MATCH_ID_FMT, platform) == -1) { 125 126 if (asprintf(&match_id, PLATFORM_DEVICE_MATCH_ID_FMT, platform) == -1) { 153 127 printf(NAME ": Memory allocation failed.\n"); 154 128 return ENOMEM; 155 129 } 156 130 157 /* Add function. */ 158 printf(NAME ": adding platform function\n"); 159 printf(NAME ": function node is `%s' (%d %s)\n", PLATFORM_FUN_NAME, 160 PLATFORM_FUN_MATCH_SCORE, match_id); 131 /* Add child. */ 161 132 162 fun = ddf_fun_create(dev, fun_inner, name); 163 if (fun == NULL) { 164 printf(NAME ": error creating function %s\n", name); 165 return ENOMEM; 166 } 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); 167 136 168 rc = ddf_fun_add_match_id(fun, match_id, PLATFORM_FUN_MATCH_SCORE); 169 if (rc != EOK) { 170 printf(NAME ": error adding match IDs to function %s\n", name); 171 ddf_fun_destroy(fun); 172 return rc; 173 } 137 res = child_device_register_wrapper(parent, PLATFORM_DEVICE_NAME, 138 match_id, PLATFORM_DEVICE_MATCH_SCORE); 174 139 175 rc = ddf_fun_bind(fun); 176 if (rc != EOK) { 177 printf(NAME ": error binding function %s: %s\n", name, 178 str_error(rc)); 179 ddf_fun_destroy(fun); 180 return rc; 181 } 182 183 return EOK; 140 return res; 184 141 } 185 142 … … 189 146 * of HW and pseudo devices). 190 147 */ 191 static int root_add_device(d df_dev_t *dev)148 static int root_add_device(device_t *dev) 192 149 { 193 150 printf(NAME ": root_add_device, device handle=%" PRIun "\n", 194 151 dev->handle); 195 152 196 153 /* 197 154 * Register virtual devices root. … … 199 156 * vital for the system. 200 157 */ 201 add_virtual_root_ fun(dev);158 add_virtual_root_child(dev); 202 159 203 160 /* Register root device's children. */ 204 int res = add_platform_ fun(dev);161 int res = add_platform_child(dev); 205 162 if (EOK != res) 206 163 printf(NAME ": failed to add child device for platform.\n"); 207 164 208 165 return res; 209 166 } … … 212 169 { 213 170 printf(NAME ": HelenOS root device driver\n"); 214 return d df_driver_main(&root_driver);171 return driver_main(&root_driver); 215 172 } 216 173
Note:
See TracChangeset
for help on using the changeset viewer.