Changeset 91b60499 in mainline for uspace/lib
- Timestamp:
- 2017-09-30T06:29:42Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 300f4c4
- Parents:
- d076f16 (diff), 6636fb19 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/lib
- Files:
-
- 7 edited
-
c/generic/async.c (modified) (5 diffs)
-
c/generic/ddi.c (modified) (1 diff)
-
c/generic/irq.c (modified) (1 diff)
-
c/include/async.h (modified) (3 diffs)
-
c/include/ipc/irq.h (modified) (1 diff)
-
drv/generic/interrupt.c (modified) (1 diff)
-
usbhost/src/ddf_helpers.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
rd076f16 r91b60499 1048 1048 * 1049 1049 * @param inr IRQ number. 1050 * @param devno Device number of the device generating inr.1051 1050 * @param handler Notification handler. 1052 1051 * @param data Notification handler client data. 1053 1052 * @param ucode Top-half pseudocode handler. 1054 1053 * 1055 * @return Zero on success or a negative error code. 1056 * 1057 */ 1058 int async_irq_subscribe(int inr, int devno, 1059 async_notification_handler_t handler, void *data, const irq_code_t *ucode) 1054 * @return IRQ capability handle on success. 1055 * @return Negative error code. 1056 * 1057 */ 1058 int async_irq_subscribe(int inr, async_notification_handler_t handler, 1059 void *data, const irq_code_t *ucode) 1060 1060 { 1061 1061 notification_t *notification = … … 1077 1077 futex_up(&async_futex); 1078 1078 1079 return ipc_irq_subscribe(inr, devno,imethod, ucode);1079 return ipc_irq_subscribe(inr, imethod, ucode); 1080 1080 } 1081 1081 1082 1082 /** Unsubscribe from IRQ notification. 1083 1083 * 1084 * @param inr IRQ number. 1085 * @param devno Device number of the device generating inr. 1084 * @param cap IRQ capability handle. 1086 1085 * 1087 1086 * @return Zero on success or a negative error code. 1088 1087 * 1089 1088 */ 1090 int async_irq_unsubscribe(int inr, int devno)1089 int async_irq_unsubscribe(int cap) 1091 1090 { 1092 1091 // TODO: Remove entry from hash table 1093 1092 // to avoid memory leak 1094 1093 1095 return ipc_irq_unsubscribe( inr, devno);1094 return ipc_irq_unsubscribe(cap); 1096 1095 } 1097 1096 … … 1384 1383 async_new_connection(call->in_task_id, in_phone_hash, callid, 1385 1384 call, handler, data); 1386 return;1387 }1388 1389 /* Cloned connection */1390 if (IPC_GET_IMETHOD(*call) == IPC_M_CLONE_ESTABLISH) {1391 // TODO: Currently ignores ports altogether1392 1393 /* Open new connection with fibril, etc. */1394 async_new_connection(call->in_task_id, IPC_GET_ARG5(*call),1395 callid, call, fallback_port_handler, fallback_port_data);1396 1385 return; 1397 1386 } … … 2111 2100 2112 2101 return EOK; 2113 }2114 2115 /** Wrapper for making IPC_M_CLONE_ESTABLISH calls using the async framework.2116 *2117 * Ask for a cloned connection to some service.2118 *2119 * @param mgmt Exchange management style.2120 * @param exch Exchange for sending the message.2121 *2122 * @return New session on success or NULL on error.2123 *2124 */2125 async_sess_t *async_clone_establish(exch_mgmt_t mgmt, async_exch_t *exch)2126 {2127 if (exch == NULL) {2128 errno = ENOENT;2129 return NULL;2130 }2131 2132 async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));2133 if (sess == NULL) {2134 errno = ENOMEM;2135 return NULL;2136 }2137 2138 ipc_call_t result;2139 2140 amsg_t *msg = amsg_create();2141 if (!msg) {2142 free(sess);2143 errno = ENOMEM;2144 return NULL;2145 }2146 2147 msg->dataptr = &result;2148 msg->wdata.active = true;2149 2150 ipc_call_async_0(exch->phone, IPC_M_CLONE_ESTABLISH, msg,2151 reply_received);2152 2153 sysarg_t rc;2154 async_wait_for((aid_t) msg, &rc);2155 2156 if (rc != EOK) {2157 errno = rc;2158 free(sess);2159 return NULL;2160 }2161 2162 int phone = (int) IPC_GET_ARG5(result);2163 2164 if (phone < 0) {2165 errno = phone;2166 free(sess);2167 return NULL;2168 }2169 2170 sess->iface = 0;2171 sess->mgmt = mgmt;2172 sess->phone = phone;2173 sess->arg1 = 0;2174 sess->arg2 = 0;2175 sess->arg3 = 0;2176 2177 fibril_mutex_initialize(&sess->remote_state_mtx);2178 sess->remote_state_data = NULL;2179 2180 list_initialize(&sess->exch_list);2181 fibril_mutex_initialize(&sess->mutex);2182 atomic_set(&sess->refcnt, 0);2183 2184 return sess;2185 2102 } 2186 2103 … … 3153 3070 } 3154 3071 3155 /** Wrapper for sending an exchange over different exchange for cloning3156 *3157 * @param exch Exchange to be used for sending.3158 * @param clone_exch Exchange to be cloned.3159 *3160 */3161 int async_exchange_clone(async_exch_t *exch, async_exch_t *clone_exch)3162 {3163 return async_req_1_0(exch, IPC_M_CONNECTION_CLONE, clone_exch->phone);3164 }3165 3166 /** Wrapper for receiving the IPC_M_CONNECTION_CLONE calls.3167 *3168 * If the current call is IPC_M_CONNECTION_CLONE then a new3169 * async session is created for the accepted phone.3170 *3171 * @param mgmt Exchange management style.3172 *3173 * @return New async session or NULL on failure.3174 *3175 */3176 async_sess_t *async_clone_receive(exch_mgmt_t mgmt)3177 {3178 /* Accept the phone */3179 ipc_call_t call;3180 ipc_callid_t callid = async_get_call(&call);3181 int phone = (int) IPC_GET_ARG1(call);3182 3183 if ((IPC_GET_IMETHOD(call) != IPC_M_CONNECTION_CLONE) ||3184 (phone < 0)) {3185 async_answer_0(callid, EINVAL);3186 return NULL;3187 }3188 3189 async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));3190 if (sess == NULL) {3191 async_answer_0(callid, ENOMEM);3192 return NULL;3193 }3194 3195 sess->iface = 0;3196 sess->mgmt = mgmt;3197 sess->phone = phone;3198 sess->arg1 = 0;3199 sess->arg2 = 0;3200 sess->arg3 = 0;3201 3202 fibril_mutex_initialize(&sess->remote_state_mtx);3203 sess->remote_state_data = NULL;3204 3205 list_initialize(&sess->exch_list);3206 fibril_mutex_initialize(&sess->mutex);3207 atomic_set(&sess->refcnt, 0);3208 3209 /* Acknowledge the cloned phone */3210 async_answer_0(callid, EOK);3211 3212 return sess;3213 }3214 3215 3072 /** Wrapper for receiving the IPC_M_CONNECT_TO_ME calls. 3216 3073 * -
uspace/lib/c/generic/ddi.c
rd076f16 r91b60499 50 50 #include "private/libc.h" 51 51 52 53 /** Return unique device number.54 *55 * @return New unique device number.56 *57 */58 int device_assign_devno(void)59 {60 return __SYSCALL0(SYS_DEVICE_ASSIGN_DEVNO);61 }62 52 63 53 /** Map a piece of physical memory to task. -
uspace/lib/c/generic/irq.c
rd076f16 r91b60499 55 55 * 56 56 * @param inr IRQ number. 57 * @param devno Device number of the device generating inr.58 57 * @param method Use this method for notifying me. 59 58 * @param ucode Top-half pseudocode handler. 59 * 60 * @return IRQ capability handle returned by the kernel. 61 * @return Error code returned by the kernel. 62 * 63 */ 64 int ipc_irq_subscribe(int inr, sysarg_t method, const irq_code_t *ucode) 65 { 66 if (ucode == NULL) 67 ucode = &default_ucode; 68 69 return __SYSCALL3(SYS_IPC_IRQ_SUBSCRIBE, inr, method, (sysarg_t) ucode); 70 } 71 72 /** Unsubscribe from IRQ notification. 73 * 74 * @param cap IRQ capability handle. 60 75 * 61 76 * @return Value returned by the kernel. 62 77 * 63 78 */ 64 int ipc_irq_subscribe(int inr, int devno, sysarg_t method, 65 const irq_code_t *ucode) 79 int ipc_irq_unsubscribe(int cap) 66 80 { 67 if (ucode == NULL) 68 ucode = &default_ucode; 69 70 return __SYSCALL4(SYS_IPC_IRQ_SUBSCRIBE, inr, devno, method, 71 (sysarg_t) ucode); 72 } 73 74 /** Unsubscribe from IRQ notification. 75 * 76 * @param inr IRQ number. 77 * @param devno Device number of the device generating inr. 78 * 79 * @return Value returned by the kernel. 80 * 81 */ 82 int ipc_irq_unsubscribe(int inr, int devno) 83 { 84 return __SYSCALL2(SYS_IPC_IRQ_UNSUBSCRIBE, inr, devno); 81 return __SYSCALL1(SYS_IPC_IRQ_UNSUBSCRIBE, cap); 85 82 } 86 83 -
uspace/lib/c/include/async.h
rd076f16 r91b60499 166 166 sysarg_t, async_port_handler_t, void *, port_id_t *); 167 167 168 extern int async_irq_subscribe(int, int,async_notification_handler_t, void *,168 extern int async_irq_subscribe(int, async_notification_handler_t, void *, 169 169 const irq_code_t *); 170 extern int async_irq_unsubscribe(int , int);170 extern int async_irq_unsubscribe(int); 171 171 172 172 extern int async_event_subscribe(event_type_t, async_notification_handler_t, … … 343 343 sysarg_t *, sysarg_t *); 344 344 345 extern async_sess_t *async_clone_establish(exch_mgmt_t, async_exch_t *);346 345 extern async_sess_t *async_connect_me_to(exch_mgmt_t, async_exch_t *, sysarg_t, 347 346 sysarg_t, sysarg_t); … … 472 471 sysarg_t, sysarg_t, sysarg_t, ipc_call_t *); 473 472 474 extern int async_exchange_clone(async_exch_t *, async_exch_t *);475 extern async_sess_t *async_clone_receive(exch_mgmt_t);476 473 extern async_sess_t *async_callback_receive(exch_mgmt_t); 477 474 extern async_sess_t *async_callback_receive_start(exch_mgmt_t, ipc_call_t *); -
uspace/lib/c/include/ipc/irq.h
rd076f16 r91b60499 39 39 #include <abi/ddi/irq.h> 40 40 41 extern int ipc_irq_subscribe(int, int,sysarg_t, const irq_code_t *);42 extern int ipc_irq_unsubscribe(int , int);41 extern int ipc_irq_subscribe(int, sysarg_t, const irq_code_t *); 42 extern int ipc_irq_unsubscribe(int); 43 43 44 44 #endif -
uspace/lib/drv/generic/interrupt.c
rd076f16 r91b60499 44 44 45 45 int register_interrupt_handler(ddf_dev_t *dev, int irq, 46 interrupt_handler_t *handler, const irq_code_t * pseudocode)46 interrupt_handler_t *handler, const irq_code_t *irq_code) 47 47 { 48 return async_irq_subscribe(irq, dev->handle,49 (async_notification_handler_t) handler, dev, pseudocode);48 return async_irq_subscribe(irq, (async_notification_handler_t) handler, 49 dev, irq_code); 50 50 } 51 51 52 int unregister_interrupt_handler(ddf_dev_t *dev, int irq)52 int unregister_interrupt_handler(ddf_dev_t *dev, int cap) 53 53 { 54 return async_irq_unsubscribe( irq, dev->handle);54 return async_irq_unsubscribe(cap); 55 55 } 56 56 -
uspace/lib/usbhost/src/ddf_helpers.c
rd076f16 r91b60499 748 748 * @param[in] gen_irq_code IRQ code generator. 749 749 * 750 * @return EOK on success or negative error code 750 * @return IRQ capability handle on success. 751 * @return Negative error code. 751 752 */ 752 753 int hcd_ddf_setup_interrupts(ddf_dev_t *device, … … 770 771 771 772 /* Register handler to avoid interrupt lockup */ 772 int ret = register_interrupt_handler(device, irq, handler, &irq_code); 773 const int irq_cap = register_interrupt_handler(device, irq, handler, 774 &irq_code); 773 775 irq_code_clean(&irq_code); 776 if (irq_cap < 0) { 777 usb_log_error("Failed to register interrupt handler: %s.\n", 778 str_error(irq_cap)); 779 return irq_cap; 780 } 781 782 /* Enable interrupts */ 783 int ret = hcd_ddf_enable_interrupts(device); 774 784 if (ret != EOK) { 775 785 usb_log_error("Failed to register interrupt handler: %s.\n", 776 786 str_error(ret)); 777 return ret; 778 } 779 780 /* Enable interrupts */ 781 ret = hcd_ddf_enable_interrupts(device); 782 if (ret != EOK) { 783 usb_log_error("Failed to register interrupt handler: %s.\n", 784 str_error(ret)); 785 unregister_interrupt_handler(device, irq); 786 return ret; 787 } 788 assert(irq > 0); 789 return irq; 787 unregister_interrupt_handler(device, irq_cap); 788 return ret; 789 } 790 return irq_cap; 790 791 } 791 792 … … 882 883 interrupt_handler_t *irq_handler = 883 884 driver->irq_handler ? driver->irq_handler : ddf_hcd_gen_irq_handler; 884 const int irq = hcd_ddf_setup_interrupts(device, &hw_res, irq_handler, 885 driver->irq_code_gen); 886 if (!(irq < 0)) { 885 const int irq_cap = hcd_ddf_setup_interrupts(device, &hw_res, 886 irq_handler, driver->irq_code_gen); 887 bool irqs_enabled = !(irq_cap < 0); 888 if (irqs_enabled) { 887 889 usb_log_debug("Hw interrupts enabled.\n"); 888 890 } … … 899 901 /* Init hw driver */ 900 902 hcd_t *hcd = dev_to_hcd(device); 901 ret = driver->init(hcd, &hw_res, !(irq < 0));903 ret = driver->init(hcd, &hw_res, irqs_enabled); 902 904 hw_res_list_parsed_clean(&hw_res); 903 905 if (ret != EOK) { … … 907 909 908 910 /* Need working irq replacement to setup root hub */ 909 if ( (irq < 0)&& hcd->ops.status_hook) {911 if (!irqs_enabled && hcd->ops.status_hook) { 910 912 hcd->polling_fibril = fibril_create(interrupt_polling, hcd); 911 913 if (hcd->polling_fibril == 0) { … … 916 918 fibril_add_ready(hcd->polling_fibril); 917 919 usb_log_warning("Failed to enable interrupts: %s." 918 " Falling back to polling.\n", str_error(irq ));920 " Falling back to polling.\n", str_error(irq_cap)); 919 921 } 920 922 … … 930 932 irq_unregister: 931 933 /* Unregistering non-existent should be ok */ 932 unregister_interrupt_handler(device, irq );934 unregister_interrupt_handler(device, irq_cap); 933 935 hcd_ddf_clean_hc(device); 934 936 return ret;
Note:
See TracChangeset
for help on using the changeset viewer.
