Changeset eb522e8 in mainline for uspace/drv/root/root.c
- Timestamp:
- 2011-06-01T08:43:42Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8d6c1f1
- Parents:
- 9e2e715 (diff), e51a514 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/root/root.c
r9e2e715 reb522e8 1 1 /* 2 2 * Copyright (c) 2010 Lenka Trochtova 3 * Copyright (c) 2010 Vojtech Horky 4 * Copyright (c) 2011 Jiri Svoboda 3 5 * All rights reserved. 4 6 * … … 43 45 #include <stdlib.h> 44 46 #include <str.h> 47 #include <str_error.h> 45 48 #include <ctype.h> 46 49 #include <macros.h> 47 48 #include <driver.h> 50 #include <inttypes.h> 51 #include <sysinfo.h> 52 53 #include <ddf/driver.h> 54 #include <ddf/log.h> 49 55 #include <devman.h> 50 56 #include <ipc/devman.h> … … 52 58 #define NAME "root" 53 59 54 static int root_add_device(device_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); 55 69 56 70 /** The root device driver's standard operations. */ … … 65 79 }; 66 80 67 /** Create the device which represents the root of HW device tree. 68 * 69 * @param parent Parent of the newly created device. 70 * @return 0 on success, negative error number otherwise. 71 */ 72 static int add_platform_child(device_t *parent) 73 { 74 printf(NAME ": adding new child for platform device.\n"); 75 76 int res = EOK; 77 device_t *platform = NULL; 78 match_id_t *match_id = NULL; 79 80 /* Create new device. */ 81 platform = create_device(); 82 if (NULL == platform) { 83 res = ENOMEM; 84 goto failure; 85 } 86 87 platform->name = "hw"; 88 printf(NAME ": the new device's name is %s.\n", platform->name); 89 90 /* Initialize match id list. */ 91 match_id = create_match_id(); 92 if (NULL == match_id) { 93 res = ENOMEM; 94 goto failure; 95 } 96 97 /* TODO - replace this with some better solution (sysinfo ?) */ 98 match_id->id = STRING(UARCH); 99 match_id->score = 100; 100 add_match_id(&platform->match_ids, match_id); 101 102 /* Register child device. */ 103 res = child_device_register(platform, parent); 104 if (EOK != res) 105 goto failure; 106 107 return res; 108 109 failure: 110 if (NULL != match_id) 111 match_id->id = NULL; 112 113 if (NULL != platform) { 114 platform->name = NULL; 115 delete_device(platform); 116 } 117 118 return res; 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) 128 { 129 char *match_id; 130 char *platform; 131 size_t platform_size; 132 133 const char *name = PLATFORM_FUN_NAME; 134 ddf_fun_t *fun; 135 int rc; 136 137 /* Get platform name from sysinfo. */ 138 platform = sysinfo_get_data("platform", &platform_size); 139 if (platform == NULL) { 140 ddf_msg(LVL_ERROR, "Failed to obtain platform name."); 141 return ENOENT; 142 } 143 144 /* Null-terminate string. */ 145 platform = realloc(platform, platform_size + 1); 146 if (platform == NULL) { 147 ddf_msg(LVL_ERROR, "Memory allocation failed."); 148 return ENOMEM; 149 } 150 151 platform[platform_size] = '\0'; 152 153 /* Construct match ID. */ 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; 119 187 } 120 188 … … 124 192 * of HW and pseudo devices). 125 193 */ 126 static int root_add_device(device_t *dev) 127 { 128 printf(NAME ": root_add_device, device handle = %d\n", dev->handle); 129 194 static int root_add_device(ddf_dev_t *dev) 195 { 196 ddf_msg(LVL_DEBUG, "root_add_device, device handle=%" PRIun, 197 dev->handle); 198 199 /* 200 * Register virtual devices root. 201 * We ignore error occurrence because virtual devices shall not be 202 * vital for the system. 203 */ 204 add_virtual_root_fun(dev); 205 130 206 /* Register root device's children. */ 131 int res = add_platform_ child(dev);207 int res = add_platform_fun(dev); 132 208 if (EOK != res) 133 printf(NAME ": failed to add child device for platform.\n");134 209 ddf_msg(LVL_ERROR, "Failed adding child device for platform."); 210 135 211 return res; 136 212 } … … 139 215 { 140 216 printf(NAME ": HelenOS root device driver\n"); 141 return driver_main(&root_driver); 217 218 ddf_log_init(NAME, LVL_ERROR); 219 return ddf_driver_main(&root_driver); 142 220 } 143 221
Note:
See TracChangeset
for help on using the changeset viewer.