Changeset 7fcb74c in mainline
- Timestamp:
- 2009-06-29T16:02:32Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f49cf64
- Parents:
- bfd247f
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/devmap.c
rbfd247f r7fcb74c 219 219 } 220 220 221 int devmap_null_create(void) 222 { 223 int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING); 224 225 if (phone < 0) 226 return -1; 227 228 ipcarg_t null_id; 229 int retval = async_req_0_1(phone, DEVMAP_DEVICE_NULL_CREATE, &null_id); 230 if (retval != EOK) 231 return -1; 232 233 return (int) null_id; 234 } 235 236 void devmap_null_destroy(int null_id) 237 { 238 int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING); 239 240 if (phone < 0) 241 return; 242 243 async_req_1_0(phone, DEVMAP_DEVICE_NULL_DESTROY, (ipcarg_t) null_id); 244 } 245 221 246 ipcarg_t devmap_device_get_count(void) 222 247 { -
uspace/lib/libc/include/devmap.h
rbfd247f r7fcb74c 48 48 extern int devmap_device_connect(dev_handle_t, unsigned int); 49 49 50 extern int devmap_null_create(void); 51 extern void devmap_null_destroy(int); 52 50 53 extern ipcarg_t devmap_device_get_count(void); 51 54 extern ipcarg_t devmap_device_get_devices(ipcarg_t, dev_desc_t *); -
uspace/lib/libc/include/ipc/devmap.h
rbfd247f r7fcb74c 29 29 /** @addtogroup devmap 30 30 * @{ 31 */ 31 */ 32 32 33 33 #ifndef DEVMAP_DEVMAP_H_ … … 49 49 DEVMAP_DEVICE_GET_NAME, 50 50 DEVMAP_DEVICE_GET_HANDLE, 51 DEVMAP_DEVICE_NULL_CREATE, 52 DEVMAP_DEVICE_NULL_DESTROY, 51 53 DEVMAP_DEVICE_GET_COUNT, 52 54 DEVMAP_DEVICE_GET_DEVICES -
uspace/srv/devmap/devmap.c
rbfd247f r7fcb74c 47 47 #include <ipc/devmap.h> 48 48 49 #define NAME "devmap" 49 #define NAME "devmap" 50 #define NULL_DEVICES 256 50 51 51 52 /** Representation of device driver. … … 98 99 static FIBRIL_MUTEX_INITIALIZE(drivers_list_mutex); 99 100 static FIBRIL_MUTEX_INITIALIZE(create_handle_mutex); 101 static FIBRIL_MUTEX_INITIALIZE(null_devices_mutex); 100 102 101 103 static dev_handle_t last_handle = 0; 104 static devmap_device_t *null_devices[NULL_DEVICES]; 102 105 103 106 static dev_handle_t devmap_create_handle(void) … … 619 622 } 620 623 621 /** Initialize device mapper. 622 * 623 * 624 */ 625 static bool devmap_init(void) 626 { 624 static void devmap_null_create(ipc_callid_t iid, ipc_call_t *icall) 625 { 626 fibril_mutex_lock(&null_devices_mutex); 627 628 unsigned int i; 629 bool fnd = false; 630 631 for (i = 0; i < NULL_DEVICES; i++) { 632 if (null_devices[i] == NULL) { 633 fnd = true; 634 break; 635 } 636 } 637 638 if (!fnd) { 639 fibril_mutex_unlock(&null_devices_mutex); 640 ipc_answer_0(iid, ENOMEM); 641 return; 642 } 643 627 644 /* Create NULL device entry */ 628 645 devmap_device_t *device = (devmap_device_t *) malloc(sizeof(devmap_device_t)); 629 if (device == NULL) 630 return false; 631 632 device->name = str_dup("null"); 646 if (device == NULL) { 647 fibril_mutex_unlock(&null_devices_mutex); 648 ipc_answer_0(iid, ENOMEM); 649 return; 650 } 651 652 char null[DEVMAP_NAME_MAXLEN]; 653 snprintf(null, DEVMAP_NAME_MAXLEN, "null%u", i); 654 655 device->name = str_dup(null); 633 656 if (device->name == NULL) { 657 fibril_mutex_unlock(&null_devices_mutex); 634 658 free(device); 635 return false; 659 ipc_answer_0(iid, ENOMEM); 660 return; 636 661 } 637 662 … … 645 670 device->driver = NULL; 646 671 647 /* Insert device into list of all devices */ 672 /* Insert device into list of all devices 673 and into null devices array */ 648 674 list_append(&device->devices, &devices_list); 675 null_devices[i] = device; 649 676 650 677 fibril_mutex_unlock(&devices_list_mutex); 678 fibril_mutex_unlock(&null_devices_mutex); 679 680 ipc_answer_1(iid, EOK, (ipcarg_t) i); 681 } 682 683 static void devmap_null_destroy(ipc_callid_t iid, ipc_call_t *icall) 684 { 685 fibril_mutex_lock(&null_devices_mutex); 686 687 ipcarg_t i = IPC_GET_ARG1(*icall); 688 689 if (null_devices[i] == NULL) { 690 ipc_answer_0(iid, ENOENT); 691 return; 692 } 693 694 devmap_device_unregister_core(null_devices[i]); 695 null_devices[i] = NULL; 696 697 fibril_mutex_unlock(&null_devices_mutex); 698 699 ipc_answer_0(iid, EOK); 700 } 701 702 /** Initialize device mapper. 703 * 704 * 705 */ 706 static bool devmap_init(void) 707 { 708 fibril_mutex_lock(&null_devices_mutex); 709 710 unsigned int i; 711 for (i = 0; i < NULL_DEVICES; i++) 712 null_devices[i] = NULL; 713 714 fibril_mutex_unlock(&null_devices_mutex); 651 715 652 716 return true; … … 702 766 } 703 767 704 if ( NULL != driver) {768 if (driver != NULL) { 705 769 /* 706 770 * Unregister the device driver and all its devices. … … 733 797 case DEVMAP_DEVICE_GET_NAME: 734 798 devmap_get_name(callid, &call); 799 break; 800 case DEVMAP_DEVICE_NULL_CREATE: 801 devmap_null_create(callid, &call); 802 break; 803 case DEVMAP_DEVICE_NULL_DESTROY: 804 devmap_null_destroy(callid, &call); 735 805 break; 736 806 case DEVMAP_DEVICE_GET_COUNT: … … 784 854 /* Set a handler of incomming connections */ 785 855 async_set_client_connection(devmap_connection); 786 856 787 857 /* Register device mapper at naming service */ 788 858 ipcarg_t phonead;
Note:
See TracChangeset
for help on using the changeset viewer.