Changeset a60e90b in mainline
- Timestamp:
- 2013-09-10T20:15:58Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 08bc23d
- Parents:
- 59dc181
- Location:
- uspace/srv/devman
- Files:
-
- 3 added
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/Makefile
r59dc181 ra60e90b 35 35 dev.c \ 36 36 devtree.c \ 37 devman.c \38 37 driver.c \ 38 loc.c \ 39 39 fun.c \ 40 40 main.c \ -
uspace/srv/devman/devman.h
r59dc181 ra60e90b 48 48 #define NAME "devman" 49 49 50 #define MATCH_EXT ".ma"51 52 50 #define LOC_DEVICE_NAMESPACE "devices" 53 51 #define LOC_SEPARATOR '\\' … … 235 233 } dev_tree_t; 236 234 237 /* Match ids and scores */238 239 extern int get_match_score(driver_t *, dev_node_t *);240 241 extern bool parse_match_ids(char *, match_id_list_t *);242 extern bool read_match_ids(const char *, match_id_list_t *);243 extern char *read_match_id(char **);244 extern char *read_id(const char **);245 246 /* Loc services */247 248 extern void loc_register_tree_function(fun_node_t *, dev_tree_t *);249 250 extern fun_node_t *find_loc_tree_function(dev_tree_t *, service_id_t);251 252 extern void tree_add_loc_function(dev_tree_t *, fun_node_t *);253 254 235 #endif 255 236 -
uspace/srv/devman/driver.c
r59dc181 ra60e90b 44 44 #include "devman.h" 45 45 #include "driver.h" 46 #include "match.h" 46 47 47 48 /** … … 511 512 } 512 513 514 /** Pass a device to running driver. 515 * 516 * @param drv The driver's structure. 517 * @param node The device's node in the device tree. 518 */ 519 void add_device(driver_t *drv, dev_node_t *dev, dev_tree_t *tree) 520 { 521 /* 522 * We do not expect to have driver's mutex locked as we do not 523 * access any structures that would affect driver_t. 524 */ 525 log_msg(LOG_DEFAULT, LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")", 526 drv->name, dev->pfun->name); 527 528 /* Send the device to the driver. */ 529 devman_handle_t parent_handle; 530 if (dev->pfun) { 531 parent_handle = dev->pfun->handle; 532 } else { 533 parent_handle = 0; 534 } 535 536 async_exch_t *exch = async_exchange_begin(drv->sess); 537 538 ipc_call_t answer; 539 aid_t req = async_send_2(exch, DRIVER_DEV_ADD, dev->handle, 540 parent_handle, &answer); 541 542 /* Send the device name to the driver. */ 543 sysarg_t rc = async_data_write_start(exch, dev->pfun->name, 544 str_size(dev->pfun->name) + 1); 545 546 async_exchange_end(exch); 547 548 if (rc != EOK) { 549 /* TODO handle error */ 550 } 551 552 /* Wait for answer from the driver. */ 553 async_wait_for(req, &rc); 554 555 switch(rc) { 556 case EOK: 557 dev->state = DEVICE_USABLE; 558 break; 559 case ENOENT: 560 dev->state = DEVICE_NOT_PRESENT; 561 break; 562 default: 563 dev->state = DEVICE_INVALID; 564 break; 565 } 566 567 dev->passed_to_driver = true; 568 569 return; 570 } 571 513 572 int driver_dev_remove(dev_tree_t *tree, dev_node_t *dev) 514 573 { -
uspace/srv/devman/driver.h
r59dc181 ra60e90b 49 49 extern void attach_driver(dev_tree_t *, dev_node_t *, driver_t *); 50 50 extern void detach_driver(dev_tree_t *, dev_node_t *); 51 extern bool start_driver(driver_t *); 51 52 extern void add_device(driver_t *, dev_node_t *, dev_tree_t *); 52 extern bool start_driver(driver_t *);53 53 extern int driver_dev_remove(dev_tree_t *, dev_node_t *); 54 54 extern int driver_dev_gone(dev_tree_t *, dev_node_t *); -
uspace/srv/devman/main.c
r59dc181 ra60e90b 63 63 #include "driver.h" 64 64 #include "fun.h" 65 #include "loc.h" 65 66 66 67 #define DRIVER_DEFAULT_STORE "/drv" -
uspace/srv/devman/match.c
r59dc181 ra60e90b 31 31 */ 32 32 33 #include <fcntl.h> 34 #include <io/log.h> 33 35 #include <str.h> 36 #include <str_error.h> 37 #include <sys/types.h> 38 #include <sys/stat.h> 34 39 35 40 #include "devman.h" 41 #include "match.h" 36 42 37 43 /** Compute compound score of driver and device. … … 93 99 } 94 100 101 /** Read match id at the specified position of a string and set the position in 102 * the string to the first character following the id. 103 * 104 * @param buf The position in the input string. 105 * @return The match id. 106 */ 107 char *read_match_id(char **buf) 108 { 109 char *res = NULL; 110 size_t len = get_nonspace_len(*buf); 111 112 if (len > 0) { 113 res = malloc(len + 1); 114 if (res != NULL) { 115 str_ncpy(res, len + 1, *buf, len); 116 *buf += len; 117 } 118 } 119 120 return res; 121 } 122 123 /** 124 * Read match ids and associated match scores from a string. 125 * 126 * Each match score in the string is followed by its match id. 127 * The match ids and match scores are separated by whitespaces. 128 * Neither match ids nor match scores can contain whitespaces. 129 * 130 * @param buf The string from which the match ids are read. 131 * @param ids The list of match ids into which the match ids and 132 * scores are added. 133 * @return True if at least one match id and associated match score 134 * was successfully read, false otherwise. 135 */ 136 bool parse_match_ids(char *buf, match_id_list_t *ids) 137 { 138 int score = 0; 139 char *id = NULL; 140 int ids_read = 0; 141 142 while (true) { 143 /* skip spaces */ 144 if (!skip_spaces(&buf)) 145 break; 146 147 /* read score */ 148 score = strtoul(buf, &buf, 10); 149 150 /* skip spaces */ 151 if (!skip_spaces(&buf)) 152 break; 153 154 /* read id */ 155 id = read_match_id(&buf); 156 if (NULL == id) 157 break; 158 159 /* create new match_id structure */ 160 match_id_t *mid = create_match_id(); 161 mid->id = id; 162 mid->score = score; 163 164 /* add it to the list */ 165 add_match_id(ids, mid); 166 167 ids_read++; 168 } 169 170 return ids_read > 0; 171 } 172 173 /** 174 * Read match ids and associated match scores from a file. 175 * 176 * Each match score in the file is followed by its match id. 177 * The match ids and match scores are separated by whitespaces. 178 * Neither match ids nor match scores can contain whitespaces. 179 * 180 * @param buf The path to the file from which the match ids are read. 181 * @param ids The list of match ids into which the match ids and 182 * scores are added. 183 * @return True if at least one match id and associated match score 184 * was successfully read, false otherwise. 185 */ 186 bool read_match_ids(const char *conf_path, match_id_list_t *ids) 187 { 188 log_msg(LOG_DEFAULT, LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path); 189 190 bool suc = false; 191 char *buf = NULL; 192 bool opened = false; 193 int fd; 194 size_t len = 0; 195 196 fd = open(conf_path, O_RDONLY); 197 if (fd < 0) { 198 log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to open `%s' for reading: %s.", 199 conf_path, str_error(fd)); 200 goto cleanup; 201 } 202 opened = true; 203 204 len = lseek(fd, 0, SEEK_END); 205 lseek(fd, 0, SEEK_SET); 206 if (len == 0) { 207 log_msg(LOG_DEFAULT, LVL_ERROR, "Configuration file '%s' is empty.", 208 conf_path); 209 goto cleanup; 210 } 211 212 buf = malloc(len + 1); 213 if (buf == NULL) { 214 log_msg(LOG_DEFAULT, LVL_ERROR, "Memory allocation failed when parsing file " 215 "'%s'.", conf_path); 216 goto cleanup; 217 } 218 219 ssize_t read_bytes = read_all(fd, buf, len); 220 if (read_bytes <= 0) { 221 log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to read file '%s' (%zd).", conf_path, 222 read_bytes); 223 goto cleanup; 224 } 225 buf[read_bytes] = 0; 226 227 suc = parse_match_ids(buf, ids); 228 229 cleanup: 230 free(buf); 231 232 if (opened) 233 close(fd); 234 235 return suc; 236 } 237 95 238 /** @} 96 239 */
Note:
See TracChangeset
for help on using the changeset viewer.