Changeset 8b1e15ac in mainline
- Timestamp:
- 2011-02-11T22:26:36Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 68414f4a
- Parents:
- 1b367b4
- Location:
- uspace
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/hw/serial/serial1.c
r1b367b4 r8b1e15ac 74 74 75 75 devman_handle_t handle; 76 res = devman_device_get_handle("/hw/pci0/00:01.0/com1 ", &handle,76 res = devman_device_get_handle("/hw/pci0/00:01.0/com1/a", &handle, 77 77 IPC_FLAG_BLOCKING); 78 78 if (res != EOK) -
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) { -
uspace/lib/c/generic/devman.c
r1b367b4 r8b1e15ac 158 158 } 159 159 160 int devman_child_device_register(const char *name, match_id_list_t *match_ids, 161 devman_handle_t parent_handle, devman_handle_t *handle) 160 /** Add function to a device. 161 * 162 * Request devman to add a new function to the specified device owned by 163 * this driver task. 164 * 165 * @param name Name of the new function 166 * @param ftype Function type, fun_inner or fun_exposed 167 * @param match_ids Match IDs (should be empty for fun_exposed) 168 * @param devh Devman handle of the device 169 * @param funh Place to store handle of the new function 170 * 171 * @return EOK on success or negative error code. 172 */ 173 int devman_add_function(const char *name, fun_type_t ftype, 174 match_id_list_t *match_ids, devman_handle_t devh, devman_handle_t *funh) 162 175 { 163 176 int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING); 177 int fun_handle; 164 178 165 179 if (phone < 0) … … 168 182 async_serialize_start(); 169 183 170 int match_count = list_count(&match_ids->ids); 171 ipc_call_t answer; 172 aid_t req = async_send_2(phone, DEVMAN_ADD_CHILD_DEVICE, parent_handle, match_count, 173 &answer); 184 int match_count = list_count(&match_ids->ids); 185 ipc_call_t answer; 186 187 aid_t req = async_send_3(phone, DEVMAN_ADD_FUNCTION, (sysarg_t) ftype, 188 devh, match_count, &answer); 174 189 175 190 sysarg_t retval = async_data_write_start(phone, name, str_size(name)); … … 186 201 async_serialize_end(); 187 202 188 if (retval != EOK) { 189 if (handle != NULL) 190 *handle = -1; 191 192 return retval; 193 } 194 195 if (handle != NULL) 196 *handle = (int) IPC_GET_ARG1(answer); 197 203 if (retval == EOK) 204 fun_handle = (int) IPC_GET_ARG1(answer); 205 else 206 fun_handle = -1; 207 208 *funh = fun_handle; 209 198 210 return retval; 199 211 } -
uspace/lib/c/include/devman.h
r1b367b4 r8b1e15ac 45 45 46 46 extern int devman_driver_register(const char *, async_client_conn_t); 47 extern int devman_ child_device_register(const char *, match_id_list_t *,47 extern int devman_add_function(const char *, fun_type_t, match_id_list_t *, 48 48 devman_handle_t, devman_handle_t *); 49 49 -
uspace/lib/c/include/ipc/devman.h
r1b367b4 r8b1e15ac 42 42 43 43 typedef sysarg_t devman_handle_t; 44 45 typedef enum { 46 /** Invalid value for debugging purposes */ 47 fun_invalid = 0, 48 /** Function to which child devices attach */ 49 fun_inner, 50 /** Fuction exported to external clients (leaf function) */ 51 fun_exposed 52 } fun_type_t; 44 53 45 54 /** Ids of device models used for device-to-driver matching. … … 127 136 typedef enum { 128 137 DEVMAN_DRIVER_REGISTER = IPC_FIRST_USER_METHOD, 129 DEVMAN_ADD_ CHILD_DEVICE,138 DEVMAN_ADD_FUNCTION, 130 139 DEVMAN_ADD_MATCH_ID, 131 140 DEVMAN_ADD_DEVICE_TO_CLASS -
uspace/lib/drv/generic/driver.c
r1b367b4 r8b1e15ac 59 59 60 60 /** Devices */ 61 LIST_INITIALIZE( devices);62 FIBRIL_MUTEX_INITIALIZE( devices_mutex);61 LIST_INITIALIZE(functions); 62 FIBRIL_MUTEX_INITIALIZE(functions_mutex); 63 63 64 64 /** Interrupts */ … … 209 209 } 210 210 211 static void add_to_devices_list(device_t *dev) 212 { 213 fibril_mutex_lock(&devices_mutex); 214 list_append(&dev->link, &devices); 215 fibril_mutex_unlock(&devices_mutex); 216 } 217 218 static void remove_from_devices_list(device_t *dev) 219 { 220 fibril_mutex_lock(&devices_mutex); 221 list_remove(&dev->link); 222 fibril_mutex_unlock(&devices_mutex); 223 } 224 225 static device_t *driver_get_device(link_t *devices, devman_handle_t handle) 226 { 227 device_t *dev = NULL; 228 229 fibril_mutex_lock(&devices_mutex); 230 link_t *link = devices->next; 231 232 while (link != devices) { 233 dev = list_get_instance(link, device_t, link); 234 if (dev->handle == handle) { 235 fibril_mutex_unlock(&devices_mutex); 236 return dev; 211 static void add_to_functions_list(function_t *fun) 212 { 213 fibril_mutex_lock(&functions_mutex); 214 list_append(&fun->link, &functions); 215 fibril_mutex_unlock(&functions_mutex); 216 } 217 218 static void remove_from_functions_list(function_t *fun) 219 { 220 fibril_mutex_lock(&functions_mutex); 221 list_remove(&fun->link); 222 fibril_mutex_unlock(&functions_mutex); 223 } 224 225 static function_t *driver_get_function(link_t *functions, devman_handle_t handle) 226 { 227 function_t *fun = NULL; 228 printf("driver_get_function handle=%" PRIun "\n", handle); 229 230 fibril_mutex_lock(&functions_mutex); 231 link_t *link = functions->next; 232 233 while (link != functions) { 234 fun = list_get_instance(link, function_t, link); 235 printf(" - fun handle %" PRIun "\n", fun->handle); 236 if (fun->handle == handle) { 237 fibril_mutex_unlock(&functions_mutex); 238 return fun; 237 239 } 240 238 241 link = link->next; 239 242 } 240 243 241 fibril_mutex_unlock(& devices_mutex);244 fibril_mutex_unlock(&functions_mutex); 242 245 243 246 return NULL; … … 250 253 251 254 devman_handle_t dev_handle = IPC_GET_ARG1(*icall); 252 devman_handle_t parent_ dev_handle = IPC_GET_ARG2(*icall);255 devman_handle_t parent_fun_handle = IPC_GET_ARG2(*icall); 253 256 254 257 device_t *dev = create_device(); 255 258 dev->handle = dev_handle; 256 259 257 260 async_data_write_accept((void **) &dev_name, true, 0, 0, 0, 0); 258 261 dev->name = dev_name; 259 260 add_to_devices_list(dev); 261 dev->parent = driver_get_device(&devices, parent_dev_handle); 262 263 /* 264 * Currently not used, parent fun handle is stored in context 265 * of the connection to the parent device driver. 266 */ 267 (void) parent_fun_handle; 262 268 263 269 res = driver->driver_ops->add_device(dev); … … 268 274 printf("%s: failed to add a new device with handle = %" PRIun ".\n", 269 275 driver->name, dev_handle); 270 remove_from_devices_list(dev);271 276 delete_device(dev); 272 277 } … … 311 316 */ 312 317 devman_handle_t handle = IPC_GET_ARG2(*icall); 313 device_t *dev = driver_get_device(&devices, handle);314 315 if ( dev== NULL) {316 printf("%s: driver_connection_gen error - no devicewith handle"318 function_t *fun = driver_get_function(&functions, handle); 319 320 if (fun == NULL) { 321 printf("%s: driver_connection_gen error - no function with handle" 317 322 " %" PRIun " was found.\n", driver->name, handle); 318 323 async_answer_0(iid, ENOENT); … … 327 332 328 333 int ret = EOK; 329 /* open the device*/330 if ( dev->ops != NULL && dev->ops->open != NULL)331 ret = (* dev->ops->open)(dev);334 /* Open device function */ 335 if (fun->ops != NULL && fun->ops->open != NULL) 336 ret = (*fun->ops->open)(fun); 332 337 333 338 async_answer_0(iid, ret); … … 344 349 switch (method) { 345 350 case IPC_M_PHONE_HUNGUP: 346 /* close the device*/347 if ( dev->ops != NULL && dev->ops->close != NULL)348 (* dev->ops->close)(dev);351 /* Close device function */ 352 if (fun->ops != NULL && fun->ops->close != NULL) 353 (*fun->ops->close)(fun); 349 354 async_answer_0(callid, EOK); 350 355 return; … … 356 361 if (!is_valid_iface_idx(iface_idx)) { 357 362 remote_handler_t *default_handler = 358 device_get_default_handler(dev);363 function_get_default_handler(fun); 359 364 if (default_handler != NULL) { 360 (*default_handler)( dev, callid, &call);365 (*default_handler)(fun, callid, &call); 361 366 break; 362 367 } 368 363 369 /* 364 * This is not device's interface and the370 * Function has no such interface and 365 371 * default handler is not provided. 366 372 */ … … 372 378 } 373 379 374 /* calling one of the device's interfaces */380 /* calling one of the function's interfaces */ 375 381 376 382 /* Get the interface ops structure. */ 377 void *ops = device_get_ops(dev, iface_idx);383 void *ops = function_get_ops(fun, iface_idx); 378 384 if (ops == NULL) { 379 385 printf("%s: driver_connection_gen error - ", 380 386 driver->name); 381 printf(" devicewith handle %" PRIun " has no interface "387 printf("Function with handle %" PRIun " has no interface " 382 388 "with id %d.\n", handle, iface_idx); 383 389 async_answer_0(callid, ENOTSUP); … … 408 414 * receive parameters from the remote client and it will 409 415 * pass it to the corresponding local interface method 410 * associated with the deviceby its driver.416 * associated with the function by its driver. 411 417 */ 412 (*iface_method_ptr)( dev, ops, callid, &call);418 (*iface_method_ptr)(fun, ops, callid, &call); 413 419 break; 414 420 } … … 425 431 driver_connection_gen(iid, icall, false); 426 432 } 427 428 433 429 434 /** Function for handling connections to device driver. */ … … 456 461 device_t *create_device(void) 457 462 { 458 device_t *dev = malloc(sizeof(device_t));459 460 if (dev != NULL) {461 memset(dev, 0, sizeof(device_t));462 init_match_ids(&dev->match_ids);463 } 464 463 device_t *dev; 464 465 dev = malloc(sizeof(device_t)); 466 if (dev == NULL) 467 return NULL; 468 469 memset(dev, 0, sizeof(device_t)); 465 470 return dev; 466 471 } 467 472 473 /** Create new function structure. 474 * 475 * @return The device structure. 476 */ 477 function_t *create_function(void) 478 { 479 function_t *fun; 480 481 fun = malloc(sizeof(function_t)); 482 if (fun == NULL) 483 return NULL; 484 485 memset(fun, 0, sizeof(device_t)); 486 487 init_match_ids(&fun->match_ids); 488 link_initialize(&fun->link); 489 490 return fun; 491 } 492 468 493 /** Delete device structure. 469 494 * … … 472 497 void delete_device(device_t *dev) 473 498 { 474 clean_match_ids(&dev->match_ids);475 if (dev->name != NULL)476 free(dev->name);477 499 free(dev); 478 500 } 479 501 480 void *device_get_ops(device_t *dev, dev_inferface_idx_t idx) 502 /** Delete device structure. 503 * 504 * @param dev The device structure. 505 */ 506 void delete_function(function_t *fun) 507 { 508 clean_match_ids(&fun->match_ids); 509 if (fun->name != NULL) 510 free(fun->name); 511 free(fun); 512 } 513 514 void *function_get_ops(function_t *fun, dev_inferface_idx_t idx) 481 515 { 482 516 assert(is_valid_iface_idx(idx)); 483 if ( dev->ops == NULL)517 if (fun->ops == NULL) 484 518 return NULL; 485 return dev->ops->interfaces[idx];486 } 487 488 int child_device_register(device_t *child, device_t *parent)489 { 490 assert( child->name != NULL);519 return fun->ops->interfaces[idx]; 520 } 521 522 int register_function(function_t *fun, device_t *dev) 523 { 524 assert(fun->name != NULL); 491 525 492 526 int res; 493 527 494 add_to_devices_list(child); 495 res = devman_child_device_register(child->name, &child->match_ids, 496 parent->handle, &child->handle); 528 fun->dev = dev; 529 530 add_to_functions_list(fun); 531 res = devman_add_function(fun->name, fun->ftype, &fun->match_ids, 532 dev->handle, &fun->handle); 497 533 if (res != EOK) { 498 remove_from_ devices_list(child);534 remove_from_functions_list(fun); 499 535 return res; 500 536 } … … 511 547 * @return Error code. 512 548 */ 513 int child_device_register_wrapper(device_t *parent, const char *child_name,514 const char * child_match_id, int child_match_score)515 { 516 device_t *child= NULL;517 match_id_t *m atch_id = NULL;549 int register_function_wrapper(device_t *dev, const char *fun_name, 550 const char *match_id, int match_score) 551 { 552 function_t *fun = NULL; 553 match_id_t *m_id = NULL; 518 554 int rc; 519 555 520 child = create_device();521 if ( child== NULL) {556 fun = create_function(); 557 if (fun == NULL) { 522 558 rc = ENOMEM; 523 559 goto failure; 524 560 } 525 561 526 child->name = child_name; 527 528 match_id = create_match_id(); 529 if (match_id == NULL) { 562 fun->dev = dev; 563 fun->name = fun_name; 564 fun->ftype = fun_inner; 565 566 m_id = create_match_id(); 567 if (m_id == NULL) { 530 568 rc = ENOMEM; 531 569 goto failure; 532 570 } 533 571 534 m atch_id->id = child_match_id;535 m atch_id->score = child_match_score;536 add_match_id(& child->match_ids, match_id);537 538 rc = child_device_register(child, parent);572 m_id->id = match_id; 573 m_id->score = match_score; 574 add_match_id(&fun->match_ids, m_id); 575 576 rc = register_function(fun, dev); 539 577 if (rc != EOK) 540 578 goto failure; … … 543 581 544 582 failure: 545 if (m atch_id != NULL) {546 m atch_id->id = NULL;547 delete_match_id(m atch_id);548 } 549 550 if ( child!= NULL) {551 child->name = NULL;552 delete_ device(child);583 if (m_id != NULL) { 584 m_id->id = NULL; 585 delete_match_id(m_id); 586 } 587 588 if (fun != NULL) { 589 fun->name = NULL; 590 delete_function(fun); 553 591 } 554 592 … … 557 595 558 596 /** Get default handler for client requests */ 559 remote_handler_t * device_get_default_handler(device_t *dev)560 { 561 if ( dev->ops == NULL)597 remote_handler_t *function_get_default_handler(function_t *fun) 598 { 599 if (fun->ops == NULL) 562 600 return NULL; 563 return dev->ops->default_handler;564 } 565 566 int add_ device_to_class(device_t *dev, const char *class_name)567 { 568 return devman_add_device_to_class( dev->handle, class_name);601 return fun->ops->default_handler; 602 } 603 604 int add_function_to_class(function_t *fun, const char *class_name) 605 { 606 return devman_add_device_to_class(fun->handle, class_name); 569 607 } 570 608 -
uspace/lib/drv/generic/remote_char_dev.c
r1b367b4 r8b1e15ac 41 41 #define MAX_CHAR_RW_COUNT 256 42 42 43 static void remote_char_read( device_t *, void *, ipc_callid_t, ipc_call_t *);44 static void remote_char_write( device_t *, void *, ipc_callid_t, ipc_call_t *);43 static void remote_char_read(function_t *, void *, ipc_callid_t, ipc_call_t *); 44 static void remote_char_write(function_t *, void *, ipc_callid_t, ipc_call_t *); 45 45 46 46 /** Remote character interface operations. */ … … 67 67 * local interface to the remote client. 68 68 * 69 * @param dev The devicefrom which the data are read.69 * @param fun The function from which the data are read. 70 70 * @param ops The local ops structure. 71 71 */ 72 72 static void 73 remote_char_read( device_t *dev, void *ops, ipc_callid_t callid,73 remote_char_read(function_t *fun, void *ops, ipc_callid_t callid, 74 74 ipc_call_t *call) 75 75 { … … 94 94 95 95 char buf[MAX_CHAR_RW_COUNT]; 96 int ret = (*char_dev_ops->read)( dev, buf, len);96 int ret = (*char_dev_ops->read)(fun, buf, len); 97 97 98 98 if (ret < 0) { … … 114 114 * local interface to the remote client. 115 115 * 116 * @param dev The deviceto which the data are written.116 * @param fun The function to which the data are written. 117 117 * @param ops The local ops structure. 118 118 */ 119 119 static void 120 remote_char_write( device_t *dev, void *ops, ipc_callid_t callid,120 remote_char_write(function_t *fun, void *ops, ipc_callid_t callid, 121 121 ipc_call_t *call) 122 122 { … … 144 144 async_data_write_finalize(cid, buf, len); 145 145 146 int ret = (*char_dev_ops->write)( dev, buf, len);146 int ret = (*char_dev_ops->write)(fun, buf, len); 147 147 if (ret < 0) { 148 148 /* Some error occured. */ -
uspace/lib/drv/generic/remote_hw_res.c
r1b367b4 r8b1e15ac 39 39 #include "driver.h" 40 40 41 static void remote_hw_res_get_resource_list( device_t *, void *, ipc_callid_t,41 static void remote_hw_res_get_resource_list(function_t *, void *, ipc_callid_t, 42 42 ipc_call_t *); 43 static void remote_hw_res_enable_interrupt( device_t *, void *, ipc_callid_t,43 static void remote_hw_res_enable_interrupt(function_t *, void *, ipc_callid_t, 44 44 ipc_call_t *); 45 45 … … 55 55 }; 56 56 57 static void remote_hw_res_enable_interrupt( device_t *dev, void *ops,57 static void remote_hw_res_enable_interrupt(function_t *fun, void *ops, 58 58 ipc_callid_t callid, ipc_call_t *call) 59 59 { … … 62 62 if (hw_res_ops->enable_interrupt == NULL) 63 63 async_answer_0(callid, ENOTSUP); 64 else if (hw_res_ops->enable_interrupt( dev))64 else if (hw_res_ops->enable_interrupt(fun)) 65 65 async_answer_0(callid, EOK); 66 66 else … … 68 68 } 69 69 70 static void remote_hw_res_get_resource_list( device_t *dev, void *ops,70 static void remote_hw_res_get_resource_list(function_t *fun, void *ops, 71 71 ipc_callid_t callid, ipc_call_t *call) 72 72 { … … 78 78 } 79 79 80 hw_resource_list_t *hw_resources = hw_res_ops->get_resource_list( dev);80 hw_resource_list_t *hw_resources = hw_res_ops->get_resource_list(fun); 81 81 if (hw_resources == NULL){ 82 82 async_answer_0(callid, ENOENT); -
uspace/lib/drv/include/dev_iface.h
r1b367b4 r8b1e15ac 43 43 */ 44 44 45 struct device;45 struct function; 46 46 47 47 /* … … 49 49 * devices driver. 50 50 */ 51 typedef void remote_iface_func_t(struct device*, void *, ipc_callid_t,51 typedef void remote_iface_func_t(struct function *, void *, ipc_callid_t, 52 52 ipc_call_t *); 53 53 typedef remote_iface_func_t *remote_iface_func_ptr_t; 54 typedef void remote_handler_t(struct device*, ipc_callid_t, ipc_call_t *);54 typedef void remote_handler_t(struct function *, ipc_callid_t, ipc_call_t *); 55 55 56 56 typedef struct { -
uspace/lib/drv/include/driver.h
r1b367b4 r8b1e15ac 52 52 typedef struct device device_t; 53 53 54 struct function; 55 typedef struct function function_t; 56 54 57 /* 55 58 * Device class … … 62 65 * device. 63 66 */ 64 int (*open)( device_t *);67 int (*open)(function_t *); 65 68 66 69 /** … … 68 71 * the device. 69 72 */ 70 void (*close)( device_t *);73 void (*close)(function_t *); 71 74 72 75 /** The table of standard interfaces implemented by the device. */ … … 100 103 int parent_phone; 101 104 102 /** Parent device if handled by this driver, NULL otherwise */103 device_t *parent;104 105 /** Device name */ 105 106 const char *name; 106 /** List of device ids for device-to-driver matching */ 107 match_id_list_t match_ids; 107 108 108 /** Driver-specific data associated with this device */ 109 109 void *driver_data; 110 /** The implementation of operations provided by this device */ 110 111 /** Link in the list of devices handled by the driver */ 112 link_t link; 113 }; 114 115 /** Function structure */ 116 struct function { 117 /** Function indentifier (asigned by device manager) */ 118 devman_handle_t handle; 119 120 /** Device which this function belogs to */ 121 device_t *dev; 122 123 /** Function type */ 124 fun_type_t ftype; 125 /** Function name */ 126 const char *name; 127 /** List of device ids for driver matching */ 128 match_id_list_t match_ids; 129 /** Driver-specific data associated with this function */ 130 void *driver_data; 131 /** Implementation of operations provided by this function */ 111 132 device_ops_t *ops; 112 133 113 /** Link in the list of devices handled by the driver */134 /** Link in the list of functions handled by the driver */ 114 135 link_t link; 115 136 }; … … 142 163 extern device_t *create_device(void); 143 164 extern void delete_device(device_t *); 144 extern void *device_get_ops(device_t *, dev_inferface_idx_t); 145 146 extern int child_device_register(device_t *, device_t *); 147 extern int child_device_register_wrapper(device_t *, const char *, const char *, 165 extern function_t *create_function(void); 166 extern void delete_function(function_t *); 167 extern void *function_get_ops(function_t *, dev_inferface_idx_t); 168 169 extern int register_function(function_t *, device_t *); 170 extern int register_function_wrapper(device_t *, const char *, const char *, 148 171 int); 149 172 … … 184 207 extern int unregister_interrupt_handler(device_t *, int); 185 208 186 extern remote_handler_t * device_get_default_handler(device_t *);187 extern int add_ device_to_class(device_t *, const char *);209 extern remote_handler_t *function_get_default_handler(function_t *); 210 extern int add_function_to_class(function_t *fun, const char *class_name); 188 211 189 212 #endif -
uspace/lib/drv/include/ops/char_dev.h
r1b367b4 r8b1e15ac 39 39 40 40 typedef struct { 41 int (*read)( device_t *, char *, size_t);42 int (*write)( device_t *, char *, size_t);41 int (*read)(function_t *, char *, size_t); 42 int (*write)(function_t *, char *, size_t); 43 43 } char_dev_ops_t; 44 44 -
uspace/lib/drv/include/ops/hw_res.h
r1b367b4 r8b1e15ac 42 42 43 43 typedef struct { 44 hw_resource_list_t *(*get_resource_list)( device_t *);45 bool (*enable_interrupt)( device_t *);44 hw_resource_list_t *(*get_resource_list)(function_t *); 45 bool (*enable_interrupt)(function_t *); 46 46 } hw_res_ops_t; 47 47 -
uspace/srv/devman/devman.c
r1b367b4 r8b1e15ac 709 709 710 710 /** Create devmap path and name for the function. */ 711 staticvoid devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree)711 void devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree) 712 712 { 713 713 char *devmap_pathname = NULL; … … 777 777 case EOK: 778 778 dev->state = DEVICE_USABLE; 779 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!780 if (0) devmap_register_tree_function(NULL, tree);781 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!782 779 break; 783 780 case ENOENT: -
uspace/srv/devman/devman.h
r1b367b4 r8b1e15ac 363 363 /* Devmap devices */ 364 364 365 extern void devmap_register_tree_function(fun_node_t *, dev_tree_t *); 366 365 367 extern fun_node_t *find_devmap_tree_function(dev_tree_t *, devmap_handle_t); 366 368 extern fun_node_t *find_devmap_class_function(class_list_t *, devmap_handle_t); -
uspace/srv/devman/main.c
r1b367b4 r8b1e15ac 204 204 } 205 205 206 /** Handle child deviceregistration.206 /** Handle function registration. 207 207 * 208 208 * Child devices are registered by their parent's device driver. 209 209 */ 210 static void devman_add_child(ipc_callid_t callid, ipc_call_t *call) 211 { 212 devman_handle_t parent_handle = IPC_GET_ARG1(*call); 213 sysarg_t match_count = IPC_GET_ARG2(*call); 210 static void devman_add_function(ipc_callid_t callid, ipc_call_t *call) 211 { 212 fun_type_t ftype = (fun_type_t) IPC_GET_ARG1(*call); 213 devman_handle_t dev_handle = IPC_GET_ARG2(*call); 214 sysarg_t match_count = IPC_GET_ARG3(*call); 214 215 dev_tree_t *tree = &device_tree; 215 216 216 217 fibril_rwlock_write_lock(&tree->rwlock); 217 dev_node_t *pdev = find_dev_node_no_lock(&device_tree, parent_handle); 218 219 dev_node_t *dev = NULL; 220 dev_node_t *pdev = find_dev_node_no_lock(&device_tree, dev_handle); 218 221 219 222 if (pdev == NULL) { 220 223 fibril_rwlock_write_unlock(&tree->rwlock); 221 224 async_answer_0(callid, ENOENT); 225 return; 226 } 227 228 if (ftype != fun_inner && ftype != fun_exposed) { 229 /* Unknown function type */ 230 printf(NAME ": Error, unknown function type provided by driver!\n"); 231 232 fibril_rwlock_write_unlock(&tree->rwlock); 233 async_answer_0(callid, EINVAL); 222 234 return; 223 235 } … … 239 251 } 240 252 241 dev_node_t *dev;242 243 dev = create_dev_node();244 if (dev == NULL) {245 fibril_rwlock_write_unlock(&tree->rwlock);246 delete_fun_node(fun);247 async_answer_0(callid, ENOMEM);248 return;249 } 250 251 insert_dev_node(tree, dev, fun);253 if (ftype == fun_inner) { 254 dev = create_dev_node(); 255 if (dev == NULL) { 256 fibril_rwlock_write_unlock(&tree->rwlock); 257 delete_fun_node(fun); 258 async_answer_0(callid, ENOMEM); 259 return; 260 } 261 262 insert_dev_node(tree, dev, fun); 263 } 252 264 253 265 fibril_rwlock_write_unlock(&tree->rwlock); 254 266 255 printf(NAME ": devman_add_ child%s\n", fun->pathname);267 printf(NAME ": devman_add_function %s\n", fun->pathname); 256 268 257 269 devman_receive_match_ids(match_count, &fun->match_ids); 258 270 259 /* 260 * Try to find a suitable driver and assign it to the device. We do 261 * not want to block the current fibril that is used for processing 262 * incoming calls: we will launch a separate fibril to handle the 263 * driver assigning. That is because assign_driver can actually include 264 * task spawning which could take some time. 265 */ 266 fid_t assign_fibril = fibril_create(assign_driver_fibril, dev); 267 if (assign_fibril == 0) { 271 if (ftype == fun_inner) { 272 assert(dev != NULL); 268 273 /* 269 * Fallback in case we are out of memory. 270 * Probably not needed as we will die soon anyway ;-). 274 * Try to find a suitable driver and assign it to the device. We do 275 * not want to block the current fibril that is used for processing 276 * incoming calls: we will launch a separate fibril to handle the 277 * driver assigning. That is because assign_driver can actually include 278 * task spawning which could take some time. 271 279 */ 272 (void) assign_driver_fibril(fun); 280 fid_t assign_fibril = fibril_create(assign_driver_fibril, dev); 281 if (assign_fibril == 0) { 282 /* 283 * Fallback in case we are out of memory. 284 * Probably not needed as we will die soon anyway ;-). 285 */ 286 (void) assign_driver_fibril(fun); 287 } else { 288 fibril_add_ready(assign_fibril); 289 } 273 290 } else { 274 fibril_add_ready(assign_fibril);275 } 276 291 devmap_register_tree_function(fun, tree); 292 } 293 277 294 /* Return device handle to parent's driver. */ 278 295 async_answer_1(callid, EOK, fun->handle); … … 384 401 cont = false; 385 402 continue; 386 case DEVMAN_ADD_ CHILD_DEVICE:387 devman_add_ child(callid, &call);403 case DEVMAN_ADD_FUNCTION: 404 devman_add_function(callid, &call); 388 405 break; 389 406 case DEVMAN_ADD_DEVICE_TO_CLASS: … … 409 426 } 410 427 411 fun_node_t * 428 fun_node_t *fun = find_fun_node_by_path(&device_tree, pathname); 412 429 413 430 free(pathname); … … 417 434 return; 418 435 } 419 436 420 437 async_answer_1(iid, EOK, fun->handle); 421 438 } … … 450 467 { 451 468 devman_handle_t handle = IPC_GET_ARG2(*icall); 452 453 fun_node_t *fun = find_fun_node(&device_tree, handle); 454 if (fun == NULL) { 455 printf(NAME ": devman_forward error - no device function with " 469 devman_handle_t fwd_h; 470 fun_node_t *fun = NULL; 471 dev_node_t *dev = NULL; 472 473 fun = find_fun_node(&device_tree, handle); 474 if (fun == NULL) 475 dev = find_dev_node(&device_tree, handle); 476 else 477 dev = fun->dev; 478 479 if (fun == NULL && dev == NULL) { 480 printf(NAME ": devman_forward error - no device or function with " 456 481 "handle %" PRIun " was found.\n", handle); 457 482 async_answer_0(iid, ENOENT); 458 483 return; 459 484 } 485 486 if (fun == NULL && !drv_to_parent) { 487 printf(NAME ": devman_forward error - cannot connect to " 488 "handle %d, refers to a device.\n", handle); 489 async_answer_0(iid, ENOENT); 490 return; 491 } 460 492 461 493 driver_t *driver = NULL; 462 494 463 495 if (drv_to_parent) { 464 if (fun->dev->pfun != NULL) 465 driver = fun->dev->pfun->dev->drv; 466 } else if (fun->dev->state == DEVICE_USABLE) { 467 driver = fun->dev->drv; 496 /* Connect to parent function of a device (or device function). */ 497 if (dev->pfun->dev != NULL) 498 driver = dev->pfun->dev->drv; 499 fwd_h = dev->pfun->handle; 500 } else if (dev->state == DEVICE_USABLE) { 501 /* Connect to the specified function */ 502 driver = dev->drv; 468 503 assert(driver != NULL); 504 505 fwd_h = handle; 469 506 } 470 507 … … 490 527 } 491 528 492 printf(NAME ": devman_forward: forward connection to function %s to " 493 "driver %s.\n", fun->pathname, driver->name); 494 async_forward_fast(iid, driver->phone, method, fun->handle, 0, IPC_FF_NONE); 529 if (fun != NULL) { 530 printf(NAME ": devman_forward: forward connection to function %s to " 531 "driver %s.\n", fun->pathname, driver->name); 532 } else { 533 printf(NAME ": devman_forward: forward connection to device %s to " 534 "driver %s.\n", dev->pfun->pathname, driver->name); 535 } 536 537 async_forward_fast(iid, driver->phone, method, fwd_h, 0, IPC_FF_NONE); 495 538 } 496 539
Note:
See TracChangeset
for help on using the changeset viewer.