Changeset 8b1e15ac in mainline for uspace/drv
- Timestamp:
- 2011-02-11T22:26:36Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 68414f4a
- Parents:
- 1b367b4
- Location:
- uspace/drv
- Files:
-
- 10 edited
-
isa/isa.c (modified) (22 diffs)
-
ns8250/ns8250.c (modified) (10 diffs)
-
pciintel/pci.c (modified) (19 diffs)
-
pciintel/pci.h (modified) (2 diffs)
-
root/root.c (modified) (2 diffs)
-
rootpc/rootpc.c (modified) (9 diffs)
-
rootvirt/rootvirt.c (modified) (3 diffs)
-
test1/char.c (modified) (1 diff)
-
test1/test1.c (modified) (2 diffs)
-
test2/test2.c (modified) (4 diffs)
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 -
uspace/drv/ns8250/ns8250.c
r1b367b4 r8b1e15ac 1 /* 1 /* 2 2 * Copyright (c) 2010 Lenka Trochtova 3 3 * All rights reserved. … … 178 178 * error number otherwise. 179 179 */ 180 static int ns8250_read( device_t *dev, char *buf, size_t count)180 static int ns8250_read(function_t *fun, char *buf, size_t count) 181 181 { 182 182 int ret = EOK; 183 ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data;183 ns8250_dev_data_t *data = (ns8250_dev_data_t *) fun->dev->driver_data; 184 184 185 185 fibril_mutex_lock(&data->mutex); … … 212 212 * @return Zero on success. 213 213 */ 214 static int ns8250_write( device_t *dev, char *buf, size_t count)215 { 216 ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data;214 static int ns8250_write(function_t *fun, char *buf, size_t count) 215 { 216 ns8250_dev_data_t *data = (ns8250_dev_data_t *) fun->dev->driver_data; 217 217 size_t idx; 218 218 … … 719 719 static int ns8250_add_device(device_t *dev) 720 720 { 721 function_t *fun; 722 721 723 printf(NAME ": ns8250_add_device %s (handle = %d)\n", 722 724 dev->name, (int) dev->handle); … … 756 758 return res; 757 759 } 760 761 fun = create_function(); 762 fun->ftype = fun_exposed; 763 fun->name = "a"; 758 764 759 765 /* Set device operations. */ 760 dev->ops = &ns8250_dev_ops; 761 762 add_device_to_class(dev, "serial"); 766 fun->ops = &ns8250_dev_ops; 767 register_function(fun, dev); 768 769 add_function_to_class(fun, "serial"); 763 770 764 771 printf(NAME ": the %s device has been successfully initialized.\n", … … 775 782 * @param dev The device. 776 783 */ 777 static int ns8250_open( device_t *dev)778 { 779 ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data;784 static int ns8250_open(function_t *fun) 785 { 786 ns8250_dev_data_t *data = (ns8250_dev_data_t *) fun->dev->driver_data; 780 787 int res; 781 788 … … 799 806 * @param dev The device. 800 807 */ 801 static void ns8250_close( device_t *dev)802 { 803 ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data;808 static void ns8250_close(function_t *fun) 809 { 810 ns8250_dev_data_t *data = (ns8250_dev_data_t *) fun->dev->driver_data; 804 811 805 812 fibril_mutex_lock(&data->mutex); … … 877 884 * Configure the parameters of the serial communication. 878 885 */ 879 static void ns8250_default_handler( device_t *dev, ipc_callid_t callid,886 static void ns8250_default_handler(function_t *fun, ipc_callid_t callid, 880 887 ipc_call_t *call) 881 888 { … … 886 893 switch (method) { 887 894 case SERIAL_GET_COM_PROPS: 888 ns8250_get_props( dev, &baud_rate, &parity, &word_length,895 ns8250_get_props(fun->dev, &baud_rate, &parity, &word_length, 889 896 &stop_bits); 890 897 async_answer_4(callid, EOK, baud_rate, parity, word_length, … … 897 904 word_length = IPC_GET_ARG3(*call); 898 905 stop_bits = IPC_GET_ARG4(*call); 899 ret = ns8250_set_props( dev, baud_rate, parity, word_length,906 ret = ns8250_set_props(fun->dev, baud_rate, parity, word_length, 900 907 stop_bits); 901 908 async_answer_0(callid, ret); -
uspace/drv/pciintel/pci.c
r1b367b4 r8b1e15ac 61 61 ((1 << 31) | (bus << 16) | (dev << 11) | (fn << 8) | (reg & ~3)) 62 62 63 static hw_resource_list_t *pciintel_get_child_resources( device_t *dev)64 { 65 pci_ dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;66 67 if ( dev_data == NULL)63 static hw_resource_list_t *pciintel_get_child_resources(function_t *fun) 64 { 65 pci_fun_data_t *fun_data = (pci_fun_data_t *) fun->driver_data; 66 67 if (fun_data == NULL) 68 68 return NULL; 69 return & dev_data->hw_resources;70 } 71 72 static bool pciintel_enable_child_interrupt( device_t *dev)69 return &fun_data->hw_resources; 70 } 71 72 static bool pciintel_enable_child_interrupt(function_t *fun) 73 73 { 74 74 /* TODO */ … … 122 122 } 123 123 124 static void pci_conf_read( device_t *dev, int reg, uint8_t *buf, size_t len)125 { 126 assert( dev->parent!= NULL);127 128 pci_ dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;129 pci_bus_data_t *bus_data = (pci_bus_data_t *) dev->parent->driver_data;124 static void pci_conf_read(function_t *fun, int reg, uint8_t *buf, size_t len) 125 { 126 assert(fun->dev != NULL); 127 128 pci_fun_data_t *fun_data = (pci_fun_data_t *) fun->driver_data; 129 pci_bus_data_t *bus_data = (pci_bus_data_t *) fun->dev->driver_data; 130 130 131 131 fibril_mutex_lock(&bus_data->conf_mutex); 132 132 133 133 uint32_t conf_addr; 134 conf_addr = CONF_ADDR( dev_data->bus, dev_data->dev, dev_data->fn, reg);134 conf_addr = CONF_ADDR(fun_data->bus, fun_data->dev, fun_data->fn, reg); 135 135 void *addr = bus_data->conf_data_port + (reg & 3); 136 136 … … 152 152 } 153 153 154 static void pci_conf_write( device_t *dev, int reg, uint8_t *buf, size_t len)155 { 156 assert( dev->parent!= NULL);157 158 pci_ dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;159 pci_bus_data_t *bus_data = (pci_bus_data_t *) dev->parent->driver_data;154 static void pci_conf_write(function_t *fun, int reg, uint8_t *buf, size_t len) 155 { 156 assert(fun->dev != NULL); 157 158 pci_fun_data_t *fun_data = (pci_fun_data_t *) fun->driver_data; 159 pci_bus_data_t *bus_data = (pci_bus_data_t *) fun->dev->driver_data; 160 160 161 161 fibril_mutex_lock(&bus_data->conf_mutex); 162 162 163 163 uint32_t conf_addr; 164 conf_addr = CONF_ADDR( dev_data->bus, dev_data->dev, dev_data->fn, reg);164 conf_addr = CONF_ADDR(fun_data->bus, fun_data->dev, fun_data->fn, reg); 165 165 void *addr = bus_data->conf_data_port + (reg & 3); 166 166 … … 182 182 } 183 183 184 uint8_t pci_conf_read_8( device_t *dev, int reg)184 uint8_t pci_conf_read_8(function_t *fun, int reg) 185 185 { 186 186 uint8_t res; 187 pci_conf_read( dev, reg, &res, 1);187 pci_conf_read(fun, reg, &res, 1); 188 188 return res; 189 189 } 190 190 191 uint16_t pci_conf_read_16( device_t *dev, int reg)191 uint16_t pci_conf_read_16(function_t *fun, int reg) 192 192 { 193 193 uint16_t res; 194 pci_conf_read( dev, reg, (uint8_t *) &res, 2);194 pci_conf_read(fun, reg, (uint8_t *) &res, 2); 195 195 return res; 196 196 } 197 197 198 uint32_t pci_conf_read_32( device_t *dev, int reg)198 uint32_t pci_conf_read_32(function_t *fun, int reg) 199 199 { 200 200 uint32_t res; 201 pci_conf_read( dev, reg, (uint8_t *) &res, 4);201 pci_conf_read(fun, reg, (uint8_t *) &res, 4); 202 202 return res; 203 203 } 204 204 205 void pci_conf_write_8( device_t *dev, int reg, uint8_t val)206 { 207 pci_conf_write( dev, reg, (uint8_t *) &val, 1);208 } 209 210 void pci_conf_write_16( device_t *dev, int reg, uint16_t val)211 { 212 pci_conf_write( dev, reg, (uint8_t *) &val, 2);213 } 214 215 void pci_conf_write_32( device_t *dev, int reg, uint32_t val)216 { 217 pci_conf_write( dev, reg, (uint8_t *) &val, 4);218 } 219 220 void create_pci_match_ids( device_t *dev)221 { 222 pci_ dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;205 void pci_conf_write_8(function_t *fun, int reg, uint8_t val) 206 { 207 pci_conf_write(fun, reg, (uint8_t *) &val, 1); 208 } 209 210 void pci_conf_write_16(function_t *fun, int reg, uint16_t val) 211 { 212 pci_conf_write(fun, reg, (uint8_t *) &val, 2); 213 } 214 215 void pci_conf_write_32(function_t *fun, int reg, uint32_t val) 216 { 217 pci_conf_write(fun, reg, (uint8_t *) &val, 4); 218 } 219 220 void create_pci_match_ids(function_t *fun) 221 { 222 pci_fun_data_t *fun_data = (pci_fun_data_t *) fun->driver_data; 223 223 match_id_t *match_id = NULL; 224 224 char *match_id_str; … … 227 227 if (match_id != NULL) { 228 228 asprintf(&match_id_str, "pci/ven=%04x&dev=%04x", 229 dev_data->vendor_id, dev_data->device_id);229 fun_data->vendor_id, fun_data->device_id); 230 230 match_id->id = match_id_str; 231 231 match_id->score = 90; 232 add_match_id(& dev->match_ids, match_id);232 add_match_id(&fun->match_ids, match_id); 233 233 } 234 234 … … 237 237 238 238 void 239 pci_add_range( device_t *dev, uint64_t range_addr, size_t range_size, bool io)240 { 241 pci_ dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;242 hw_resource_list_t *hw_res_list = & dev_data->hw_resources;239 pci_add_range(function_t *fun, uint64_t range_addr, size_t range_size, bool io) 240 { 241 pci_fun_data_t *fun_data = (pci_fun_data_t *) fun->driver_data; 242 hw_resource_list_t *hw_res_list = &fun_data->hw_resources; 243 243 hw_resource_t *hw_resources = hw_res_list->resources; 244 244 size_t count = hw_res_list->count; … … 270 270 * @return The addr the address of the BAR which should be read next. 271 271 */ 272 int pci_read_bar( device_t *dev, int addr)272 int pci_read_bar(function_t *fun, int addr) 273 273 { 274 274 /* Value of the BAR */ … … 285 285 286 286 /* Get the value of the BAR. */ 287 val = pci_conf_read_32( dev, addr);287 val = pci_conf_read_32(fun, addr); 288 288 289 289 io = (bool) (val & 1); … … 305 305 306 306 /* Get the address mask. */ 307 pci_conf_write_32( dev, addr, 0xffffffff);308 mask = pci_conf_read_32( dev, addr);307 pci_conf_write_32(fun, addr, 0xffffffff); 308 mask = pci_conf_read_32(fun, addr); 309 309 310 310 /* Restore the original value. */ 311 pci_conf_write_32( dev, addr, val);312 val = pci_conf_read_32( dev, addr);311 pci_conf_write_32(fun, addr, val); 312 val = pci_conf_read_32(fun, addr); 313 313 314 314 range_size = pci_bar_mask_to_size(mask); 315 315 316 316 if (addrw64) { 317 range_addr = ((uint64_t)pci_conf_read_32( dev, addr + 4) << 32) |317 range_addr = ((uint64_t)pci_conf_read_32(fun, addr + 4) << 32) | 318 318 (val & 0xfffffff0); 319 319 } else { … … 322 322 323 323 if (range_addr != 0) { 324 printf(NAME ": device %s : ", dev->name);324 printf(NAME ": function %s : ", fun->name); 325 325 printf("address = %" PRIx64, range_addr); 326 326 printf(", size = %x\n", (unsigned int) range_size); 327 327 } 328 328 329 pci_add_range( dev, range_addr, range_size, io);329 pci_add_range(fun, range_addr, range_size, io); 330 330 331 331 if (addrw64) … … 335 335 } 336 336 337 void pci_add_interrupt( device_t *dev, int irq)338 { 339 pci_ dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;340 hw_resource_list_t *hw_res_list = & dev_data->hw_resources;337 void pci_add_interrupt(function_t *fun, int irq) 338 { 339 pci_fun_data_t *fun_data = (pci_fun_data_t *) fun->driver_data; 340 hw_resource_list_t *hw_res_list = &fun_data->hw_resources; 341 341 hw_resource_t *hw_resources = hw_res_list->resources; 342 342 size_t count = hw_res_list->count; … … 350 350 hw_res_list->count++; 351 351 352 printf(NAME ": device %s uses irq %x.\n", dev->name, irq);353 } 354 355 void pci_read_interrupt( device_t *dev)356 { 357 uint8_t irq = pci_conf_read_8( dev, PCI_BRIDGE_INT_LINE);352 printf(NAME ": function %s uses irq %x.\n", fun->name, irq); 353 } 354 355 void pci_read_interrupt(function_t *fun) 356 { 357 uint8_t irq = pci_conf_read_8(fun, PCI_BRIDGE_INT_LINE); 358 358 if (irq != 0xff) 359 pci_add_interrupt( dev, irq);359 pci_add_interrupt(fun, irq); 360 360 } 361 361 362 362 /** Enumerate (recursively) and register the devices connected to a pci bus. 363 363 * 364 * @param parentThe host-to-pci bridge device.364 * @param dev The host-to-pci bridge device. 365 365 * @param bus_num The bus number. 366 366 */ 367 void pci_bus_scan(device_t *parent, int bus_num) 368 { 369 device_t *dev = create_device(); 370 pci_dev_data_t *dev_data = create_pci_dev_data(); 371 dev->driver_data = dev_data; 372 dev->parent = parent; 367 void pci_bus_scan(device_t *dev, int bus_num) 368 { 369 function_t *fun = create_function(); 370 pci_fun_data_t *fun_data = create_pci_fun_data(); 371 fun->driver_data = fun_data; 373 372 374 373 int child_bus = 0; 375 374 int dnum, fnum; 376 375 bool multi; 377 uint8_t header_type; 376 uint8_t header_type; 377 378 /* We need this early, before registering. */ 379 fun->dev = dev; 378 380 379 381 for (dnum = 0; dnum < 32; dnum++) { 380 382 multi = true; 381 383 for (fnum = 0; multi && fnum < 8; fnum++) { 382 init_pci_ dev_data(dev_data, bus_num, dnum, fnum);383 dev_data->vendor_id = pci_conf_read_16(dev,384 init_pci_fun_data(fun_data, bus_num, dnum, fnum); 385 fun_data->vendor_id = pci_conf_read_16(fun, 384 386 PCI_VENDOR_ID); 385 dev_data->device_id = pci_conf_read_16(dev,387 fun_data->device_id = pci_conf_read_16(fun, 386 388 PCI_DEVICE_ID); 387 if ( dev_data->vendor_id == 0xffff) {389 if (fun_data->vendor_id == 0xffff) { 388 390 /* 389 391 * The device is not present, go on scanning the … … 396 398 } 397 399 398 header_type = pci_conf_read_8( dev, PCI_HEADER_TYPE);400 header_type = pci_conf_read_8(fun, PCI_HEADER_TYPE); 399 401 if (fnum == 0) { 400 402 /* Is the device multifunction? */ … … 404 406 header_type = header_type & 0x7F; 405 407 406 create_pci_dev_name(dev); 407 408 pci_alloc_resource_list(dev); 409 pci_read_bars(dev); 410 pci_read_interrupt(dev); 411 412 dev->ops = &pci_child_ops; 413 414 printf(NAME ": adding new child device %s.\n", 415 dev->name); 416 417 create_pci_match_ids(dev); 418 419 if (child_device_register(dev, parent) != EOK) { 420 pci_clean_resource_list(dev); 421 clean_match_ids(&dev->match_ids); 422 free((char *) dev->name); 423 dev->name = NULL; 408 create_pci_fun_name(fun); 409 410 pci_alloc_resource_list(fun); 411 pci_read_bars(fun); 412 pci_read_interrupt(fun); 413 414 fun->ftype = fun_inner; 415 fun->ops = &pci_child_ops; 416 417 printf(NAME ": adding new function %s.\n", 418 fun->name); 419 420 create_pci_match_ids(fun); 421 422 if (register_function(fun, dev) != EOK) { 423 pci_clean_resource_list(fun); 424 clean_match_ids(&fun->match_ids); 425 free((char *) fun->name); 426 fun->name = NULL; 424 427 continue; 425 428 } … … 427 430 if (header_type == PCI_HEADER_TYPE_BRIDGE || 428 431 header_type == PCI_HEADER_TYPE_CARDBUS) { 429 child_bus = pci_conf_read_8( dev,432 child_bus = pci_conf_read_8(fun, 430 433 PCI_BRIDGE_SEC_BUS_NUM); 431 434 printf(NAME ": device is pci-to-pci bridge, " 432 435 "secondary bus number = %d.\n", bus_num); 433 436 if (child_bus > bus_num) 434 pci_bus_scan( parent, child_bus);437 pci_bus_scan(dev, child_bus); 435 438 } 436 439 437 /* Alloc new aux. dev. structure. */ 438 dev = create_device(); 439 dev_data = create_pci_dev_data(); 440 dev->driver_data = dev_data; 441 dev->parent = parent; 440 /* Alloc new aux. fun. structure. */ 441 fun = create_function(); 442 443 /* We need this early, before registering. */ 444 fun->dev = dev; 445 446 fun_data = create_pci_fun_data(); 447 fun->driver_data = fun_data; 442 448 } 443 449 } 444 450 445 if ( dev_data->vendor_id == 0xffff) {446 delete_ device(dev);447 /* Free the auxiliary devicestructure. */448 delete_pci_ dev_data(dev_data);451 if (fun_data->vendor_id == 0xffff) { 452 delete_function(fun); 453 /* Free the auxiliary function structure. */ 454 delete_pci_fun_data(fun_data); 449 455 } 450 456 } … … 504 510 dev->driver_data = bus_data; 505 511 512 /* Make the bus device more visible. Does not do anything. */ 513 printf(NAME ": adding a 'ctl' function\n"); 514 515 function_t *ctl = create_function(); 516 ctl->ftype = fun_exposed; 517 ctl->name = "ctl"; 518 register_function(ctl, dev); 519 506 520 /* Enumerate child devices. */ 507 521 printf(NAME ": scanning the bus\n"); … … 518 532 } 519 533 520 pci_ dev_data_t *create_pci_dev_data(void)521 { 522 pci_ dev_data_t *res = (pci_dev_data_t *) malloc(sizeof(pci_dev_data_t));534 pci_fun_data_t *create_pci_fun_data(void) 535 { 536 pci_fun_data_t *res = (pci_fun_data_t *) malloc(sizeof(pci_fun_data_t)); 523 537 524 538 if (res != NULL) 525 memset(res, 0, sizeof(pci_ dev_data_t));539 memset(res, 0, sizeof(pci_fun_data_t)); 526 540 return res; 527 541 } 528 542 529 void init_pci_ dev_data(pci_dev_data_t *dev_data, int bus, int dev, int fn)530 { 531 dev_data->bus = bus;532 dev_data->dev = dev;533 dev_data->fn = fn;534 } 535 536 void delete_pci_ dev_data(pci_dev_data_t *dev_data)537 { 538 if ( dev_data != NULL) {539 hw_res_clean_resource_list(& dev_data->hw_resources);540 free( dev_data);541 } 542 } 543 544 void create_pci_ dev_name(device_t *dev)545 { 546 pci_ dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;543 void init_pci_fun_data(pci_fun_data_t *fun_data, int bus, int dev, int fn) 544 { 545 fun_data->bus = bus; 546 fun_data->dev = dev; 547 fun_data->fn = fn; 548 } 549 550 void delete_pci_fun_data(pci_fun_data_t *fun_data) 551 { 552 if (fun_data != NULL) { 553 hw_res_clean_resource_list(&fun_data->hw_resources); 554 free(fun_data); 555 } 556 } 557 558 void create_pci_fun_name(function_t *fun) 559 { 560 pci_fun_data_t *fun_data = (pci_fun_data_t *) fun->driver_data; 547 561 char *name = NULL; 548 562 549 asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev,550 dev_data->fn);551 dev->name = name;552 } 553 554 bool pci_alloc_resource_list( device_t *dev)555 { 556 pci_ dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;557 558 dev_data->hw_resources.resources =563 asprintf(&name, "%02x:%02x.%01x", fun_data->bus, fun_data->dev, 564 fun_data->fn); 565 fun->name = name; 566 } 567 568 bool pci_alloc_resource_list(function_t *fun) 569 { 570 pci_fun_data_t *fun_data = (pci_fun_data_t *)fun->driver_data; 571 572 fun_data->hw_resources.resources = 559 573 (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t)); 560 return dev_data->hw_resources.resources != NULL;561 } 562 563 void pci_clean_resource_list( device_t *dev)564 { 565 pci_ dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;566 567 if ( dev_data->hw_resources.resources != NULL) {568 free( dev_data->hw_resources.resources);569 dev_data->hw_resources.resources = NULL;574 return fun_data->hw_resources.resources != NULL; 575 } 576 577 void pci_clean_resource_list(function_t *fun) 578 { 579 pci_fun_data_t *fun_data = (pci_fun_data_t *) fun->driver_data; 580 581 if (fun_data->hw_resources.resources != NULL) { 582 free(fun_data->hw_resources.resources); 583 fun_data->hw_resources.resources = NULL; 570 584 } 571 585 } … … 576 590 * @param dev the pci device. 577 591 */ 578 void pci_read_bars( device_t *dev)592 void pci_read_bars(function_t *fun) 579 593 { 580 594 /* … … 585 599 586 600 while (addr <= PCI_BASE_ADDR_5) 587 addr = pci_read_bar( dev, addr);601 addr = pci_read_bar(fun, addr); 588 602 } 589 603 -
uspace/drv/pciintel/pci.h
r1b367b4 r8b1e15ac 44 44 #define PCI_MAX_HW_RES 8 45 45 46 typedef struct pci_ dev_data {46 typedef struct pci_fun_data { 47 47 int bus; 48 48 int dev; … … 51 51 int device_id; 52 52 hw_resource_list_t hw_resources; 53 } pci_ dev_data_t;53 } pci_fun_data_t; 54 54 55 extern void create_pci_match_ids( device_t *);55 extern void create_pci_match_ids(function_t *); 56 56 57 extern uint8_t pci_conf_read_8( device_t *, int);58 extern uint16_t pci_conf_read_16( device_t *, int);59 extern uint32_t pci_conf_read_32( device_t *, int);60 extern void pci_conf_write_8( device_t *, int, uint8_t);61 extern void pci_conf_write_16( device_t *, int, uint16_t);62 extern void pci_conf_write_32( device_t *, int, uint32_t);57 extern uint8_t pci_conf_read_8(function_t *, int); 58 extern uint16_t pci_conf_read_16(function_t *, int); 59 extern uint32_t pci_conf_read_32(function_t *, int); 60 extern void pci_conf_write_8(function_t *, int, uint8_t); 61 extern void pci_conf_write_16(function_t *, int, uint16_t); 62 extern void pci_conf_write_32(function_t *, int, uint32_t); 63 63 64 extern void pci_add_range( device_t *, uint64_t, size_t, bool);65 extern int pci_read_bar( device_t *, int);66 extern void pci_read_interrupt( device_t *);67 extern void pci_add_interrupt( device_t *, int);64 extern void pci_add_range(function_t *, uint64_t, size_t, bool); 65 extern int pci_read_bar(function_t *, int); 66 extern void pci_read_interrupt(function_t *); 67 extern void pci_add_interrupt(function_t *, int); 68 68 69 69 extern void pci_bus_scan(device_t *, int); 70 70 71 extern pci_ dev_data_t *create_pci_dev_data(void);72 extern void init_pci_ dev_data(pci_dev_data_t *, int, int, int);73 extern void delete_pci_ dev_data(pci_dev_data_t *);74 extern void create_pci_ dev_name(device_t *);71 extern pci_fun_data_t *create_pci_fun_data(void); 72 extern void init_pci_fun_data(pci_fun_data_t *, int, int, int); 73 extern void delete_pci_fun_data(pci_fun_data_t *); 74 extern void create_pci_fun_name(function_t *); 75 75 76 extern bool pci_alloc_resource_list( device_t *);77 extern void pci_clean_resource_list( device_t *);76 extern bool pci_alloc_resource_list(function_t *); 77 extern void pci_clean_resource_list(function_t *); 78 78 79 extern void pci_read_bars( device_t *);79 extern void pci_read_bars(function_t *); 80 80 extern size_t pci_bar_mask_to_size(uint32_t); 81 81 -
uspace/drv/root/root.c
r1b367b4 r8b1e15ac 87 87 VIRTUAL_DEVICE_MATCH_SCORE, VIRTUAL_DEVICE_MATCH_ID); 88 88 89 int res = child_device_register_wrapper(parent, VIRTUAL_DEVICE_NAME,89 int res = register_function_wrapper(parent, VIRTUAL_DEVICE_NAME, 90 90 VIRTUAL_DEVICE_MATCH_ID, VIRTUAL_DEVICE_MATCH_SCORE); 91 91 … … 135 135 PLATFORM_DEVICE_MATCH_SCORE, match_id); 136 136 137 res = child_device_register_wrapper(parent, PLATFORM_DEVICE_NAME,137 res = register_function_wrapper(parent, PLATFORM_DEVICE_NAME, 138 138 match_id, PLATFORM_DEVICE_MATCH_SCORE); 139 139 -
uspace/drv/rootpc/rootpc.c
r1b367b4 r8b1e15ac 55 55 #define NAME "rootpc" 56 56 57 typedef struct rootpc_ child_dev_data {57 typedef struct rootpc_fun_data { 58 58 hw_resource_list_t hw_resources; 59 } rootpc_ child_dev_data_t;59 } rootpc_fun_data_t; 60 60 61 61 static int rootpc_add_device(device_t *dev); … … 82 82 }; 83 83 84 static rootpc_ child_dev_data_t pci_data = {84 static rootpc_fun_data_t pci_data = { 85 85 .hw_resources = { 86 86 1, … … 89 89 }; 90 90 91 static hw_resource_list_t *rootpc_get_ child_resources(device_t *dev)92 { 93 rootpc_ child_dev_data_t *data;94 95 data = (rootpc_ child_dev_data_t *) dev->driver_data;91 static hw_resource_list_t *rootpc_get_fun_resources(function_t *fun) 92 { 93 rootpc_fun_data_t *data; 94 95 data = (rootpc_fun_data_t *) fun->driver_data; 96 96 if (NULL == data) 97 97 return NULL; … … 100 100 } 101 101 102 static bool rootpc_enable_ child_interrupt(device_t *dev)102 static bool rootpc_enable_fun_interrupt(function_t *fun) 103 103 { 104 104 /* TODO */ … … 107 107 } 108 108 109 static hw_res_ops_t child_hw_res_ops = {110 &rootpc_get_ child_resources,111 &rootpc_enable_ child_interrupt109 static hw_res_ops_t fun_hw_res_ops = { 110 &rootpc_get_fun_resources, 111 &rootpc_enable_fun_interrupt 112 112 }; 113 113 114 114 /* Initialized in root_pc_init() function. */ 115 static device_ops_t rootpc_ child_ops;115 static device_ops_t rootpc_fun_ops; 116 116 117 117 static bool 118 rootpc_add_ child(device_t *parent, const char *name, const char *str_match_id,119 rootpc_ child_dev_data_t *drv_data)120 { 121 printf(NAME ": adding new child device'%s'.\n", name);122 123 device_t *child= NULL;118 rootpc_add_fun(device_t *parent, const char *name, const char *str_match_id, 119 rootpc_fun_data_t *drv_data) 120 { 121 printf(NAME ": adding new function '%s'.\n", name); 122 123 function_t *fun = NULL; 124 124 match_id_t *match_id = NULL; 125 125 126 126 /* Create new device. */ 127 child = create_device();128 if ( NULL == child)127 fun = create_function(); 128 if (fun == NULL) 129 129 goto failure; 130 130 131 child->name = name; 132 child->driver_data = drv_data; 131 fun->name = name; 132 fun->driver_data = drv_data; 133 fun->ftype = fun_inner; 133 134 134 135 /* Initialize match id list */ … … 139 140 match_id->id = str_match_id; 140 141 match_id->score = 100; 141 add_match_id(& child->match_ids, match_id);142 add_match_id(&fun->match_ids, match_id); 142 143 143 144 /* Set provided operations to the device. */ 144 child->ops = &rootpc_child_ops;145 146 /* Register child device. */147 if (EOK != child_device_register(child, parent))145 fun->ops = &rootpc_fun_ops; 146 147 /* Register function. */ 148 if (EOK != register_function(fun, parent)) 148 149 goto failure; 150 printf(NAME ": registered function handle = %u\n", fun->handle); 149 151 150 152 return true; … … 154 156 match_id->id = NULL; 155 157 156 if (NULL != child) {157 child->name = NULL;158 delete_ device(child);159 } 160 161 printf(NAME ": failed to add child device'%s'.\n", name);158 if (NULL != fun) { 159 fun->name = NULL; 160 delete_function(fun); 161 } 162 163 printf(NAME ": failed to add function '%s'.\n", name); 162 164 163 165 return false; 164 166 } 165 167 166 static bool rootpc_add_ children(device_t *dev)167 { 168 return rootpc_add_ child(dev, "pci0", "intel_pci", &pci_data);168 static bool rootpc_add_functions(device_t *dev) 169 { 170 return rootpc_add_fun(dev, "pci0", "intel_pci", &pci_data); 169 171 } 170 172 … … 180 182 (int)dev->handle); 181 183 182 /* Register child devices. */183 if (!rootpc_add_ children(dev)) {184 printf(NAME ": failed to add child devices for PC platform.\n");184 /* Register functions. */ 185 if (!rootpc_add_functions(dev)) { 186 printf(NAME ": failed to add functions for PC platform.\n"); 185 187 } 186 188 … … 190 192 static void root_pc_init(void) 191 193 { 192 rootpc_ child_ops.interfaces[HW_RES_DEV_IFACE] = &child_hw_res_ops;194 rootpc_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops; 193 195 } 194 196 -
uspace/drv/rootvirt/rootvirt.c
r1b367b4 r8b1e15ac 43 43 #define NAME "rootvirt" 44 44 45 /** Virtual device entry.*/45 /** Virtual function entry */ 46 46 typedef struct { 47 /** Device name.*/47 /** Function name */ 48 48 const char *name; 49 /** Device match id.*/49 /** Function match ID */ 50 50 const char *match_id; 51 } virtual_ device_t;51 } virtual_function_t; 52 52 53 /** List of existing virtual devices.*/54 virtual_ device_t virtual_devices[] = {53 /** List of existing virtual functions */ 54 virtual_function_t virtual_functions[] = { 55 55 #include "devices.def" 56 /* Terminating item .*/56 /* Terminating item */ 57 57 { 58 58 .name = NULL, … … 72 72 }; 73 73 74 /** Add childdevice.74 /** Add function to the virtual device. 75 75 * 76 * @param parent Parent device.77 * @param v irt_dev Virtual device to add.78 * @return Error code.76 * @param vdev The virtual device 77 * @param vfun Virtual function description 78 * @return EOK on success or negative error code. 79 79 */ 80 static int add_child(device_t * parent, virtual_device_t *virt_dev)80 static int add_child(device_t *vdev, virtual_function_t *vfun) 81 81 { 82 printf(NAME ": registering child device`%s' (match \"%s\")\n",83 v irt_dev->name, virt_dev->match_id);82 printf(NAME ": registering function `%s' (match \"%s\")\n", 83 vfun->name, vfun->match_id); 84 84 85 int rc = child_device_register_wrapper(parent, virt_dev->name,86 v irt_dev->match_id, 10);85 int rc = register_function_wrapper(vdev, vfun->name, 86 vfun->match_id, 10); 87 87 88 88 if (rc == EOK) { 89 89 printf(NAME ": registered child device `%s'\n", 90 v irt_dev->name);90 vfun->name); 91 91 } else { 92 92 printf(NAME ": failed to register child device `%s': %s\n", 93 v irt_dev->name, str_error(rc));93 vfun->name, str_error(rc)); 94 94 } 95 95 … … 109 109 } 110 110 111 printf(NAME ": add_device(name=\"%s\", handle=%d)\n", 112 dev->name, (int)dev->handle); 111 printf(NAME ": add_device(handle=%d)\n", (int)dev->handle); 113 112 114 113 /* 115 * Go through all virtual devices and try to add them.114 * Go through all virtual functions and try to add them. 116 115 * We silently ignore failures. 117 116 */ 118 virtual_ device_t *virt_dev = virtual_devices;119 while (v irt_dev->name != NULL) {120 (void) add_child(dev, v irt_dev);121 v irt_dev++;117 virtual_function_t *vfun = virtual_functions; 118 while (vfun->name != NULL) { 119 (void) add_child(dev, vfun); 120 vfun++; 122 121 } 123 122 -
uspace/drv/test1/char.c
r1b367b4 r8b1e15ac 37 37 #include "test1.h" 38 38 39 static int impl_char_read( device_t *dev, char *buf, size_t count) {39 static int impl_char_read(function_t *fun, char *buf, size_t count) { 40 40 memset(buf, 0, count); 41 41 return count; 42 42 } 43 43 44 static int imp_char_write( device_t *dev, char *buf, size_t count) {44 static int imp_char_write(function_t *fun, char *buf, size_t count) { 45 45 return count; 46 46 } -
uspace/drv/test1/test1.c
r1b367b4 r8b1e15ac 61 61 name, message); 62 62 63 int rc = child_device_register_wrapper(parent, name,63 int rc = register_function_wrapper(parent, name, 64 64 match_id, match_score); 65 65 66 66 if (rc == EOK) { 67 printf(NAME ": registered child device`%s'.\n", name);67 printf(NAME ": registered function `%s'.\n", name); 68 68 } else { 69 printf(NAME ": failed to register child`%s' (%s).\n",69 printf(NAME ": failed to register function `%s' (%s).\n", 70 70 name, str_error(rc)); 71 71 } … … 91 91 static int add_device(device_t *dev) 92 92 { 93 function_t *fun_a; 94 93 95 printf(NAME ": add_device(name=\"%s\", handle=%d)\n", 94 96 dev->name, (int) dev->handle); 95 97 96 add_device_to_class(dev, "virtual"); 98 fun_a = create_function(); 99 fun_a->ftype = fun_exposed; 100 fun_a->name = "a"; 101 102 register_function(fun_a, dev); 103 104 add_function_to_class(fun_a, "virtual"); 97 105 98 106 if (str_cmp(dev->name, "null") == 0) { 99 dev->ops = &char_device_ops;100 add_ device_to_class(dev, "virt-null");101 } else if ( dev->parent == NULL) {107 fun_a->ops = &char_device_ops; 108 add_function_to_class(fun_a, "virt-null"); 109 } else if (str_cmp(dev->name, "test1") == 0) { 102 110 register_child_verbose(dev, "cloning myself ;-)", "clone", 103 111 "virtual&test1", 10); -
uspace/drv/test2/test2.c
r1b367b4 r8b1e15ac 63 63 name, message); 64 64 65 int rc = child_device_register_wrapper(parent, name,65 int rc = register_function_wrapper(parent, name, 66 66 match_id, match_score); 67 67 … … 82 82 { 83 83 device_t *dev = (device_t *) arg; 84 function_t *fun; 84 85 85 86 async_usleep(1000); … … 90 91 "test1", "virtual&test1", 10); 91 92 92 add_device_to_class(dev, "virtual"); 93 fun = create_function(); 94 fun->ftype = fun_exposed; 95 fun->name = "a"; 96 97 register_function(fun, dev); 98 99 add_function_to_class(fun, "virtual"); 93 100 94 101 return EOK; 95 102 } 96 97 103 98 104 static int add_device(device_t *dev) … … 101 107 dev->name, (int) dev->handle); 102 108 103 if ( dev->parent == NULL) {109 if (str_cmp(dev->name, "child") != 0) { 104 110 fid_t postpone = fibril_create(postponed_birth, dev); 105 111 if (postpone == 0) {
Note:
See TracChangeset
for help on using the changeset viewer.
