Changes in / [0a3fbc7:f2d2c604] in mainline
- Files:
-
- 2 added
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/pack.py
r0a3fbc7 rf2d2c604 113 113 114 114 comp_in = file(component, "rb") 115 comp_data = comp_in.read() ;115 comp_data = comp_in.read() 116 116 comp_in.close() 117 117 -
uspace/drv/ns8250/ns8250.c
r0a3fbc7 rf2d2c604 123 123 static void delete_ns8250_dev_data(ns8250_dev_data_t *data) 124 124 { 125 if ( NULL != data)125 if (data != NULL) 126 126 free(data); 127 127 } … … 251 251 static void ns8250_dev_cleanup(device_t *dev) 252 252 { 253 if ( NULL != dev->driver_data) {253 if (dev->driver_data != NULL) { 254 254 delete_ns8250_dev_data((ns8250_dev_data_t*) dev->driver_data); 255 255 dev->driver_data = NULL; … … 332 332 /* Allocate driver data for the device. */ 333 333 ns8250_dev_data_t *data = create_ns8250_dev_data(); 334 if ( NULL == data)334 if (data == NULL) 335 335 return ENOMEM; 336 336 dev->driver_data = data; … … 436 436 /* Enable interrupt globally. */ 437 437 res = interrupt_enable(data->irq); 438 if ( EOK != res)438 if (res != EOK) 439 439 return res; 440 440 … … 480 480 uint8_t div_low, div_high; 481 481 482 if ( 50 > baud_rate || 0 != MAX_BAUD_RATE % baud_rate) {482 if (baud_rate < 50 || MAX_BAUD_RATE % baud_rate != 0) { 483 483 printf(NAME ": error - somebody tried to set invalid baud rate " 484 484 "%d\n", baud_rate); … … 534 534 * @param stop_bits The number of stop bits used (one or two). 535 535 */ 536 static void 537 ns8250_port_get_com_props(ioport8_t *port, unsigned int *parity, 536 static void ns8250_port_get_com_props(ioport8_t *port, unsigned int *parity, 538 537 unsigned int *word_length, unsigned int *stop_bits) 539 538 { … … 572 571 * is invalid. 573 572 */ 574 static int 575 ns8250_port_set_com_props(ioport8_t *port, unsigned int parity, 573 static int ns8250_port_set_com_props(ioport8_t *port, unsigned int parity, 576 574 unsigned int word_length, unsigned int stop_bits) 577 575 { … … 691 689 * @param dev The serial port device. 692 690 */ 693 static inline void 694 ns8250_interrupt_handler(device_t *dev, ipc_callid_t iid,ipc_call_t *icall)691 static inline void ns8250_interrupt_handler(device_t *dev, ipc_callid_t iid, 692 ipc_call_t *icall) 695 693 { 696 694 ns8250_read_from_device(dev); … … 726 724 * @param dev The serial port device. 727 725 */ 728 static int ns8250_add_device(device_t *dev) 726 static int ns8250_add_device(device_t *dev) 729 727 { 730 728 printf(NAME ": ns8250_add_device %s (handle = %d)\n", … … 732 730 733 731 int res = ns8250_dev_initialize(dev); 734 if ( EOK != res)732 if (res != EOK) 735 733 return res; 736 734 … … 750 748 751 749 /* Register interrupt handler. */ 752 if ( EOK != ns8250_register_interrupt_handler(dev)) {750 if (ns8250_register_interrupt_handler(dev) != EOK) { 753 751 printf(NAME ": failed to register interrupt handler.\n"); 754 752 ns8250_dev_cleanup(dev); … … 758 756 /* Enable interrupt. */ 759 757 res = ns8250_interrupt_enable(dev); 760 if ( EOK != res) {758 if (res != EOK) { 761 759 printf(NAME ": failed to enable the interrupt. Error code = " 762 760 "%d.\n", res); … … 859 857 * @param stop_bits The number of stop bits to be used. 860 858 */ 861 static int 862 ns8250_set_props(device_t *dev, unsigned int baud_rate, unsigned int parity, 863 unsigned int word_length, unsigned int stop_bits) 859 static int ns8250_set_props(device_t *dev, unsigned int baud_rate, 860 unsigned int parity, unsigned int word_length, unsigned int stop_bits) 864 861 { 865 862 printf(NAME ": ns8250_set_props: baud rate %d, parity 0x%x, word " … … 874 871 ns8250_port_interrupts_disable(port); 875 872 ret = ns8250_port_set_baud_rate(port, baud_rate); 876 if ( EOK == ret)873 if (ret == EOK) 877 874 ret = ns8250_port_set_com_props(port, parity, word_length, stop_bits); 878 875 ns8250_port_interrupts_enable(port); … … 887 884 * Configure the parameters of the serial communication. 888 885 */ 889 static void 890 ns8250_default_handler(device_t *dev, ipc_callid_t callid,ipc_call_t *call)886 static void ns8250_default_handler(device_t *dev, ipc_callid_t callid, 887 ipc_call_t *call) 891 888 { 892 889 ipcarg_t method = IPC_GET_METHOD(*call); -
uspace/drv/pciintel/pci.c
r0a3fbc7 rf2d2c604 65 65 pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data; 66 66 67 if ( NULL == dev_data)67 if (dev_data == NULL) 68 68 return NULL; 69 69 return &dev_data->hw_resources; … … 109 109 110 110 bus_data = (pci_bus_data_t *) malloc(sizeof(pci_bus_data_t)); 111 if ( NULL != bus_data) {111 if (bus_data != NULL) { 112 112 memset(bus_data, 0, sizeof(pci_bus_data_t)); 113 113 fibril_mutex_initialize(&bus_data->conf_mutex); 114 114 } 115 115 116 return bus_data; 116 117 } … … 123 124 static void pci_conf_read(device_t *dev, int reg, uint8_t *buf, size_t len) 124 125 { 125 assert( NULL != dev->parent);126 assert(dev->parent != NULL); 126 127 127 128 pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data; … … 153 154 static void pci_conf_write(device_t *dev, int reg, uint8_t *buf, size_t len) 154 155 { 155 assert( NULL != dev->parent);156 assert(dev->parent != NULL); 156 157 157 158 pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data; … … 224 225 225 226 match_id = create_match_id(); 226 if ( NULL != match_id) {227 if (match_id != NULL) { 227 228 asprintf(&match_id_str, "pci/ven=%04x&dev=%04x", 228 229 dev_data->vendor_id, dev_data->device_id); … … 230 231 match_id->score = 90; 231 232 add_match_id(&dev->match_ids, match_id); 232 } 233 } 234 233 235 /* TODO add more ids (with subsys ids, using class id etc.) */ 234 236 } … … 242 244 size_t count = hw_res_list->count; 243 245 244 assert( NULL != hw_resources);246 assert(hw_resources != NULL); 245 247 assert(count < PCI_MAX_HW_RES); 246 248 … … 275 277 bool io; 276 278 /* 64-bit wide address */ 277 bool w64;279 bool addrw64; 278 280 279 281 /* Size of the io or memory range specified by the BAR */ … … 287 289 io = (bool) (val & 1); 288 290 if (io) { 289 w64 = false;291 addrw64 = false; 290 292 } else { 291 293 switch ((val >> 1) & 3) { 292 294 case 0: 293 w64 = false;295 addrw64 = false; 294 296 break; 295 297 case 2: 296 w64 = true;298 addrw64 = true; 297 299 break; 298 300 default: … … 312 314 range_size = pci_bar_mask_to_size(mask); 313 315 314 if ( w64) {316 if (addrw64) { 315 317 range_addr = ((uint64_t)pci_conf_read_32(dev, addr + 4) << 32) | 316 318 (val & 0xfffffff0); … … 319 321 } 320 322 321 if ( 0 != range_addr) {323 if (range_addr != 0) { 322 324 printf(NAME ": device %s : ", dev->name); 323 325 printf("address = %x", range_addr); … … 327 329 pci_add_range(dev, range_addr, range_size, io); 328 330 329 if ( w64)331 if (addrw64) 330 332 return addr + 8; 331 333 … … 354 356 { 355 357 uint8_t irq = pci_conf_read_8(dev, PCI_BRIDGE_INT_LINE); 356 if ( 0xff != irq)358 if (irq != 0xff) 357 359 pci_add_interrupt(dev, irq); 358 360 } … … 415 417 create_pci_match_ids(dev); 416 418 417 if ( EOK != child_device_register(dev, parent)) {419 if (child_device_register(dev, parent) != EOK) { 418 420 pci_clean_resource_list(dev); 419 421 clean_match_ids(&dev->match_ids); … … 424 426 425 427 if (header_type == PCI_HEADER_TYPE_BRIDGE || 426 header_type == PCI_HEADER_TYPE_CARDBUS 428 header_type == PCI_HEADER_TYPE_CARDBUS) { 427 429 child_bus = pci_conf_read_8(dev, 428 430 PCI_BRIDGE_SEC_BUS_NUM); 429 431 printf(NAME ": device is pci-to-pci bridge, " 430 432 "secondary bus number = %d.\n", bus_num); 431 if (child_bus > bus_num)433 if (child_bus > bus_num) 432 434 pci_bus_scan(parent, child_bus); 433 435 } … … 453 455 454 456 pci_bus_data_t *bus_data = create_pci_bus_data(); 455 if ( NULL == bus_data) {457 if (bus_data == NULL) { 456 458 printf(NAME ": pci_add_device allocation failed.\n"); 457 459 return ENOMEM; … … 513 515 } 514 516 517 pci_dev_data_t *create_pci_dev_data(void) 518 { 519 pci_dev_data_t *res = (pci_dev_data_t *) malloc(sizeof(pci_dev_data_t)); 520 521 if (res != NULL) 522 memset(res, 0, sizeof(pci_dev_data_t)); 523 return res; 524 } 525 526 void init_pci_dev_data(pci_dev_data_t *dev_data, int bus, int dev, int fn) 527 { 528 dev_data->bus = bus; 529 dev_data->dev = dev; 530 dev_data->fn = fn; 531 } 532 533 void delete_pci_dev_data(pci_dev_data_t *dev_data) 534 { 535 if (dev_data != NULL) { 536 clean_hw_resource_list(&dev_data->hw_resources); 537 free(dev_data); 538 } 539 } 540 541 void create_pci_dev_name(device_t *dev) 542 { 543 pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data; 544 char *name = NULL; 545 546 asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev, 547 dev_data->fn); 548 dev->name = name; 549 } 550 551 bool pci_alloc_resource_list(device_t *dev) 552 { 553 pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data; 554 555 dev_data->hw_resources.resources = 556 (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t)); 557 return dev_data->hw_resources.resources != NULL; 558 } 559 560 void pci_clean_resource_list(device_t *dev) 561 { 562 pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data; 563 564 if (dev_data->hw_resources.resources != NULL) { 565 free(dev_data->hw_resources.resources); 566 dev_data->hw_resources.resources = NULL; 567 } 568 } 569 570 /** Read the base address registers (BARs) of the device and adds the addresses 571 * to its hw resource list. 572 * 573 * @param dev the pci device. 574 */ 575 void pci_read_bars(device_t *dev) 576 { 577 /* 578 * Position of the BAR in the PCI configuration address space of the 579 * device. 580 */ 581 int addr = PCI_BASE_ADDR_0; 582 583 while (addr <= PCI_BASE_ADDR_5) 584 addr = pci_read_bar(dev, addr); 585 } 586 587 size_t pci_bar_mask_to_size(uint32_t mask) 588 { 589 return ((mask & 0xfffffff0) ^ 0xffffffff) + 1; 590 } 591 515 592 int main(int argc, char *argv[]) 516 593 { -
uspace/drv/pciintel/pci.h
r0a3fbc7 rf2d2c604 69 69 extern void pci_bus_scan(device_t *, int); 70 70 71 static inline pci_dev_data_t *create_pci_dev_data(void) 72 { 73 pci_dev_data_t *res = (pci_dev_data_t *) malloc(sizeof(pci_dev_data_t)); 74 75 if (NULL != res) 76 memset(res, 0, sizeof(pci_dev_data_t)); 77 return res; 78 } 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 *); 79 75 80 static inline void 81 init_pci_dev_data(pci_dev_data_t *d, int bus, int dev, int fn) 82 { 83 d->bus = bus; 84 d->dev = dev; 85 d->fn = fn; 86 } 76 extern bool pci_alloc_resource_list(device_t *); 77 extern void pci_clean_resource_list(device_t *); 87 78 88 static inline void delete_pci_dev_data(pci_dev_data_t *d) 89 { 90 if (NULL != d) { 91 clean_hw_resource_list(&d->hw_resources); 92 free(d); 93 } 94 } 95 96 static inline void create_pci_dev_name(device_t *dev) 97 { 98 pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data; 99 char *name = NULL; 100 101 asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev, 102 dev_data->fn); 103 dev->name = name; 104 } 105 106 static inline bool pci_alloc_resource_list(device_t *dev) 107 { 108 pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data; 109 110 dev_data->hw_resources.resources = 111 (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t)); 112 return dev_data->hw_resources.resources != NULL; 113 } 114 115 static inline void pci_clean_resource_list(device_t *dev) 116 { 117 pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data; 118 119 if (NULL != dev_data->hw_resources.resources) { 120 free(dev_data->hw_resources.resources); 121 dev_data->hw_resources.resources = NULL; 122 } 123 } 124 125 /** Read the base address registers (BARs) of the device and adds the addresses 126 * to its hw resource list. 127 * 128 * @param dev the pci device. 129 */ 130 static inline void pci_read_bars(device_t *dev) 131 { 132 /* 133 * Position of the BAR in the PCI configuration address space of the 134 * device. 135 */ 136 int addr = PCI_BASE_ADDR_0; 137 138 while (addr <= PCI_BASE_ADDR_5) 139 addr = pci_read_bar(dev, addr); 140 } 141 142 static inline size_t pci_bar_mask_to_size(uint32_t mask) 143 { 144 return ((mask & 0xfffffff0) ^ 0xffffffff) + 1; 145 } 79 extern void pci_read_bars(device_t *); 80 extern size_t pci_bar_mask_to_size(uint32_t); 146 81 147 82 #endif -
uspace/lib/c/arch/abs32le/include/fibril.h
r0a3fbc7 rf2d2c604 44 44 (ctx)->pc = (uintptr_t) (_pc); \ 45 45 (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; \ 46 (ctx)->fp = 0; \ 46 47 (ctx)->tls = ((uintptr_t) (ptls)) + sizeof(tcb_t); \ 47 48 } while (0) … … 53 54 typedef struct { 54 55 uintptr_t sp; 56 uintptr_t fp; 55 57 uintptr_t pc; 56 58 uintptr_t tls; 57 59 } context_t; 60 61 static inline uintptr_t context_get_fp(context_t *ctx) 62 { 63 /* On real hardware, this function returns the frame pointer. */ 64 return ctx->fp; 65 } 58 66 59 67 #endif -
uspace/lib/c/arch/amd64/include/fibril.h
r0a3fbc7 rf2d2c604 56 56 */ 57 57 typedef struct { 58 uint64_t sp; 59 uint64_t pc; 60 61 uint64_t rbx; 62 uint64_t rbp; 58 uint64_t sp; 59 uint64_t pc; 63 60 64 uint64_t r12; 65 uint64_t r13; 66 uint64_t r14; 67 uint64_t r15; 61 uint64_t rbx; 62 uint64_t rbp; 68 63 69 uint64_t tls; 64 uint64_t r12; 65 uint64_t r13; 66 uint64_t r14; 67 uint64_t r15; 68 69 uint64_t tls; 70 70 } context_t; 71 72 static inline uintptr_t context_get_fp(context_t *ctx) 73 { 74 return ctx->rbp; 75 } 71 76 72 77 #endif -
uspace/lib/c/arch/arm32/include/fibril.h
r0a3fbc7 rf2d2c604 86 86 } context_t; 87 87 88 static inline uintptr_t context_get_fp(context_t *ctx) 89 { 90 return ctx->fp; 91 } 92 88 93 89 94 #endif -
uspace/lib/c/arch/ia32/include/fibril.h
r0a3fbc7 rf2d2c604 67 67 } context_t; 68 68 69 static inline uintptr_t context_get_fp(context_t *ctx) 70 { 71 return ctx->ebp; 72 } 73 69 74 #endif 70 75 -
uspace/lib/c/arch/ia64/include/fibril.h
r0a3fbc7 rf2d2c604 130 130 } context_t; 131 131 132 static inline uintptr_t context_get_fp(context_t *ctx) 133 { 134 return 0; /* FIXME */ 135 } 136 132 137 #endif 133 138 -
uspace/lib/c/arch/mips32/include/fibril.h
r0a3fbc7 rf2d2c604 85 85 } context_t; 86 86 87 static inline uintptr_t context_get_fp(context_t *ctx) 88 { 89 return ctx->sp; 90 } 91 87 92 #endif 88 93 -
uspace/lib/c/arch/ppc32/include/fibril.h
r0a3fbc7 rf2d2c604 78 78 } __attribute__ ((packed)) context_t; 79 79 80 static inline uintptr_t context_get_fp(context_t *ctx) 81 { 82 return ctx->sp; 83 } 84 80 85 #endif 81 86 -
uspace/lib/c/arch/sparc64/include/fibril.h
r0a3fbc7 rf2d2c604 77 77 } context_t; 78 78 79 static inline uintptr_t context_get_fp(context_t *ctx) 80 { 81 return ctx->sp + STACK_BIAS; 82 } 83 79 84 #endif 80 85 -
uspace/lib/c/generic/fibril.c
r0a3fbc7 rf2d2c604 275 275 fibril->func = func; 276 276 fibril->arg = arg; 277 278 fibril->waits_for = NULL; 277 279 278 280 context_save(&fibril->ctx); -
uspace/lib/c/generic/fibril_synch.c
r0a3fbc7 rf2d2c604 42 42 #include <errno.h> 43 43 #include <assert.h> 44 #include <stacktrace.h> 45 #include <stdlib.h> 44 46 45 47 static void optimize_execution_power(void) … … 56 58 } 57 59 60 static bool check_for_deadlock(fibril_owner_info_t *oi) 61 { 62 while (oi && oi->owned_by) { 63 if (oi->owned_by == (fibril_t *) fibril_get_id()) 64 return true; 65 oi = oi->owned_by->waits_for; 66 } 67 68 return false; 69 } 70 71 static void print_deadlock(fibril_owner_info_t *oi) 72 { 73 fibril_t *f = (fibril_t *) fibril_get_id(); 74 75 printf("Deadlock detected.\n"); 76 stacktrace_print(); 77 78 printf("Fibril %p waits for primitive %p.\n", f, oi); 79 80 while (oi && oi->owned_by) { 81 printf("Primitive %p is owned by fibril %p.\n", 82 oi, oi->owned_by); 83 if (oi->owned_by == f) 84 break; 85 stacktrace_print_fp_pc(context_get_fp(&oi->owned_by->ctx), 86 oi->owned_by->ctx.pc); 87 printf("Fibril %p waits for primitive %p.\n", 88 oi->owned_by, oi->owned_by->waits_for); 89 oi = oi->owned_by->waits_for; 90 } 91 92 abort(); 93 } 94 58 95 void fibril_mutex_initialize(fibril_mutex_t *fm) 59 96 { 97 fm->oi.owned_by = NULL; 60 98 fm->counter = 1; 61 99 list_initialize(&fm->waiters); … … 64 102 void fibril_mutex_lock(fibril_mutex_t *fm) 65 103 { 104 fibril_t *f = (fibril_t *) fibril_get_id(); 105 66 106 futex_down(&async_futex); 67 107 if (fm->counter-- <= 0) { … … 73 113 link_initialize(&wdata.wu_event.link); 74 114 list_append(&wdata.wu_event.link, &fm->waiters); 115 116 if (check_for_deadlock(&fm->oi)) 117 print_deadlock(&fm->oi); 118 f->waits_for = &fm->oi; 119 75 120 fibril_switch(FIBRIL_TO_MANAGER); 76 121 } else { 122 fm->oi.owned_by = f; 77 123 futex_up(&async_futex); 78 124 } … … 86 132 if (fm->counter > 0) { 87 133 fm->counter--; 134 fm->oi.owned_by = (fibril_t *) fibril_get_id(); 88 135 locked = true; 89 136 } … … 99 146 link_t *tmp; 100 147 awaiter_t *wdp; 148 fibril_t *f; 101 149 102 150 assert(!list_empty(&fm->waiters)); … … 105 153 wdp->active = true; 106 154 wdp->wu_event.inlist = false; 155 156 f = (fibril_t *) wdp->fid; 157 fm->oi.owned_by = f; 158 f->waits_for = NULL; 159 107 160 list_remove(&wdp->wu_event.link); 108 161 fibril_add_ready(wdp->fid); 109 162 optimize_execution_power(); 163 } else { 164 fm->oi.owned_by = NULL; 110 165 } 111 166 } … … 120 175 void fibril_rwlock_initialize(fibril_rwlock_t *frw) 121 176 { 177 frw->oi.owned_by = NULL; 122 178 frw->writers = 0; 123 179 frw->readers = 0; -
uspace/lib/c/include/fibril.h
r0a3fbc7 rf2d2c604 48 48 #define FIBRIL_WRITER 2 49 49 50 struct fibril; 51 52 typedef struct { 53 struct fibril *owned_by; 54 } fibril_owner_info_t; 55 50 56 typedef enum { 51 57 FIBRIL_PREEMPT, … … 68 74 int retval; 69 75 int flags; 76 77 fibril_owner_info_t *waits_for; 70 78 } fibril_t; 71 79 -
uspace/lib/c/include/fibril_synch.h
r0a3fbc7 rf2d2c604 43 43 44 44 typedef struct { 45 fibril_owner_info_t oi; /* Keep this the first thing. */ 45 46 int counter; 46 47 link_t waiters; … … 49 50 #define FIBRIL_MUTEX_INITIALIZER(name) \ 50 51 { \ 52 .oi = { \ 53 .owned_by = NULL \ 54 }, \ 51 55 .counter = 1, \ 52 56 .waiters = { \ … … 60 64 61 65 typedef struct { 66 fibril_owner_info_t oi; /* Keep this the first thing. */ 62 67 unsigned writers; 63 68 unsigned readers; … … 67 72 #define FIBRIL_RWLOCK_INITIALIZER(name) \ 68 73 { \ 74 .oi = { \ 75 .owned_by = NULL \ 76 }, \ 69 77 .readers = 0, \ 70 78 .writers = 0, \ -
uspace/srv/devman/devman.c
r0a3fbc7 rf2d2c604 76 76 .remove_callback = devices_remove_callback 77 77 }; 78 79 /** 80 * Initialize the list of device driver's. 81 * 82 * @param drv_list the list of device driver's. 83 * 84 */ 85 void init_driver_list(driver_list_t *drv_list) 86 { 87 assert(drv_list != NULL); 88 89 list_initialize(&drv_list->drivers); 90 fibril_mutex_initialize(&drv_list->drivers_mutex); 91 } 78 92 79 93 /** Allocate and initialize a new driver structure. … … 548 562 } 549 563 564 /** Initialize device driver structure. 565 * 566 * @param drv The device driver structure. 567 */ 568 void init_driver(driver_t *drv) 569 { 570 assert(drv != NULL); 571 572 memset(drv, 0, sizeof(driver_t)); 573 list_initialize(&drv->match_ids.ids); 574 list_initialize(&drv->devices); 575 fibril_mutex_initialize(&drv->driver_mutex); 576 } 577 578 /** Device driver structure clean-up. 579 * 580 * @param drv The device driver structure. 581 */ 582 void clean_driver(driver_t *drv) 583 { 584 assert(drv != NULL); 585 586 free_not_null(drv->name); 587 free_not_null(drv->binary_path); 588 589 clean_match_ids(&drv->match_ids); 590 591 init_driver(drv); 592 } 593 594 /** Delete device driver structure. 595 * 596 * @param drv The device driver structure. 597 */ 598 void delete_driver(driver_t *drv) 599 { 600 assert(drv != NULL); 601 602 clean_driver(drv); 603 free(drv); 604 } 550 605 551 606 /** Create devmap path and name for the device. */ … … 685 740 } 686 741 742 /* Device nodes */ 743 744 /** Create a new device node. 745 * 746 * @return A device node structure. 747 */ 748 node_t *create_dev_node(void) 749 { 750 node_t *res = malloc(sizeof(node_t)); 751 752 if (res != NULL) { 753 memset(res, 0, sizeof(node_t)); 754 list_initialize(&res->children); 755 list_initialize(&res->match_ids.ids); 756 list_initialize(&res->classes); 757 } 758 759 return res; 760 } 761 762 /** Delete a device node. 763 * 764 * @param node The device node structure. 765 */ 766 void delete_dev_node(node_t *node) 767 { 768 assert(list_empty(&node->children)); 769 assert(node->parent == NULL); 770 assert(node->drv == NULL); 771 772 clean_match_ids(&node->match_ids); 773 free_not_null(node->name); 774 free_not_null(node->pathname); 775 free(node); 776 } 777 778 /** Find the device node structure of the device witch has the specified handle. 779 * 780 * Device tree's rwlock should be held at least for reading. 781 * 782 * @param tree The device tree where we look for the device node. 783 * @param handle The handle of the device. 784 * @return The device node. 785 */ 786 node_t *find_dev_node_no_lock(dev_tree_t *tree, device_handle_t handle) 787 { 788 unsigned long key = handle; 789 link_t *link = hash_table_find(&tree->devman_devices, &key); 790 return hash_table_get_instance(link, node_t, devman_link); 791 } 792 793 /** Find the device node structure of the device witch has the specified handle. 794 * 795 * @param tree The device tree where we look for the device node. 796 * @param handle The handle of the device. 797 * @return The device node. 798 */ 799 node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle) 800 { 801 node_t *node = NULL; 802 803 fibril_rwlock_read_lock(&tree->rwlock); 804 node = find_dev_node_no_lock(tree, handle); 805 fibril_rwlock_read_unlock(&tree->rwlock); 806 807 return node; 808 } 809 810 687 811 /** Create and set device's full path in device tree. 688 812 * … … 825 949 return NULL; 826 950 } 951 952 /* Device classes */ 953 954 /** Create device class. 955 * 956 * @return Device class. 957 */ 958 dev_class_t *create_dev_class(void) 959 { 960 dev_class_t *cl; 961 962 cl = (dev_class_t *) malloc(sizeof(dev_class_t)); 963 if (cl != NULL) { 964 memset(cl, 0, sizeof(dev_class_t)); 965 list_initialize(&cl->devices); 966 fibril_mutex_initialize(&cl->mutex); 967 } 968 969 return cl; 970 } 971 972 /** Create device class info. 973 * 974 * @return Device class info. 975 */ 976 dev_class_info_t *create_dev_class_info(void) 977 { 978 dev_class_info_t *info; 979 980 info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t)); 981 if (info != NULL) 982 memset(info, 0, sizeof(dev_class_info_t)); 983 984 return info; 985 } 986 987 size_t get_new_class_dev_idx(dev_class_t *cl) 988 { 989 size_t dev_idx; 990 991 fibril_mutex_lock(&cl->mutex); 992 dev_idx = ++cl->curr_dev_idx; 993 fibril_mutex_unlock(&cl->mutex); 994 995 return dev_idx; 996 } 997 827 998 828 999 /** Create unique device name within the class. … … 921 1092 } 922 1093 1094 void add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl) 1095 { 1096 list_append(&cl->link, &class_list->classes); 1097 } 1098 923 1099 void init_class_list(class_list_t *class_list) 924 1100 { … … 930 1106 931 1107 932 /* devmap devices */1108 /* Devmap devices */ 933 1109 934 1110 node_t *find_devmap_tree_device(dev_tree_t *tree, dev_handle_t devmap_handle) … … 967 1143 } 968 1144 1145 void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli) 1146 { 1147 unsigned long key = (unsigned long) cli->devmap_handle; 1148 1149 fibril_rwlock_write_lock(&class_list->rwlock); 1150 hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link); 1151 fibril_rwlock_write_unlock(&class_list->rwlock); 1152 } 1153 1154 void tree_add_devmap_device(dev_tree_t *tree, node_t *node) 1155 { 1156 unsigned long key = (unsigned long) node->devmap_handle; 1157 fibril_rwlock_write_lock(&tree->rwlock); 1158 hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link); 1159 fibril_rwlock_write_unlock(&tree->rwlock); 1160 } 1161 969 1162 /** @} 970 1163 */ -
uspace/srv/devman/devman.h
r0a3fbc7 rf2d2c604 283 283 /* Drivers */ 284 284 285 /** 286 * Initialize the list of device driver's. 287 * 288 * @param drv_list the list of device driver's. 289 * 290 */ 291 static inline void init_driver_list(driver_list_t *drv_list) 292 { 293 assert(drv_list != NULL); 294 295 list_initialize(&drv_list->drivers); 296 fibril_mutex_initialize(&drv_list->drivers_mutex); 297 } 298 285 extern void init_driver_list(driver_list_t *); 299 286 extern driver_t *create_driver(void); 300 287 extern bool get_driver_info(const char *, const char *, driver_t *); … … 311 298 extern driver_t *find_driver(driver_list_t *, const char *); 312 299 extern void set_driver_phone(driver_t *, ipcarg_t); 313 void initialize_running_driver(driver_t *, dev_tree_t *); 314 315 /** Initialize device driver structure. 316 * 317 * @param drv The device driver structure. 318 */ 319 static inline void init_driver(driver_t *drv) 320 { 321 assert(drv != NULL); 322 323 memset(drv, 0, sizeof(driver_t)); 324 list_initialize(&drv->match_ids.ids); 325 list_initialize(&drv->devices); 326 fibril_mutex_initialize(&drv->driver_mutex); 327 } 328 329 /** Device driver structure clean-up. 330 * 331 * @param drv The device driver structure. 332 */ 333 static inline void clean_driver(driver_t *drv) 334 { 335 assert(drv != NULL); 336 337 free_not_null(drv->name); 338 free_not_null(drv->binary_path); 339 340 clean_match_ids(&drv->match_ids); 341 342 init_driver(drv); 343 } 344 345 /** Delete device driver structure. 346 * 347 * @param drv The device driver structure. 348 */ 349 static inline void delete_driver(driver_t *drv) 350 { 351 assert(drv != NULL); 352 353 clean_driver(drv); 354 free(drv); 355 } 356 300 extern void initialize_running_driver(driver_t *, dev_tree_t *); 301 302 extern void init_driver(driver_t *); 303 extern void clean_driver(driver_t *); 304 extern void delete_driver(driver_t *); 357 305 358 306 /* Device nodes */ 359 307 360 /** Create a new device node. 361 * 362 * @return A device node structure. 363 */ 364 static inline node_t *create_dev_node(void) 365 { 366 node_t *res = malloc(sizeof(node_t)); 367 368 if (res != NULL) { 369 memset(res, 0, sizeof(node_t)); 370 list_initialize(&res->children); 371 list_initialize(&res->match_ids.ids); 372 list_initialize(&res->classes); 373 } 374 375 return res; 376 } 377 378 /** Delete a device node. 379 * 380 * @param node The device node structure. 381 */ 382 static inline void delete_dev_node(node_t *node) 383 { 384 assert(list_empty(&node->children)); 385 assert(node->parent == NULL); 386 assert(node->drv == NULL); 387 388 clean_match_ids(&node->match_ids); 389 free_not_null(node->name); 390 free_not_null(node->pathname); 391 free(node); 392 } 393 394 /** Find the device node structure of the device witch has the specified handle. 395 * 396 * Device tree's rwlock should be held at least for reading. 397 * 398 * @param tree The device tree where we look for the device node. 399 * @param handle The handle of the device. 400 * @return The device node. 401 */ 402 static inline node_t *find_dev_node_no_lock(dev_tree_t *tree, 403 device_handle_t handle) 404 { 405 unsigned long key = handle; 406 link_t *link = hash_table_find(&tree->devman_devices, &key); 407 return hash_table_get_instance(link, node_t, devman_link); 408 } 409 410 /** Find the device node structure of the device witch has the specified handle. 411 * 412 * @param tree The device tree where we look for the device node. 413 * @param handle The handle of the device. 414 * @return The device node. 415 */ 416 static inline node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle) 417 { 418 node_t *node = NULL; 419 420 fibril_rwlock_read_lock(&tree->rwlock); 421 node = find_dev_node_no_lock(tree, handle); 422 fibril_rwlock_read_unlock(&tree->rwlock); 423 424 return node; 425 } 426 308 extern node_t *create_dev_node(void); 309 extern void delete_dev_node(node_t *node); 310 extern node_t *find_dev_node_no_lock(dev_tree_t *tree, 311 device_handle_t handle); 312 extern node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle); 427 313 extern node_t *find_dev_node_by_path(dev_tree_t *, char *); 428 314 extern node_t *find_node_child(node_t *, const char *); 429 430 315 431 316 /* Device tree */ … … 435 320 extern bool insert_dev_node(dev_tree_t *, node_t *, char *, node_t *); 436 321 437 438 322 /* Device classes */ 439 323 440 /** Create device class. 441 * 442 * @return Device class. 443 */ 444 static inline dev_class_t *create_dev_class(void) 445 { 446 dev_class_t *cl; 447 448 cl = (dev_class_t *) malloc(sizeof(dev_class_t)); 449 if (cl != NULL) { 450 memset(cl, 0, sizeof(dev_class_t)); 451 list_initialize(&cl->devices); 452 fibril_mutex_initialize(&cl->mutex); 453 } 454 455 return cl; 456 } 457 458 /** Create device class info. 459 * 460 * @return Device class info. 461 */ 462 static inline dev_class_info_t *create_dev_class_info(void) 463 { 464 dev_class_info_t *info; 465 466 info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t)); 467 if (info != NULL) 468 memset(info, 0, sizeof(dev_class_info_t)); 469 470 return info; 471 } 472 473 static inline size_t get_new_class_dev_idx(dev_class_t *cl) 474 { 475 size_t dev_idx; 476 477 fibril_mutex_lock(&cl->mutex); 478 dev_idx = ++cl->curr_dev_idx; 479 fibril_mutex_unlock(&cl->mutex); 480 481 return dev_idx; 482 } 483 324 extern dev_class_t *create_dev_class(void); 325 extern dev_class_info_t *create_dev_class_info(void); 326 extern size_t get_new_class_dev_idx(dev_class_t *); 484 327 extern char *create_dev_name_for_class(dev_class_t *, const char *); 485 328 extern dev_class_info_t *add_device_to_class(node_t *, dev_class_t *, … … 490 333 extern dev_class_t *get_dev_class(class_list_t *, char *); 491 334 extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *); 492 493 static inline void add_dev_class_no_lock(class_list_t *class_list, 494 dev_class_t *cl) 495 { 496 list_append(&cl->link, &class_list->classes); 497 } 498 335 extern void add_dev_class_no_lock(class_list_t *, dev_class_t *); 499 336 500 337 /* Devmap devices */ … … 503 340 extern node_t *find_devmap_class_device(class_list_t *, dev_handle_t); 504 341 505 static inline void class_add_devmap_device(class_list_t *class_list, 506 dev_class_info_t *cli) 507 { 508 unsigned long key = (unsigned long) cli->devmap_handle; 509 510 fibril_rwlock_write_lock(&class_list->rwlock); 511 hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link); 512 fibril_rwlock_write_unlock(&class_list->rwlock); 513 } 514 515 static inline void tree_add_devmap_device(dev_tree_t *tree, node_t *node) 516 { 517 unsigned long key = (unsigned long) node->devmap_handle; 518 fibril_rwlock_write_lock(&tree->rwlock); 519 hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link); 520 fibril_rwlock_write_unlock(&tree->rwlock); 521 } 342 extern void class_add_devmap_device(class_list_t *, dev_class_info_t *); 343 extern void tree_add_devmap_device(dev_tree_t *, node_t *); 522 344 523 345 #endif -
uspace/srv/devman/main.c
r0a3fbc7 rf2d2c604 66 66 static driver_t *devman_driver_register(void) 67 67 { 68 ipc_call_t icall; 69 ipc_callid_t iid; 70 driver_t *driver = NULL; 71 68 72 printf(NAME ": devman_driver_register \n"); 69 73 70 ipc_call_t icall; 71 ipc_callid_t iid = async_get_call(&icall); 72 driver_t *driver = NULL; 73 74 iid = async_get_call(&icall); 74 75 if (IPC_GET_METHOD(icall) != DEVMAN_DRIVER_REGISTER) { 75 76 ipc_answer_0(iid, EREFUSED); … … 85 86 return NULL; 86 87 } 88 87 89 printf(NAME ": the %s driver is trying to register by the service.\n", 88 90 drv_name); … … 91 93 driver = find_driver(&drivers_list, drv_name); 92 94 93 if ( NULL == driver) {95 if (driver == NULL) { 94 96 printf(NAME ": no driver named %s was found.\n", drv_name); 95 97 free(drv_name); … … 146 148 } 147 149 148 if ( NULL == match_id) {150 if (match_id == NULL) { 149 151 printf(NAME ": ERROR: devman_receive_match_id - failed to " 150 152 "allocate match id.\n"); … … 160 162 rc = async_data_write_accept((void **) &match_id_str, true, 0, 0, 0, 0); 161 163 match_id->id = match_id_str; 162 if ( EOK != rc) {164 if (rc != EOK) { 163 165 delete_match_id(match_id); 164 166 printf(NAME ": devman_receive_match_id - failed to receive " … … 181 183 * @return Zero on success, negative error code otherwise. 182 184 */ 183 static int 184 devman_receive_match_ids(ipcarg_t match_count,match_id_list_t *match_ids)185 static int devman_receive_match_ids(ipcarg_t match_count, 186 match_id_list_t *match_ids) 185 187 { 186 188 int ret = EOK; … … 205 207 206 208 fibril_rwlock_write_lock(&tree->rwlock); 207 node_t *parent = 208 209 if ( NULL == parent) {209 node_t *parent = find_dev_node_no_lock(&device_tree, parent_handle); 210 211 if (parent == NULL) { 210 212 fibril_rwlock_write_unlock(&tree->rwlock); 211 213 ipc_answer_0(callid, ENOENT); 212 214 return; 213 } 215 } 214 216 215 217 char *dev_name = NULL; 216 218 int rc = async_data_write_accept((void **)&dev_name, true, 0, 0, 0, 0); 217 if ( EOK != rc) {219 if (rc != EOK) { 218 220 fibril_rwlock_write_unlock(&tree->rwlock); 219 221 ipc_answer_0(callid, rc); … … 227 229 ipc_answer_0(callid, ENOMEM); 228 230 return; 229 } 231 } 232 230 233 fibril_rwlock_write_unlock(&tree->rwlock); 231 234 … … 245 248 /* Create devmap path and name for the device. */ 246 249 char *devmap_pathname = NULL; 250 247 251 asprintf(&devmap_pathname, "%s/%s%c%s", DEVMAP_CLASS_NAMESPACE, 248 252 cli->dev_class->name, DEVMAP_SEPARATOR, cli->dev_name); 249 if ( NULL == devmap_pathname)253 if (devmap_pathname == NULL) 250 254 return; 251 255 … … 279 283 280 284 node_t *dev = find_dev_node(&device_tree, handle); 281 if ( NULL == dev) {285 if (dev == NULL) { 282 286 ipc_answer_0(callid, ENOENT); 283 287 return; … … 318 322 319 323 driver_t *driver = devman_driver_register(); 320 if ( NULL == driver)324 if (driver == NULL) 321 325 return; 322 326 … … 373 377 free(pathname); 374 378 375 if ( NULL == dev) {379 if (dev == NULL) { 376 380 ipc_answer_0(iid, ENOENT); 377 381 return; … … 404 408 ipc_answer_0(callid, ENOENT); 405 409 } 406 } 407 } 408 409 static void 410 devman_forward(ipc_callid_t iid, ipc_call_t *icall,bool drv_to_parent)410 } 411 } 412 413 static void devman_forward(ipc_callid_t iid, ipc_call_t *icall, 414 bool drv_to_parent) 411 415 { 412 416 device_handle_t handle = IPC_GET_ARG2(*icall); 413 417 414 418 node_t *dev = find_dev_node(&device_tree, handle); 415 if ( NULL == dev) {419 if (dev == NULL) { 416 420 printf(NAME ": devman_forward error - no device with handle %x " 417 421 "was found.\n", handle); … … 423 427 424 428 if (drv_to_parent) { 425 if ( NULL != dev->parent)429 if (dev->parent != NULL) 426 430 driver = dev->parent->drv; 427 } else if ( DEVICE_USABLE == dev->state) {431 } else if (dev->state == DEVICE_USABLE) { 428 432 driver = dev->drv; 429 assert( NULL != driver);430 } 431 432 if ( NULL == driver) {433 assert(driver != NULL); 434 } 435 436 if (driver == NULL) { 433 437 printf(NAME ": devman_forward error - the device is not in " 434 438 "usable state.\n", handle); … … 450 454 return; 451 455 } 456 452 457 printf(NAME ": devman_forward: forward connection to device %s to " 453 458 "driver %s.\n", dev->pathname, driver->name); … … 460 465 { 461 466 dev_handle_t devmap_handle = IPC_GET_METHOD(*icall); 462 463 node_t *dev = find_devmap_tree_device(&device_tree, devmap_handle); 464 if (NULL == dev) 467 node_t *dev; 468 469 dev = find_devmap_tree_device(&device_tree, devmap_handle); 470 if (dev == NULL) 465 471 dev = find_devmap_class_device(&class_list, devmap_handle); 466 472 467 if ( NULL == dev || NULL == dev->drv) {473 if (dev == NULL || dev->drv == NULL) { 468 474 ipc_answer_0(iid, ENOENT); 469 475 return; 470 476 } 471 477 472 if ( DEVICE_USABLE != dev->state|| dev->drv->phone <= 0) {478 if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) { 473 479 ipc_answer_0(iid, EINVAL); 474 480 return; … … 493 499 * passes device handle to the driver as an ipc method.) 494 500 */ 495 if (IPC_ M_CONNECT_ME_TO != IPC_GET_METHOD(*icall))501 if (IPC_GET_METHOD(*icall) != IPC_M_CONNECT_ME_TO) 496 502 devman_connection_devmapper(iid, icall); 497 503 … … 531 537 /* Initialize list of available drivers. */ 532 538 init_driver_list(&drivers_list); 533 if ( 0 ==lookup_available_drivers(&drivers_list,534 DRIVER_DEFAULT_STORE) ) {539 if (lookup_available_drivers(&drivers_list, 540 DRIVER_DEFAULT_STORE) == 0) { 535 541 printf(NAME " no drivers found."); 536 542 return false; 537 543 } 544 538 545 printf(NAME ": devman_init - list of drivers has been initialized.\n"); 539 546 -
uspace/srv/devman/match.c
r0a3fbc7 rf2d2c604 55 55 match_id_t *tmp_ma_id; 56 56 57 if ( 0 == str_cmp(drv_id->id, dev_id->id)) {57 if (str_cmp(drv_id->id, dev_id->id) == 0) { 58 58 /* 59 59 * We found a match. … … 67 67 * list of match ids. 68 68 */ 69 if (drv_ head != drv_link->next) {69 if (drv_link->next != drv_head) { 70 70 tmp_ma_id = list_get_instance(drv_link->next, 71 71 match_id_t, link); … … 79 79 * list of match ids. 80 80 */ 81 if (dev_ head != dev_link->next) {81 if (dev_link->next != dev_head) { 82 82 tmp_ma_id = list_get_instance(dev_link->next, 83 83 match_id_t, link); … … 99 99 } 100 100 101 } while (drv_ head != drv_link->next && dev_head != dev_link->next);101 } while (drv_link->next != drv_head && dev_link->next != dev_head); 102 102 103 103 return 0; -
uspace/srv/devman/util.c
r0a3fbc7 rf2d2c604 61 61 char *get_path_elem_end(char *path) 62 62 { 63 while ( 0 != *path && '/' != *path)63 while (*path != '\0' && *path != '/') 64 64 path++; 65 65 return path; 66 66 } 67 67 68 bool skip_spaces(char **buf) 69 { 70 while (isspace(**buf)) 71 (*buf)++; 72 return *buf != 0; 73 } 74 75 size_t get_nonspace_len(const char *str) 76 { 77 size_t len = 0; 78 79 while(*str != '\0' && !isspace(*str)) { 80 len++; 81 str++; 82 } 83 84 return len; 85 } 86 87 void free_not_null(const void *ptr) 88 { 89 if (ptr != NULL) 90 free(ptr); 91 } 92 93 char *clone_string(const char *s) 94 { 95 size_t size = str_size(s) + 1; 96 char *str; 97 98 str = (char *) malloc(size); 99 if (str != NULL) 100 str_cpy(str, size, s); 101 return str; 102 } 103 104 void replace_char(char *str, char orig, char repl) 105 { 106 while (*str) { 107 if (*str == orig) 108 *str = repl; 109 str++; 110 } 111 } 112 68 113 /** @} 69 114 */ -
uspace/srv/devman/util.h
r0a3fbc7 rf2d2c604 41 41 extern char *get_path_elem_end(char *); 42 42 43 static inline bool skip_spaces(char **buf) 44 { 45 while (isspace(**buf)) 46 (*buf)++; 47 return *buf != 0; 48 } 49 50 static inline size_t get_nonspace_len(const char *str) 51 { 52 size_t len = 0; 53 54 while(*str != 0 && !isspace(*str)) { 55 len++; 56 str++; 57 } 58 return len; 59 } 60 61 static inline void free_not_null(const void *ptr) 62 { 63 if (NULL != ptr) 64 free(ptr); 65 } 66 67 static inline char *clone_string(const char *s) 68 { 69 size_t size = str_size(s) + 1; 70 char *str; 71 72 str = (char *) malloc(size); 73 if (NULL != str) 74 str_cpy(str, size, s); 75 return str; 76 } 77 78 static inline void replace_char(char *str, char orig, char repl) 79 { 80 while (*str) { 81 if (orig == *str) 82 *str = repl; 83 str++; 84 } 85 } 43 extern bool skip_spaces(char **); 44 extern size_t get_nonspace_len(const char *); 45 extern void free_not_null(const void *); 46 extern char *clone_string(const char *); 47 extern void replace_char(char *, char, char); 86 48 87 49 #endif
Note:
See TracChangeset
for help on using the changeset viewer.