Changeset 68414f4a in mainline for uspace/drv/isa/isa.c
- Timestamp:
- 2011-02-13T20:03:45Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bab6388
- Parents:
- 8b1e15ac
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/isa/isa.c
r8b1e15ac r68414f4a 1 1 /* 2 2 * Copyright (c) 2010 Lenka Trochtova 3 * Copyright (c) 2011 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 60 61 #define CHILD_FUN_CONF_PATH "/drv/isa/isa.dev" 61 62 63 /** Obtain soft-state pointer from function node pointer */ 64 #define ISA_FUN(fnode) ((isa_fun_t *) ((fnode)->driver_data)) 65 62 66 #define ISA_MAX_HW_RES 4 63 67 64 typedef struct isa_fun_data { 68 typedef struct isa_fun { 69 function_t *fnode; 65 70 hw_resource_list_t hw_resources; 66 } isa_fun_data_t; 67 68 static hw_resource_list_t *isa_get_fun_resources(function_t *fun) 69 { 70 isa_fun_data_t *fun_data; 71 72 fun_data = (isa_fun_data_t *)fun->driver_data; 73 if (fun_data == NULL) 74 return NULL; 75 76 return &fun_data->hw_resources; 77 } 78 79 static bool isa_enable_fun_interrupt(function_t *fun) 71 } isa_fun_t; 72 73 static hw_resource_list_t *isa_get_fun_resources(function_t *fnode) 74 { 75 isa_fun_t *fun = ISA_FUN(fnode); 76 assert(fun != NULL); 77 78 return &fun->hw_resources; 79 } 80 81 static bool isa_enable_fun_interrupt(function_t *fnode) 80 82 { 81 83 // TODO … … 89 91 }; 90 92 91 static device_ops_t isa_fun_ dev_ops;93 static device_ops_t isa_fun_ops; 92 94 93 95 static int isa_add_device(device_t *dev); … … 104 106 }; 105 107 106 107 static isa_fun_data_t *create_isa_fun_data() 108 { 109 isa_fun_data_t *data; 110 111 data = (isa_fun_data_t *) malloc(sizeof(isa_fun_data_t)); 112 if (data != NULL) 113 memset(data, 0, sizeof(isa_fun_data_t)); 114 115 return data; 116 } 117 118 static function_t *create_isa_fun() 119 { 120 function_t *fun = create_function(); 108 static isa_fun_t *isa_fun_create() 109 { 110 isa_fun_t *fun = calloc(1, sizeof(isa_fun_t)); 121 111 if (fun == NULL) 122 112 return NULL; 123 113 124 isa_fun_data_t *data = create_isa_fun_data();125 if ( data== NULL) {126 delete_function(fun);114 function_t *fnode = create_function(); 115 if (fnode == NULL) { 116 free(fun); 127 117 return NULL; 128 118 } 129 119 130 fun->driver_data = data; 120 fun->fnode = fnode; 121 fnode->driver_data = fun; 131 122 return fun; 132 123 } 133 124 134 static char * read_fun_conf(const char *conf_path)125 static char *fun_conf_read(const char *conf_path) 135 126 { 136 127 bool suc = false; … … 151 142 lseek(fd, 0, SEEK_SET); 152 143 if (len == 0) { 153 printf(NAME ": read_fun_conferror: configuration file '%s' "144 printf(NAME ": fun_conf_read error: configuration file '%s' " 154 145 "is empty.\n", conf_path); 155 146 goto cleanup; … … 158 149 buf = malloc(len + 1); 159 150 if (buf == NULL) { 160 printf(NAME ": read_fun_conferror: memory allocation failed.\n");151 printf(NAME ": fun_conf_read error: memory allocation failed.\n"); 161 152 goto cleanup; 162 153 } 163 154 164 155 if (0 >= read(fd, buf, len)) { 165 printf(NAME ": read_fun_conferror: unable to read file '%s'.\n",156 printf(NAME ": fun_conf_read error: unable to read file '%s'.\n", 166 157 conf_path); 167 158 goto cleanup; … … 249 240 } 250 241 251 static void isa_fun_set_irq(function_t *fun, int irq) 252 { 253 isa_fun_data_t *data = (isa_fun_data_t *)fun->driver_data; 254 255 size_t count = data->hw_resources.count; 256 hw_resource_t *resources = data->hw_resources.resources; 242 static void isa_fun_set_irq(isa_fun_t *fun, int irq) 243 { 244 size_t count = fun->hw_resources.count; 245 hw_resource_t *resources = fun->hw_resources.resources; 257 246 258 247 if (count < ISA_MAX_HW_RES) { … … 260 249 resources[count].res.interrupt.irq = irq; 261 250 262 data->hw_resources.count++; 263 264 printf(NAME ": added irq 0x%x to function %s\n", irq, fun->name); 265 } 266 } 267 268 static void isa_fun_set_io_range(function_t *fun, size_t addr, size_t len) 269 { 270 isa_fun_data_t *data = (isa_fun_data_t *)fun->driver_data; 271 272 size_t count = data->hw_resources.count; 273 hw_resource_t *resources = data->hw_resources.resources; 251 fun->hw_resources.count++; 252 253 printf(NAME ": added irq 0x%x to function %s\n", irq, 254 fun->fnode->name); 255 } 256 } 257 258 static void isa_fun_set_io_range(isa_fun_t *fun, size_t addr, size_t len) 259 { 260 size_t count = fun->hw_resources.count; 261 hw_resource_t *resources = fun->hw_resources.resources; 274 262 275 263 if (count < ISA_MAX_HW_RES) { … … 279 267 resources[count].res.io_range.endianness = LITTLE_ENDIAN; 280 268 281 data->hw_resources.count++;269 fun->hw_resources.count++; 282 270 283 271 printf(NAME ": added io range (addr=0x%x, size=0x%x) to " 284 272 "function %s\n", (unsigned int) addr, (unsigned int) len, 285 fun-> name);286 } 287 } 288 289 static void get_dev_irq(function_t *fun, char *val)273 fun->fnode->name); 274 } 275 } 276 277 static void fun_parse_irq(isa_fun_t *fun, char *val) 290 278 { 291 279 int irq = 0; … … 299 287 } 300 288 301 static void get_dev_io_range(function_t *fun, char *val)289 static void fun_parse_io_range(isa_fun_t *fun, char *val) 302 290 { 303 291 size_t addr, len; … … 331 319 } 332 320 333 static void get_fun_match_id(function_t *fun, char *val)321 static void fun_parse_match_id(isa_fun_t *fun, char *val) 334 322 { 335 323 char *id = NULL; … … 337 325 char *end = NULL; 338 326 339 val = skip_spaces(val); 327 val = skip_spaces(val); 340 328 341 329 score = (int)strtol(val, &end, 10); 342 330 if (val == end) { 343 331 printf(NAME " : error - could not read match score for " 344 "function %s.\n", fun-> name);332 "function %s.\n", fun->fnode->name); 345 333 return; 346 334 } … … 349 337 if (match_id == NULL) { 350 338 printf(NAME " : failed to allocate match id for function %s.\n", 351 fun-> name);339 fun->fnode->name); 352 340 return; 353 341 } … … 357 345 if (id == NULL) { 358 346 printf(NAME " : error - could not read match id for " 359 "function %s.\n", fun-> name);347 "function %s.\n", fun->fnode->name); 360 348 delete_match_id(match_id); 361 349 return; … … 366 354 367 355 printf(NAME ": adding match id '%s' with score %d to function %s\n", id, 368 score, fun-> name);369 add_match_id(&fun-> match_ids, match_id);370 } 371 372 static bool read_fun_prop(function_t *fun, char *line, const char *prop,373 void (*read_fn)( function_t *, char *))356 score, fun->fnode->name); 357 add_match_id(&fun->fnode->match_ids, match_id); 358 } 359 360 static bool prop_parse(isa_fun_t *fun, char *line, const char *prop, 361 void (*read_fn)(isa_fun_t *, char *)) 374 362 { 375 363 size_t proplen = str_size(prop); … … 386 374 } 387 375 388 static void get_fun_prop(function_t *fun, char *line)376 static void fun_prop_parse(isa_fun_t *fun, char *line) 389 377 { 390 378 /* Skip leading spaces. */ 391 379 line = skip_spaces(line); 392 380 393 if (! read_fun_prop(fun, line, "io_range", &get_dev_io_range) &&394 ! read_fun_prop(fun, line, "irq", &get_dev_irq) &&395 ! read_fun_prop(fun, line, "match", &get_fun_match_id))381 if (!prop_parse(fun, line, "io_range", &fun_parse_io_range) && 382 !prop_parse(fun, line, "irq", &fun_parse_irq) && 383 !prop_parse(fun, line, "match", &fun_parse_match_id)) 396 384 { 397 385 printf(NAME " error undefined device property at line '%s'\n", … … 400 388 } 401 389 402 static void child_alloc_hw_res(function_t *fun) 403 { 404 isa_fun_data_t *data = (isa_fun_data_t *)fun->driver_data; 405 data->hw_resources.resources = 390 static void fun_hw_res_alloc(isa_fun_t *fun) 391 { 392 fun->hw_resources.resources = 406 393 (hw_resource_t *)malloc(sizeof(hw_resource_t) * ISA_MAX_HW_RES); 407 394 } 408 395 409 static char * read_isa_fun_info(char *fun_conf, device_t *dev)396 static char *isa_fun_read_info(char *fun_conf, device_t *dev) 410 397 { 411 398 char *line; … … 430 417 return NULL; 431 418 432 function_t *fun = create_isa_fun();419 isa_fun_t *fun = isa_fun_create(); 433 420 if (fun == NULL) { 434 421 free(fun_name); … … 436 423 } 437 424 438 fun->name = fun_name; 439 fun->ftype = fun_inner; 425 function_t *fnode = fun->fnode; 426 fnode->name = fun_name; 427 fnode->ftype = fun_inner; 440 428 441 429 /* Allocate buffer for the list of hardware resources of the device. */ 442 child_alloc_hw_res(fun);430 fun_hw_res_alloc(fun); 443 431 444 432 /* Get properties of the device (match ids, irq and io range). */ … … 455 443 * and store it in the device structure. 456 444 */ 457 get_fun_prop(fun, line); 458 459 //printf(NAME ": next line ='%s'\n", fun_conf); 460 //printf(NAME ": current line ='%s'\n", line); 445 fun_prop_parse(fun, line); 461 446 } 462 447 463 448 /* Set device operations to the device. */ 464 f un->ops = &isa_fun_dev_ops;449 fnode->ops = &isa_fun_ops; 465 450 466 451 printf(NAME ": register_function(fun, dev); function is %s.\n", 467 f un->name);468 register_function(f un, dev);452 fnode->name); 453 register_function(fnode, dev); 469 454 470 455 return fun_conf; 471 456 } 472 457 473 static void parse_fun_conf(char *conf, device_t *dev)458 static void fun_conf_parse(char *conf, device_t *dev) 474 459 { 475 460 while (conf != NULL && *conf != '\0') { 476 conf = read_isa_fun_info(conf, dev);477 } 478 } 479 480 static void add_legacy_children(device_t *dev)461 conf = isa_fun_read_info(conf, dev); 462 } 463 } 464 465 static void isa_functions_add(device_t *dev) 481 466 { 482 467 char *fun_conf; 483 468 484 fun_conf = read_fun_conf(CHILD_FUN_CONF_PATH);469 fun_conf = fun_conf_read(CHILD_FUN_CONF_PATH); 485 470 if (fun_conf != NULL) { 486 parse_fun_conf(fun_conf, dev);471 fun_conf_parse(fun_conf, dev); 487 472 free(fun_conf); 488 473 } … … 502 487 register_function(ctl, dev); 503 488 504 /* Add child devices. */505 add_legacy_children(dev);506 printf(NAME ": finished the enumeration of legacy devices\n");489 /* Add functions as specified in the configuration file. */ 490 isa_functions_add(dev); 491 printf(NAME ": finished the enumeration of legacy functions\n"); 507 492 508 493 return EOK; … … 511 496 static void isa_init() 512 497 { 513 isa_fun_ dev_ops.interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops;498 isa_fun_ops.interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops; 514 499 } 515 500 … … 524 509 * @} 525 510 */ 526
Note:
See TracChangeset
for help on using the changeset viewer.