Changeset 03362fbd in mainline for uspace/lib/drv
- Timestamp:
- 2013-02-09T23:14:45Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 22dfd38
- Parents:
- b5d2e57 (diff), 005b765 (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/drv
- Files:
-
- 10 added
- 12 edited
-
Makefile (modified) (2 diffs)
-
generic/dev_iface.c (modified) (3 diffs)
-
generic/driver.c (modified) (10 diffs)
-
generic/interrupt.c (modified) (1 diff)
-
generic/log.c (modified) (2 diffs)
-
generic/private/driver.h (added)
-
generic/remote_battery_dev.c (added)
-
generic/remote_clock_dev.c (added)
-
generic/remote_graph_dev.c (added)
-
generic/remote_usb.c (modified) (8 diffs)
-
generic/remote_usbhc.c (modified) (15 diffs)
-
include/audio_mixer_iface.h (modified) (1 diff)
-
include/audio_pcm_iface.h (modified) (1 diff)
-
include/ddf/driver.h (modified) (4 diffs)
-
include/ddf/log.h (modified) (1 diff)
-
include/ops/battery_dev.h (added)
-
include/ops/clock_dev.h (added)
-
include/ops/graph_dev.h (added)
-
include/remote_battery_dev.h (added)
-
include/remote_clock_dev.h (added)
-
include/remote_graph_dev.h (added)
-
include/usbhc_iface.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/Makefile
rb5d2e57 r03362fbd 42 42 generic/remote_hw_res.c \ 43 43 generic/remote_char_dev.c \ 44 generic/remote_graph_dev.c \ 44 45 generic/remote_nic.c \ 45 46 generic/remote_usb.c \ … … 47 48 generic/remote_usbhc.c \ 48 49 generic/remote_usbhid.c \ 50 generic/remote_clock_dev.c \ 51 generic/remote_battery_dev.c \ 49 52 generic/remote_ahci.c 50 53 -
uspace/lib/drv/generic/dev_iface.c
rb5d2e57 r03362fbd 41 41 #include "remote_hw_res.h" 42 42 #include "remote_char_dev.h" 43 #include "remote_clock_dev.h" 44 #include "remote_battery_dev.h" 45 #include "remote_graph_dev.h" 43 46 #include "remote_nic.h" 44 47 #include "remote_usb.h" … … 56 59 [HW_RES_DEV_IFACE] = &remote_hw_res_iface, 57 60 [CHAR_DEV_IFACE] = &remote_char_dev_iface, 61 [GRAPH_DEV_IFACE] = &remote_graph_dev_iface, 58 62 [NIC_DEV_IFACE] = &remote_nic_iface, 59 63 [PCI_DEV_IFACE] = &remote_pci_iface, … … 61 65 [USBHC_DEV_IFACE] = &remote_usbhc_iface, 62 66 [USBHID_DEV_IFACE] = &remote_usbhid_iface, 67 [CLOCK_DEV_IFACE] = &remote_clock_dev_iface, 68 [BATTERY_DEV_IFACE] = &remote_battery_dev_iface, 63 69 [AHCI_DEV_IFACE] = &remote_ahci_iface, 64 70 } -
uspace/lib/drv/generic/driver.c
rb5d2e57 r03362fbd 37 37 */ 38 38 39 #define _DDF_DATA_IMPLANT 40 39 41 #include <assert.h> 40 42 #include <ipc/services.h> … … 43 45 #include <stdio.h> 44 46 #include <errno.h> 45 #include < bool.h>47 #include <stdbool.h> 46 48 #include <fibril_synch.h> 47 49 #include <stdlib.h> … … 58 60 #include "ddf/driver.h" 59 61 #include "ddf/interrupt.h" 62 #include "private/driver.h" 60 63 61 64 /** Driver structure */ … … 523 526 static void delete_device(ddf_dev_t *dev) 524 527 { 528 if (dev->parent_sess) 529 async_hangup(dev->parent_sess); 525 530 if (dev->driver_data != NULL) 526 531 free(dev->driver_data); … … 597 602 } 598 603 604 /** Implant foreign driver-specific device data. 605 * 606 * XXX This is used to transition USB to new interface. Do not use 607 * in new code. Use of this function must be removed. 608 */ 609 void ddf_fun_data_implant(ddf_fun_t *fun, void *data) 610 { 611 assert(fun->driver_data == NULL); 612 fun->driver_data = data; 613 } 614 615 /** Return driver-specific device data. */ 616 void *ddf_dev_data_get(ddf_dev_t *dev) 617 { 618 return dev->driver_data; 619 } 620 621 /** Get device handle. */ 622 devman_handle_t ddf_dev_get_handle(ddf_dev_t *dev) 623 { 624 return dev->handle; 625 } 626 627 /** Return device name. 628 * 629 * @param dev Device 630 * @return Device name. Valid as long as @a dev is valid. 631 */ 632 const char *ddf_dev_get_name(ddf_dev_t *dev) 633 { 634 return dev->name; 635 } 636 637 /** Create session with the parent function. 638 * 639 * The session will be automatically closed when @a dev is destroyed. 640 * 641 * @param dev Device 642 * @param mgmt Exchange management style 643 * @return New session or NULL if session could not be created 644 */ 645 async_sess_t *ddf_dev_parent_sess_create(ddf_dev_t *dev, exch_mgmt_t mgmt) 646 { 647 assert(dev->parent_sess == NULL); 648 dev->parent_sess = devman_parent_device_connect(mgmt, dev->handle, 649 IPC_FLAG_BLOCKING); 650 651 return dev->parent_sess; 652 } 653 654 /** Return existing session with the parent function. 655 * 656 * @param dev Device 657 * @return Existing session or NULL if there is no session 658 */ 659 async_sess_t *ddf_dev_parent_sess_get(ddf_dev_t *dev) 660 { 661 return dev->parent_sess; 662 } 663 664 /** Set function name (if it was not specified when node was created.) 665 * 666 * @param dev Device whose name has not been set yet 667 * @param name Name, will be copied 668 * @return EOK on success, ENOMEM if out of memory 669 */ 670 int ddf_fun_set_name(ddf_fun_t *dev, const char *name) 671 { 672 assert(dev->name == NULL); 673 674 dev->name = str_dup(name); 675 if (dev->name == NULL) 676 return ENOENT; 677 678 return EOK; 679 } 680 681 /** Get device to which function belongs. */ 682 ddf_dev_t *ddf_fun_get_dev(ddf_fun_t *fun) 683 { 684 return fun->dev; 685 } 686 687 /** Get function handle. 688 * 689 * XXX USB uses this, but its use should be eliminated. 690 */ 691 devman_handle_t ddf_fun_get_handle(ddf_fun_t *fun) 692 { 693 return fun->handle; 694 } 695 599 696 /** Create a DDF function node. 600 697 * … … 608 705 * This function should only fail if there is not enough free memory. 609 706 * Specifically, this function succeeds even if @a dev already has 610 * a (bound) function with the same name. 707 * a (bound) function with the same name. @a name can be NULL in which 708 * case the caller will set the name later using ddf_fun_set_name(). 709 * He must do this before binding the function. 611 710 * 612 711 * Type: A function of type fun_inner indicates that DDF should attempt … … 616 715 * @param dev Device to which we are adding function 617 716 * @param ftype Type of function (fun_inner or fun_exposed) 618 * @param name Name of function 717 * @param name Name of function or NULL 619 718 * 620 719 * @return New function or @c NULL if memory is not available … … 633 732 fun->ftype = ftype; 634 733 635 fun->name = str_dup(name); 636 if (fun->name == NULL) { 637 delete_function(fun); 638 return NULL; 734 if (name != NULL) { 735 fun->name = str_dup(name); 736 if (fun->name == NULL) { 737 delete_function(fun); 738 return NULL; 739 } 639 740 } 640 741 … … 654 755 fun->driver_data = data; 655 756 return data; 757 } 758 759 /** Return driver-specific function data. */ 760 void *ddf_fun_data_get(ddf_fun_t *fun) 761 { 762 return fun->driver_data; 763 } 764 765 /** Return function name. 766 * 767 * @param fun Function 768 * @return Function name. Valid as long as @a fun is valid. 769 */ 770 const char *ddf_fun_get_name(ddf_fun_t *fun) 771 { 772 return fun->name; 656 773 } 657 774 … … 805 922 add_match_id(&fun->match_ids, match_id); 806 923 return EOK; 924 } 925 926 /** Set function ops. */ 927 void ddf_fun_set_ops(ddf_fun_t *fun, ddf_dev_ops_t *dev_ops) 928 { 929 assert(fun->conn_handler == NULL); 930 fun->ops = dev_ops; 931 } 932 933 /** Set user-defined connection handler. 934 * 935 * This allows handling connections the non-devman way. 936 */ 937 void ddf_fun_set_conn_handler(ddf_fun_t *fun, async_client_conn_t conn) 938 { 939 assert(fun->ops == NULL); 940 fun->conn_handler = conn; 807 941 } 808 942 -
uspace/lib/drv/generic/interrupt.c
rb5d2e57 r03362fbd 41 41 42 42 #include "ddf/interrupt.h" 43 #include "private/driver.h" 43 44 44 45 static void driver_irq_handler(ipc_callid_t iid, ipc_call_t *icall); -
uspace/lib/drv/generic/log.c
rb5d2e57 r03362fbd 38 38 * 39 39 * @param drv_name Driver name, will be printed as part of message 40 * @param level Minimum message level to print41 40 * 42 41 */ 43 int ddf_log_init(const char *drv_name , log_level_t level)42 int ddf_log_init(const char *drv_name) 44 43 { 45 return log_init(drv_name , level);44 return log_init(drv_name); 46 45 } 47 46 … … 59 58 60 59 va_start(args, fmt); 61 log_msgv( level, fmt, args);60 log_msgv(LOG_DEFAULT, level, fmt, args); 62 61 va_end(args); 63 62 } -
uspace/lib/drv/generic/remote_usb.c
rb5d2e57 r03362fbd 56 56 { 57 57 if (!exch) 58 return E INVAL;58 return EBADMEM; 59 59 sysarg_t addr; 60 60 const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE), … … 65 65 return ret; 66 66 } 67 /*----------------------------------------------------------------------------*/ 67 68 68 /** Tell interface number given device can use. 69 69 * @param[in] exch IPC communication exchange … … 75 75 { 76 76 if (!exch) 77 return E INVAL;77 return EBADMEM; 78 78 sysarg_t iface_no; 79 79 const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE), … … 83 83 return ret; 84 84 } 85 /*----------------------------------------------------------------------------*/ 85 86 86 /** Tell devman handle of device host controller. 87 87 * @param[in] exch IPC communication exchange … … 92 92 { 93 93 if (!exch) 94 return E INVAL;94 return EBADMEM; 95 95 devman_handle_t h; 96 96 const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE), … … 121 121 }; 122 122 123 /*----------------------------------------------------------------------------*/ 123 124 124 void remote_usb_get_my_address(ddf_fun_t *fun, void *iface, 125 125 ipc_callid_t callid, ipc_call_t *call) … … 140 140 } 141 141 } 142 /*----------------------------------------------------------------------------*/ 142 143 143 void remote_usb_get_my_interface(ddf_fun_t *fun, void *iface, 144 144 ipc_callid_t callid, ipc_call_t *call) … … 159 159 } 160 160 } 161 /*----------------------------------------------------------------------------*/ 161 162 162 void remote_usb_get_hc_handle(ddf_fun_t *fun, void *iface, 163 163 ipc_callid_t callid, ipc_call_t *call) -
uspace/lib/drv/generic/remote_usbhc.c
rb5d2e57 r03362fbd 165 165 { 166 166 if (!exch || !address) 167 return E INVAL;167 return EBADMEM; 168 168 sysarg_t new_address; 169 169 const int ret = async_req_4_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), … … 173 173 return ret; 174 174 } 175 /*----------------------------------------------------------------------------*/ 175 176 176 int usbhc_bind_address(async_exch_t *exch, usb_address_t address, 177 177 devman_handle_t handle) 178 178 { 179 179 if (!exch) 180 return E INVAL;180 return EBADMEM; 181 181 return async_req_3_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 182 182 IPC_M_USBHC_BIND_ADDRESS, address, handle); 183 183 } 184 /*----------------------------------------------------------------------------*/ 184 185 185 int usbhc_get_handle(async_exch_t *exch, usb_address_t address, 186 186 devman_handle_t *handle) 187 187 { 188 188 if (!exch) 189 return E INVAL;189 return EBADMEM; 190 190 sysarg_t h; 191 191 const int ret = async_req_2_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), … … 195 195 return ret; 196 196 } 197 /*----------------------------------------------------------------------------*/ 197 198 198 int usbhc_release_address(async_exch_t *exch, usb_address_t address) 199 199 { 200 200 if (!exch) 201 return E INVAL;201 return EBADMEM; 202 202 return async_req_2_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 203 203 IPC_M_USBHC_RELEASE_ADDRESS, address); 204 204 } 205 /*----------------------------------------------------------------------------*/ 205 206 206 int usbhc_register_endpoint(async_exch_t *exch, usb_address_t address, 207 207 usb_endpoint_t endpoint, usb_transfer_type_t type, … … 209 209 { 210 210 if (!exch) 211 return E INVAL;211 return EBADMEM; 212 212 const usb_target_t target = 213 213 {{ .address = address, .endpoint = endpoint }}; … … 220 220 #undef _PACK2 221 221 } 222 /*----------------------------------------------------------------------------*/ 222 223 223 int usbhc_unregister_endpoint(async_exch_t *exch, usb_address_t address, 224 224 usb_endpoint_t endpoint, usb_direction_t direction) 225 225 { 226 226 if (!exch) 227 return E INVAL;227 return EBADMEM; 228 228 return async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 229 229 IPC_M_USBHC_UNREGISTER_ENDPOINT, address, endpoint, direction); 230 230 } 231 /*----------------------------------------------------------------------------*/ 231 232 232 int usbhc_read(async_exch_t *exch, usb_address_t address, 233 233 usb_endpoint_t endpoint, uint64_t setup, void *data, size_t size, 234 234 size_t *rec_size) 235 235 { 236 if (!exch) 237 return EBADMEM; 238 236 239 if (size == 0 && setup == 0) 237 240 return EOK; 238 241 239 if (!exch)240 return EINVAL;241 242 const usb_target_t target = 242 243 {{ .address = address, .endpoint = endpoint }}; … … 284 285 return EOK; 285 286 } 286 /*----------------------------------------------------------------------------*/ 287 287 288 int usbhc_write(async_exch_t *exch, usb_address_t address, 288 289 usb_endpoint_t endpoint, uint64_t setup, const void *data, size_t size) 289 290 { 291 if (!exch) 292 return EBADMEM; 293 290 294 if (size == 0 && setup == 0) 291 295 return EOK; 292 296 293 if (!exch)294 return EINVAL;295 297 const usb_target_t target = 296 298 {{ .address = address, .endpoint = endpoint }}; … … 319 321 return (int) opening_request_rc; 320 322 } 321 /*----------------------------------------------------------------------------*/ 323 322 324 323 325 static void remote_usbhc_request_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); … … 384 386 return trans; 385 387 } 386 /*----------------------------------------------------------------------------*/ 388 387 389 void remote_usbhc_request_address(ddf_fun_t *fun, void *iface, 388 390 ipc_callid_t callid, ipc_call_t *call) … … 406 408 } 407 409 } 408 /*----------------------------------------------------------------------------*/ 410 409 411 void remote_usbhc_bind_address(ddf_fun_t *fun, void *iface, 410 412 ipc_callid_t callid, ipc_call_t *call) … … 423 425 async_answer_0(callid, ret); 424 426 } 425 /*----------------------------------------------------------------------------*/ 427 426 428 void remote_usbhc_get_handle(ddf_fun_t *fun, void *iface, 427 429 ipc_callid_t callid, ipc_call_t *call) … … 444 446 } 445 447 } 446 /*----------------------------------------------------------------------------*/ 448 447 449 void remote_usbhc_release_address(ddf_fun_t *fun, void *iface, 448 450 ipc_callid_t callid, ipc_call_t *call) … … 460 462 async_answer_0(callid, ret); 461 463 } 462 /*----------------------------------------------------------------------------*/ 464 463 465 static void callback_out(ddf_fun_t *fun, 464 466 int outcome, void *arg) … … 470 472 async_transaction_destroy(trans); 471 473 } 472 /*----------------------------------------------------------------------------*/ 474 473 475 static void callback_in(ddf_fun_t *fun, 474 476 int outcome, size_t actual_size, void *arg) … … 494 496 async_transaction_destroy(trans); 495 497 } 496 /*----------------------------------------------------------------------------*/ 498 497 499 void remote_usbhc_register_endpoint(ddf_fun_t *fun, void *iface, 498 500 ipc_callid_t callid, ipc_call_t *call) … … 594 596 } 595 597 } 596 /*----------------------------------------------------------------------------*/ 598 597 599 void remote_usbhc_write( 598 600 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call) -
uspace/lib/drv/include/audio_mixer_iface.h
rb5d2e57 r03362fbd 39 39 40 40 #include <async.h> 41 #include < bool.h>41 #include <stdbool.h> 42 42 43 43 #include "ddf/driver.h" -
uspace/lib/drv/include/audio_pcm_iface.h
rb5d2e57 r03362fbd 38 38 39 39 #include <async.h> 40 #include < bool.h>40 #include <stdbool.h> 41 41 #include <loc.h> 42 42 #include <pcm/sample_format.h> -
uspace/lib/drv/include/ddf/driver.h
rb5d2e57 r03362fbd 42 42 #include "../dev_iface.h" 43 43 44 typedef struct ddf_dev ddf_dev_t;45 typedef struct ddf_fun ddf_fun_t;46 44 47 45 /* 48 46 * Device 49 47 */ 48 49 typedef struct ddf_dev ddf_dev_t; 50 typedef struct ddf_fun ddf_fun_t; 50 51 51 52 /** Devices operations */ … … 75 76 76 77 /** Device structure */ 77 struct ddf_dev { 78 /** 79 * Globally unique device identifier (assigned to the device by the 80 * device manager). 81 */ 82 devman_handle_t handle; 83 84 /** Reference count */ 85 atomic_t refcnt; 86 87 /** 88 * Session to the parent device driver (if it is different from this 89 * driver) 90 */ 91 async_sess_t *parent_sess; 92 93 /** Device name */ 94 const char *name; 95 96 /** Driver-specific data associated with this device */ 97 void *driver_data; 98 99 /** Link in the list of devices handled by the driver */ 100 link_t link; 101 }; 78 struct ddf_dev; 102 79 103 80 /** Function structure */ 104 struct ddf_fun { 105 /** True if bound to the device manager */ 106 bool bound; 107 108 /** Function indentifier (asigned by device manager) */ 109 devman_handle_t handle; 110 111 /** Reference count */ 112 atomic_t refcnt; 113 114 /** Device which this function belogs to */ 115 ddf_dev_t *dev; 116 117 /** Function type */ 118 fun_type_t ftype; 119 120 /** Function name */ 121 const char *name; 122 123 /** List of device ids for driver matching */ 124 match_id_list_t match_ids; 125 126 /** Driver-specific data associated with this function */ 127 void *driver_data; 128 129 /** Implementation of operations provided by this function */ 130 ddf_dev_ops_t *ops; 131 132 /** Connection handler or @c NULL to use the DDF default handler. */ 133 async_client_conn_t conn_handler; 134 135 /** Link in the list of functions handled by the driver */ 136 link_t link; 137 }; 81 struct ddf_fun; 138 82 139 83 /* … … 167 111 } driver_t; 168 112 113 /** XXX Only to transition USB */ 114 #ifdef _DDF_DATA_IMPLANT 115 extern void ddf_fun_data_implant(ddf_fun_t *, void *); 116 #endif 117 169 118 extern int ddf_driver_main(driver_t *); 170 119 171 120 extern void *ddf_dev_data_alloc(ddf_dev_t *, size_t); 121 extern void *ddf_dev_data_get(ddf_dev_t *); 122 extern devman_handle_t ddf_dev_get_handle(ddf_dev_t *); 123 extern const char *ddf_dev_get_name(ddf_dev_t *); 124 extern async_sess_t *ddf_dev_parent_sess_create(ddf_dev_t *, exch_mgmt_t); 125 extern async_sess_t *ddf_dev_parent_sess_get(ddf_dev_t *); 172 126 extern ddf_fun_t *ddf_fun_create(ddf_dev_t *, fun_type_t, const char *); 127 extern devman_handle_t ddf_fun_get_handle(ddf_fun_t *); 173 128 extern void ddf_fun_destroy(ddf_fun_t *); 174 129 extern void *ddf_fun_data_alloc(ddf_fun_t *, size_t); 130 extern void *ddf_fun_data_get(ddf_fun_t *); 131 extern const char *ddf_fun_get_name(ddf_fun_t *); 132 extern int ddf_fun_set_name(ddf_fun_t *, const char *); 133 extern ddf_dev_t *ddf_fun_get_dev(ddf_fun_t *); 175 134 extern int ddf_fun_bind(ddf_fun_t *); 176 135 extern int ddf_fun_unbind(ddf_fun_t *); … … 178 137 extern int ddf_fun_offline(ddf_fun_t *); 179 138 extern int ddf_fun_add_match_id(ddf_fun_t *, const char *, int); 180 139 extern void ddf_fun_set_ops(ddf_fun_t *, ddf_dev_ops_t *); 140 extern void ddf_fun_set_conn_handler(ddf_fun_t *, async_client_conn_t); 181 141 extern int ddf_fun_add_to_category(ddf_fun_t *, const char *); 182 142 -
uspace/lib/drv/include/ddf/log.h
rb5d2e57 r03362fbd 35 35 36 36 #include <io/log.h> 37 #include <io/verify.h> 37 38 38 extern int ddf_log_init(const char *, log_level_t); 39 extern void ddf_msg(log_level_t, const char *, ...); 39 extern int ddf_log_init(const char *); 40 extern void ddf_msg(log_level_t, const char *, ...) 41 PRINTF_ATTRIBUTE(2, 3); 40 42 41 43 extern void ddf_dump_buffer(char *, size_t, const void *, size_t, size_t, 42 44 size_t); 45 46 #define ddf_log_fatal(msg...) ddf_msg(LVL_FATAL, msg) 47 #define ddf_log_error(msg...) ddf_msg(LVL_ERROR, msg) 48 #define ddf_log_warning(msg...) ddf_msg(LVL_WARN, msg) 49 #define ddf_log_note(msg...) ddf_msg(LVL_NOTE, msg) 50 #define ddf_log_debug(msg...) ddf_msg(LVL_DEBUG, msg) 51 #define ddf_log_verbose(msg...) ddf_msg(LVL_DEBUG2, msg) 43 52 44 53 #endif -
uspace/lib/drv/include/usbhc_iface.h
rb5d2e57 r03362fbd 42 42 #include "ddf/driver.h" 43 43 #include <usb/usb.h> 44 #include < bool.h>44 #include <stdbool.h> 45 45 46 46 int usbhc_request_address(async_exch_t *, usb_address_t *, bool, usb_speed_t);
Note:
See TracChangeset
for help on using the changeset viewer.
