Changeset 8b1e15ac in mainline for uspace/drv/isa/isa.c
- Timestamp:
- 2011-02-11T22:26:36Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 68414f4a
- Parents:
- 1b367b4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/isa/isa.c
r1b367b4 r8b1e15ac 58 58 59 59 #define NAME "isa" 60 #define CHILD_ DEV_CONF_PATH "/drv/isa/isa.dev"60 #define CHILD_FUN_CONF_PATH "/drv/isa/isa.dev" 61 61 62 62 #define ISA_MAX_HW_RES 4 63 63 64 typedef struct isa_ child_data {64 typedef struct isa_fun_data { 65 65 hw_resource_list_t hw_resources; 66 } isa_ child_data_t;67 68 static hw_resource_list_t *isa_get_ child_resources(device_t *dev)69 { 70 isa_ child_data_t *dev_data;71 72 dev_data = (isa_child_data_t *)dev->driver_data;73 if ( dev_data == NULL)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 74 return NULL; 75 75 76 return & dev_data->hw_resources;77 } 78 79 static bool isa_enable_ child_interrupt(device_t *dev)76 return &fun_data->hw_resources; 77 } 78 79 static bool isa_enable_fun_interrupt(function_t *fun) 80 80 { 81 81 // TODO … … 84 84 } 85 85 86 static hw_res_ops_t isa_ child_hw_res_ops = {87 &isa_get_ child_resources,88 &isa_enable_ child_interrupt86 static hw_res_ops_t isa_fun_hw_res_ops = { 87 &isa_get_fun_resources, 88 &isa_enable_fun_interrupt 89 89 }; 90 90 91 static device_ops_t isa_ child_dev_ops;91 static device_ops_t isa_fun_dev_ops; 92 92 93 93 static int isa_add_device(device_t *dev); … … 105 105 106 106 107 static isa_ child_data_t *create_isa_child_data()108 { 109 isa_ child_data_t *data;110 111 data = (isa_ child_data_t *) malloc(sizeof(isa_child_data_t));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 112 if (data != NULL) 113 memset(data, 0, sizeof(isa_ child_data_t));113 memset(data, 0, sizeof(isa_fun_data_t)); 114 114 115 115 return data; 116 116 } 117 117 118 static device_t *create_isa_child_dev()119 { 120 device_t *dev = create_device();121 if ( dev== NULL)118 static function_t *create_isa_fun() 119 { 120 function_t *fun = create_function(); 121 if (fun == NULL) 122 122 return NULL; 123 123 124 isa_ child_data_t *data = create_isa_child_data();124 isa_fun_data_t *data = create_isa_fun_data(); 125 125 if (data == NULL) { 126 delete_ device(dev);126 delete_function(fun); 127 127 return NULL; 128 128 } 129 129 130 dev->driver_data = data;131 return dev;132 } 133 134 static char *read_ dev_conf(const char *conf_path)130 fun->driver_data = data; 131 return fun; 132 } 133 134 static char *read_fun_conf(const char *conf_path) 135 135 { 136 136 bool suc = false; … … 151 151 lseek(fd, 0, SEEK_SET); 152 152 if (len == 0) { 153 printf(NAME ": read_ dev_conf error: configuration file '%s' "153 printf(NAME ": read_fun_conf error: configuration file '%s' " 154 154 "is empty.\n", conf_path); 155 155 goto cleanup; … … 158 158 buf = malloc(len + 1); 159 159 if (buf == NULL) { 160 printf(NAME ": read_ dev_conf error: memory allocation failed.\n");160 printf(NAME ": read_fun_conf error: memory allocation failed.\n"); 161 161 goto cleanup; 162 162 } 163 163 164 164 if (0 >= read(fd, buf, len)) { 165 printf(NAME ": read_ dev_conf error: unable to read file '%s'.\n",165 printf(NAME ": read_fun_conf error: unable to read file '%s'.\n", 166 166 conf_path); 167 167 goto cleanup; … … 249 249 } 250 250 251 static void isa_ child_set_irq(device_t *dev, int irq)252 { 253 isa_ child_data_t *data = (isa_child_data_t *)dev->driver_data;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 254 255 255 size_t count = data->hw_resources.count; … … 262 262 data->hw_resources.count++; 263 263 264 printf(NAME ": added irq 0x%x to device %s\n", irq, dev->name);265 } 266 } 267 268 static void isa_ child_set_io_range(device_t *dev, size_t addr, size_t len)269 { 270 isa_ child_data_t *data = (isa_child_data_t *)dev->driver_data;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 271 272 272 size_t count = data->hw_resources.count; … … 282 282 283 283 printf(NAME ": added io range (addr=0x%x, size=0x%x) to " 284 " device%s\n", (unsigned int) addr, (unsigned int) len,285 dev->name);286 } 287 } 288 289 static void get_dev_irq( device_t *dev, char *val)284 "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) 290 290 { 291 291 int irq = 0; 292 292 char *end = NULL; 293 293 294 val = skip_spaces(val); 294 val = skip_spaces(val); 295 295 irq = (int)strtol(val, &end, 0x10); 296 296 297 297 if (val != end) 298 isa_ child_set_irq(dev, irq);299 } 300 301 static void get_dev_io_range( device_t *dev, char *val)298 isa_fun_set_irq(fun, irq); 299 } 300 301 static void get_dev_io_range(function_t *fun, char *val) 302 302 { 303 303 size_t addr, len; 304 304 char *end = NULL; 305 305 306 val = skip_spaces(val); 306 val = skip_spaces(val); 307 307 addr = strtol(val, &end, 0x10); 308 308 … … 310 310 return; 311 311 312 val = skip_spaces(end); 312 val = skip_spaces(end); 313 313 len = strtol(val, &end, 0x10); 314 314 … … 316 316 return; 317 317 318 isa_ child_set_io_range(dev, addr, len);318 isa_fun_set_io_range(fun, addr, len); 319 319 } 320 320 … … 331 331 } 332 332 333 static void get_ dev_match_id(device_t *dev, char *val)333 static void get_fun_match_id(function_t *fun, char *val) 334 334 { 335 335 char *id = NULL; … … 342 342 if (val == end) { 343 343 printf(NAME " : error - could not read match score for " 344 " device %s.\n", dev->name);344 "function %s.\n", fun->name); 345 345 return; 346 346 } … … 348 348 match_id_t *match_id = create_match_id(); 349 349 if (match_id == NULL) { 350 printf(NAME " : failed to allocate match id for device%s.\n",351 dev->name);350 printf(NAME " : failed to allocate match id for function %s.\n", 351 fun->name); 352 352 return; 353 353 } … … 357 357 if (id == NULL) { 358 358 printf(NAME " : error - could not read match id for " 359 " device %s.\n", dev->name);359 "function %s.\n", fun->name); 360 360 delete_match_id(match_id); 361 361 return; … … 365 365 match_id->score = score; 366 366 367 printf(NAME ": adding match id '%s' with score %d to device%s\n", id,368 score, dev->name);369 add_match_id(& dev->match_ids, match_id);370 } 371 372 static bool read_ dev_prop(device_t *dev, char *line, const char *prop,373 void (*read_fn)( device_t *, char *))367 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 *)) 374 374 { 375 375 size_t proplen = str_size(prop); … … 378 378 line += proplen; 379 379 line = skip_spaces(line); 380 (*read_fn)( dev, line);380 (*read_fn)(fun, line); 381 381 382 382 return true; … … 386 386 } 387 387 388 static void get_ dev_prop(device_t *dev, char *line)388 static void get_fun_prop(function_t *fun, char *line) 389 389 { 390 390 /* Skip leading spaces. */ 391 391 line = skip_spaces(line); 392 392 393 if (!read_ dev_prop(dev, line, "io_range", &get_dev_io_range) &&394 !read_ dev_prop(dev, line, "irq", &get_dev_irq) &&395 !read_ dev_prop(dev, line, "match", &get_dev_match_id))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)) 396 396 { 397 397 printf(NAME " error undefined device property at line '%s'\n", … … 400 400 } 401 401 402 static void child_alloc_hw_res( device_t *dev)403 { 404 isa_ child_data_t *data = (isa_child_data_t *)dev->driver_data;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 405 data->hw_resources.resources = 406 406 (hw_resource_t *)malloc(sizeof(hw_resource_t) * ISA_MAX_HW_RES); 407 407 } 408 408 409 static char *read_isa_ dev_info(char *dev_conf, device_t *parent)409 static char *read_isa_fun_info(char *fun_conf, device_t *dev) 410 410 { 411 411 char *line; 412 char * dev_name = NULL;412 char *fun_name = NULL; 413 413 414 414 /* Skip empty lines. */ 415 415 while (true) { 416 line = str_get_line( dev_conf, &dev_conf);416 line = str_get_line(fun_conf, &fun_conf); 417 417 418 418 if (line == NULL) { … … 426 426 427 427 /* Get device name. */ 428 dev_name = get_device_name(line);429 if ( dev_name == NULL)428 fun_name = get_device_name(line); 429 if (fun_name == NULL) 430 430 return NULL; 431 431 432 device_t *dev = create_isa_child_dev();433 if ( dev== NULL) {434 free( dev_name);432 function_t *fun = create_isa_fun(); 433 if (fun == NULL) { 434 free(fun_name); 435 435 return NULL; 436 436 } 437 437 438 dev->name = dev_name; 438 fun->name = fun_name; 439 fun->ftype = fun_inner; 439 440 440 441 /* Allocate buffer for the list of hardware resources of the device. */ 441 child_alloc_hw_res( dev);442 child_alloc_hw_res(fun); 442 443 443 444 /* Get properties of the device (match ids, irq and io range). */ 444 445 while (true) { 445 line = str_get_line( dev_conf, &dev_conf);446 line = str_get_line(fun_conf, &fun_conf); 446 447 447 448 if (line_empty(line)) { … … 454 455 * and store it in the device structure. 455 456 */ 456 get_ dev_prop(dev, line);457 458 //printf(NAME ": next line ='%s'\n", dev_conf);457 get_fun_prop(fun, line); 458 459 //printf(NAME ": next line ='%s'\n", fun_conf); 459 460 //printf(NAME ": current line ='%s'\n", line); 460 461 } 461 462 462 463 /* Set device operations to the device. */ 463 dev->ops = &isa_child_dev_ops;464 465 printf(NAME ": child_device_register(dev, parent); deviceis %s.\n",466 dev->name);467 child_device_register(dev, parent);468 469 return dev_conf;470 } 471 472 static void parse_ dev_conf(char *conf, device_t *parent)464 fun->ops = &isa_fun_dev_ops; 465 466 printf(NAME ": register_function(fun, dev); function is %s.\n", 467 fun->name); 468 register_function(fun, dev); 469 470 return fun_conf; 471 } 472 473 static void parse_fun_conf(char *conf, device_t *dev) 473 474 { 474 475 while (conf != NULL && *conf != '\0') { 475 conf = read_isa_ dev_info(conf, parent);476 } 477 } 478 479 static void add_legacy_children(device_t * parent)480 { 481 char * dev_conf;482 483 dev_conf = read_dev_conf(CHILD_DEV_CONF_PATH);484 if ( dev_conf != NULL) {485 parse_ dev_conf(dev_conf, parent);486 free( dev_conf);476 conf = read_isa_fun_info(conf, dev); 477 } 478 } 479 480 static void add_legacy_children(device_t *dev) 481 { 482 char *fun_conf; 483 484 fun_conf = read_fun_conf(CHILD_FUN_CONF_PATH); 485 if (fun_conf != NULL) { 486 parse_fun_conf(fun_conf, dev); 487 free(fun_conf); 487 488 } 488 489 } … … 492 493 printf(NAME ": isa_add_device, device handle = %d\n", 493 494 (int) dev->handle); 495 496 /* Make the bus device more visible. Does not do anything. */ 497 printf(NAME ": adding a 'ctl' function\n"); 498 499 function_t *ctl = create_function(); 500 ctl->ftype = fun_exposed; 501 ctl->name = "ctl"; 502 register_function(ctl, dev); 494 503 495 504 /* Add child devices. */ … … 502 511 static void isa_init() 503 512 { 504 isa_ child_dev_ops.interfaces[HW_RES_DEV_IFACE] = &isa_child_hw_res_ops;513 isa_fun_dev_ops.interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops; 505 514 } 506 515
Note:
See TracChangeset
for help on using the changeset viewer.