Changeset 0c968a17 in mainline for uspace/drv/root/root.c
- Timestamp:
- 2011-02-15T22:58:28Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8b1ea2d4
- Parents:
- 6a343bdf (diff), aa7dc64 (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
r6a343bdf r0c968a17 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 <d river.h>53 #include <ddf/driver.h> 52 54 #include <devman.h> 53 55 #include <ipc/devman.h> … … 55 57 #define NAME "root" 56 58 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);59 #define PLATFORM_FUN_NAME "hw" 60 #define PLATFORM_FUN_MATCH_ID_FMT "platform/%s" 61 #define PLATFORM_FUN_MATCH_SCORE 100 62 63 #define VIRTUAL_FUN_NAME "virt" 64 #define VIRTUAL_FUN_MATCH_ID "rootvirt" 65 #define VIRTUAL_FUN_MATCH_SCORE 100 66 67 static int root_add_device(ddf_dev_t *dev); 66 68 67 69 /** The root device driver's standard operations. */ … … 76 78 }; 77 79 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) 80 /** Create the function which represents the root of virtual device tree. 81 * 82 * @param dev Device 83 * @return EOK on success or negative error code 84 */ 85 static int add_virtual_root_fun(ddf_dev_t *dev) 86 { 87 const char *name = VIRTUAL_FUN_NAME; 88 ddf_fun_t *fun; 89 int rc; 90 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); 94 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; 118 } 119 120 /** Create the function which represents the root of HW device tree. 121 * 122 * @param dev Device 123 * @return EOK on success or negative error code 124 */ 125 static int add_platform_fun(ddf_dev_t *dev) 101 126 { 102 127 char *match_id; 103 128 char *platform; 104 129 size_t platform_size; 105 int res; 130 131 const char *name = PLATFORM_FUN_NAME; 132 ddf_fun_t *fun; 133 int rc; 106 134 107 135 /* Get platform name from sysinfo. */ 108 109 136 platform = sysinfo_get_data("platform", &platform_size); 110 137 if (platform == NULL) { … … 123 150 124 151 /* Construct match ID. */ 125 126 if (asprintf(&match_id, PLATFORM_DEVICE_MATCH_ID_FMT, platform) == -1) { 152 if (asprintf(&match_id, PLATFORM_FUN_MATCH_ID_FMT, platform) == -1) { 127 153 printf(NAME ": Memory allocation failed.\n"); 128 154 return ENOMEM; 129 155 } 130 156 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; 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); 161 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 } 167 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 } 174 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; 141 184 } 142 185 … … 146 189 * of HW and pseudo devices). 147 190 */ 148 static int root_add_device(d evice_t *dev)191 static int root_add_device(ddf_dev_t *dev) 149 192 { 150 193 printf(NAME ": root_add_device, device handle=%" PRIun "\n", 151 194 dev->handle); 152 195 153 196 /* 154 197 * Register virtual devices root. … … 156 199 * vital for the system. 157 200 */ 158 add_virtual_root_ child(dev);201 add_virtual_root_fun(dev); 159 202 160 203 /* Register root device's children. */ 161 int res = add_platform_ child(dev);204 int res = add_platform_fun(dev); 162 205 if (EOK != res) 163 206 printf(NAME ": failed to add child device for platform.\n"); 164 207 165 208 return res; 166 209 } … … 169 212 { 170 213 printf(NAME ": HelenOS root device driver\n"); 171 return d river_main(&root_driver);214 return ddf_driver_main(&root_driver); 172 215 } 173 216
Note:
See TracChangeset
for help on using the changeset viewer.