Changeset 62f4212 in mainline
- Timestamp:
- 2011-03-22T10:07:53Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f8e4cb6
- Parents:
- 18b3cfd (diff), b01995b (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. - Files:
-
- 22 added
- 61 edited
- 10 moved
Legend:
- Unmodified
- Added
- Removed
-
.bzrignore
r18b3cfd r62f4212 9 9 _link.ld 10 10 ./*.iso 11 12 ./tools/__pycache__/ 11 13 12 14 ./Makefile.common … … 84 86 ./uspace/drv/test1/test1 85 87 ./uspace/drv/test2/test2 88 ./uspace/drv/ohci/ohci 86 89 ./uspace/drv/ehci-hcd/ehci-hcd 87 90 ./uspace/drv/uhci-hcd/uhci-hcd 88 91 ./uspace/drv/uhci-rhd/uhci-rhd 92 ./uspace/drv/usbflbk/usbflbk 89 93 ./uspace/drv/usbhub/usbhub 90 94 ./uspace/drv/usbhid/usbhid … … 137 141 .cproject 138 142 .project 143 .settings 144 .pydevproject 145 -
boot/arch/amd64/Makefile.inc
r18b3cfd r62f4212 44 44 ns8250 \ 45 45 ehci-hcd \ 46 ohci \ 46 47 uhci-hcd \ 47 48 uhci-rhd \ 49 usbflbk \ 48 50 usbhub \ 49 51 usbhid \ -
kernel/tools/genmap.py
r18b3cfd r62f4212 100 100 for addr, symbol in symbols: 101 101 value = fname + ':' + symbol 102 data = struct.pack(symtabfmt, addr + offset, value[:MAXSTRING]) 102 value_bytes = value.encode('ascii') 103 data = struct.pack(symtabfmt, addr + offset, value_bytes[:MAXSTRING]) 103 104 out.write(data) 104 105 105 out.write(struct.pack(symtabfmt, 0, ''))106 out.write(struct.pack(symtabfmt, 0, b'')) 106 107 107 108 def main(): -
tools/mkfat.py
r18b3cfd r62f4212 211 211 dir_entry = xstruct.create(DIR_ENTRY) 212 212 213 dir_entry.name = mangle_fname(name) 214 dir_entry.ext = mangle_ext(name) 213 dir_entry.name = mangle_fname(name).encode('ascii') 214 dir_entry.ext = mangle_ext(name).encode('ascii') 215 215 216 216 if (directory): … … 239 239 240 240 dir_entry.signature = 0x2e 241 dir_entry.name = ' '242 dir_entry.ext = ' '241 dir_entry.name = b' ' 242 dir_entry.ext = b' ' 243 243 dir_entry.attr = 0x10 244 244 … … 258 258 259 259 dir_entry.signature = [0x2e, 0x2e] 260 dir_entry.name = ' '261 dir_entry.ext = ' '260 dir_entry.name = b' ' 261 dir_entry.ext = b' ' 262 262 dir_entry.attr = 0x10 263 263 -
tools/mkhord.py
r18b3cfd r62f4212 84 84 payload_size_aligned = align_up(payload_size, align) 85 85 86 header.tag = "HORD"86 header.tag = b"HORD" 87 87 header.version = 1 88 88 header.encoding = HORD_LSB -
tools/mktmpfs.py
r18b3cfd r62f4212 80 80 dentry.kind = TMPFS_FILE 81 81 dentry.fname_len = len(name) 82 dentry.fname = name 82 dentry.fname = name.encode('ascii') 83 83 dentry.flen = size 84 84 … … 97 97 dentry.kind = TMPFS_DIRECTORY 98 98 dentry.fname_len = len(name) 99 dentry.fname = name 99 dentry.fname = name.encode('ascii') 100 100 101 101 outf.write(dentry.pack()) … … 122 122 123 123 header = xstruct.create(HEADER) 124 header.tag = "TMPFS"124 header.tag = b"TMPFS" 125 125 126 126 outf.write(header.pack()) -
uspace/Makefile
r18b3cfd r62f4212 118 118 srv/hw/irc/i8259 \ 119 119 drv/ehci-hcd \ 120 drv/ohci \ 120 121 drv/uhci-hcd \ 121 122 drv/uhci-rhd \ 123 drv/usbflbk \ 122 124 drv/usbhid \ 123 125 drv/usbhub \ … … 136 138 srv/hw/irc/i8259 \ 137 139 drv/ehci-hcd \ 140 drv/ohci \ 138 141 drv/uhci-hcd \ 139 142 drv/uhci-rhd \ 143 drv/usbflbk \ 140 144 drv/usbhid \ 141 145 drv/usbhub \ -
uspace/app/bdsh/cmds/modules/bdd/bdd.c
r18b3cfd r62f4212 70 70 unsigned int i, j; 71 71 devmap_handle_t handle; 72 aoff64_t offset; 72 73 uint8_t *blk; 73 74 size_t size, bytes, rows; … … 120 121 } 121 122 123 offset = ba * block_size; 124 122 125 while (size > 0) { 123 126 rc = block_read_direct(handle, ba, 1, blk); … … 133 136 134 137 for (j = 0; j < rows; j++) { 138 printf("[%06" PRIxOFF64 "] ", offset); 135 139 for (i = 0; i < BPR; i++) { 136 140 if (j * BPR + i < bytes) … … 152 156 } 153 157 } 158 offset += BPR; 154 159 putchar('\n'); 155 160 } -
uspace/app/usbinfo/dev.c
r18b3cfd r62f4212 59 59 } 60 60 61 rc = usb_ endpoint_pipe_initialize_default_control(&dev->ctrl_pipe,61 rc = usb_pipe_initialize_default_control(&dev->ctrl_pipe, 62 62 &dev->wire); 63 63 if (rc != EOK) { … … 68 68 } 69 69 70 rc = usb_ endpoint_pipe_probe_default_control(&dev->ctrl_pipe);70 rc = usb_pipe_probe_default_control(&dev->ctrl_pipe); 71 71 if (rc != EOK) { 72 72 fprintf(stderr, … … 76 76 } 77 77 78 rc = usb_ endpoint_pipe_start_session(&dev->ctrl_pipe);78 rc = usb_pipe_start_session(&dev->ctrl_pipe); 79 79 if (rc != EOK) { 80 80 fprintf(stderr, … … 107 107 108 108 leave: 109 if (usb_ endpoint_pipe_is_session_started(&dev->ctrl_pipe)) {110 usb_ endpoint_pipe_end_session(&dev->ctrl_pipe);109 if (usb_pipe_is_session_started(&dev->ctrl_pipe)) { 110 usb_pipe_end_session(&dev->ctrl_pipe); 111 111 } 112 112 … … 118 118 void destroy_device(usbinfo_device_t *dev) 119 119 { 120 usb_ endpoint_pipe_end_session(&dev->ctrl_pipe);120 usb_pipe_end_session(&dev->ctrl_pipe); 121 121 free(dev); 122 122 } -
uspace/app/usbinfo/info.c
r18b3cfd r62f4212 42 42 #include <usb/classes/classes.h> 43 43 #include <usb/classes/hid.h> 44 #include <usb/classes/hub.h> 44 45 #include "usbinfo.h" 45 46 … … 109 110 usb_standard_device_descriptor_t *descriptor) 110 111 { 111 printf("%sDevice (0x%04x by 0x%04x, %s )\n", prefix,112 printf("%sDevice (0x%04x by 0x%04x, %s, %zu configurations)\n", prefix, 112 113 (int) descriptor->product_id, 113 114 (int) descriptor->vendor_id, 114 usb_str_class(descriptor->device_class)); 115 usb_str_class(descriptor->device_class), 116 (size_t) descriptor->configuration_count); 115 117 } 116 118 … … 118 120 usb_standard_configuration_descriptor_t *descriptor) 119 121 { 120 printf("%sConfiguration #%d\n", prefix, 121 (int) descriptor->configuration_number); 122 printf("%sConfiguration #%d (%zu interfaces, total %zuB)\n", prefix, 123 (int) descriptor->configuration_number, 124 (size_t) descriptor->interface_count, 125 (size_t) descriptor->total_length); 122 126 } 123 127 … … 125 129 usb_standard_interface_descriptor_t *descriptor) 126 130 { 127 printf("%sInterface #%d (%s, 0x%02x, 0x%02x) \n", prefix,131 printf("%sInterface #%d (%s, 0x%02x, 0x%02x), alternate %d\n", prefix, 128 132 (int) descriptor->interface_number, 129 133 usb_str_class(descriptor->interface_class), 130 134 (int) descriptor->interface_subclass, 131 (int) descriptor->interface_protocol); 135 (int) descriptor->interface_protocol, 136 (int) descriptor->alternate_setting); 132 137 } 133 138 … … 153 158 } 154 159 155 156 static void dump_descriptor_tree_brief_callback(uint8_t *descriptor, 160 static void dump_descriptor_tree_brief_hub(const char *prefix, 161 usb_hub_descriptor_header_t *descriptor) 162 { 163 printf("%shub (%d ports)\n", prefix, 164 (int) descriptor->port_count); 165 } 166 167 168 static void dump_descriptor_tree_callback(uint8_t *descriptor, 157 169 size_t depth, void *arg) 158 170 { … … 171 183 if (descr_size >= sizeof(descriptor_type)) { \ 172 184 callback(indent, (descriptor_type *) descriptor); \ 185 if (arg != NULL) { \ 186 usb_dump_standard_descriptor(stdout, \ 187 get_indent(depth +2), "\n", \ 188 descriptor, descr_size); \ 189 } \ 173 190 } else { \ 174 191 descr_type = -1; \ … … 191 208 usb_standard_hid_descriptor_t, 192 209 dump_descriptor_tree_brief_hid); 210 /* 211 * Probably useless, hub descriptor shall not be part of 212 * configuration descriptor. 213 */ 214 _BRANCH(USB_DESCTYPE_HUB, 215 usb_hub_descriptor_header_t, 216 dump_descriptor_tree_brief_hub); 193 217 194 218 default: … … 203 227 void dump_descriptor_tree_brief(usbinfo_device_t *dev) 204 228 { 205 dump_descriptor_tree_ brief_callback((uint8_t *)&dev->device_descriptor,229 dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor, 206 230 (size_t) -1, NULL); 207 231 usb_dp_walk_simple(dev->full_configuration_descriptor, 208 232 dev->full_configuration_descriptor_size, 209 233 usb_dp_standard_descriptor_nesting, 210 dump_descriptor_tree_ brief_callback,234 dump_descriptor_tree_callback, 211 235 NULL); 212 236 } 237 238 void dump_descriptor_tree_full(usbinfo_device_t *dev) 239 { 240 dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor, 241 (size_t) -1, dev); 242 usb_dp_walk_simple(dev->full_configuration_descriptor, 243 dev->full_configuration_descriptor_size, 244 usb_dp_standard_descriptor_nesting, 245 dump_descriptor_tree_callback, 246 dev); 247 } 248 213 249 214 250 void dump_strings(usbinfo_device_t *dev) -
uspace/app/usbinfo/main.c
r18b3cfd r62f4212 134 134 _OPTION("-m --match-ids", "Print match ids generated for the device."); 135 135 _OPTION("-t --descriptor-tree", "Print descriptor tree."); 136 _OPTION("-T --descriptor-tree-full", "Print detailed descriptor tree"); 136 137 _OPTION("-s --strings", "Try to print all string descriptors."); 137 138 … … 149 150 {"match-ids", no_argument, NULL, 'm'}, 150 151 {"descriptor-tree", no_argument, NULL, 't'}, 152 {"descriptor-tree-full", no_argument, NULL, 'T'}, 151 153 {"strings", no_argument, NULL, 's'}, 152 154 {0, 0, NULL, 0} 153 155 }; 154 static const char *short_options = "himt s";156 static const char *short_options = "himtTs"; 155 157 156 158 static usbinfo_action_t actions[] = { … … 168 170 .opt = 't', 169 171 .action = dump_descriptor_tree_brief, 172 .active = false 173 }, 174 { 175 .opt = 'T', 176 .action = dump_descriptor_tree_full, 170 177 .active = false 171 178 }, -
uspace/app/usbinfo/usbinfo.h
r18b3cfd r62f4212 44 44 45 45 typedef struct { 46 usb_ endpoint_pipe_t ctrl_pipe;46 usb_pipe_t ctrl_pipe; 47 47 usb_device_connection_t wire; 48 48 usb_standard_device_descriptor_t device_descriptor; … … 82 82 void dump_device_match_ids(usbinfo_device_t *); 83 83 void dump_descriptor_tree_brief(usbinfo_device_t *); 84 void dump_descriptor_tree_full(usbinfo_device_t *); 84 85 void dump_strings(usbinfo_device_t *); 85 86 -
uspace/doc/doxygroups.h
r18b3cfd r62f4212 274 274 */ 275 275 276 276 /** 277 * @defgroup drvusbfallback USB fallback driver. 278 * @ingroup usb 279 * @brief Fallback driver for any USB device. 280 * @details 281 * The purpose of this driver is to simplify querying of unknown 282 * devices from within HelenOS (without a driver, no node at all 283 * may appear under /dev/devices). 284 */ 285 286 -
uspace/drv/ehci-hcd/Makefile
r18b3cfd r62f4212 33 33 34 34 SOURCES = \ 35 hc_iface.c \ 35 36 main.c \ 36 37 pci.c -
uspace/drv/ehci-hcd/main.c
r18b3cfd r62f4212 44 44 45 45 #include "pci.h" 46 47 #define NAME "ehci-hcd" 46 #include "ehci.h" 48 47 49 48 static int ehci_add_device(ddf_dev_t *device); … … 57 56 .driver_ops = &ehci_driver_ops 58 57 }; 58 static ddf_dev_ops_t hc_ops = { 59 .interfaces[USBHC_DEV_IFACE] = &ehci_hc_iface, 60 }; 61 59 62 /*----------------------------------------------------------------------------*/ 60 63 /** Initializes a new ddf driver instance of EHCI hcd. … … 71 74 return ret; \ 72 75 } 73 74 usb_log_info("uhci_add_device() called\n");75 76 76 77 uintptr_t mem_reg_base = 0; … … 89 90 "Failed(%d) disable legacy USB: %s.\n", ret, str_error(ret)); 90 91 92 ddf_fun_t *hc_fun = ddf_fun_create(device, fun_exposed, "ehci-hc"); 93 if (hc_fun == NULL) { 94 usb_log_error("Failed to create EHCI function.\n"); 95 return ENOMEM; 96 } 97 hc_fun->ops = &hc_ops; 98 ret = ddf_fun_bind(hc_fun); 99 100 CHECK_RET_RETURN(ret, 101 "Failed to bind EHCI function: %s.\n", 102 str_error(ret)); 103 104 usb_log_info("Controlling new EHCI device `%s' (handle %llu).\n", 105 device->name, device->handle); 106 91 107 return EOK; 92 108 #undef CHECK_RET_RETURN … … 103 119 int main(int argc, char *argv[]) 104 120 { 105 usb_log_enable(USB_LOG_LEVEL_ ERROR, NAME);121 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 106 122 return ddf_driver_main(&ehci_driver); 107 123 } -
uspace/drv/ohci/hc.h
r18b3cfd r62f4212 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 29 /** @addtogroup drvusbuhcihc 28 /** @addtogroup drvusbohci 30 29 * @{ 31 30 */ 32 31 /** @file 33 * @brief UHCI driver32 * @brief OHCI host controller driver structure 34 33 */ 35 #ifndef UTILS_DEVICE_KEEPER_H 36 #define UTILS_DEVICE_KEEPER_H 37 #include <devman.h> 34 #ifndef DRV_OHCI_HC_H 35 #define DRV_OHCI_HC_H 36 37 #include <fibril.h> 38 38 #include <fibril_synch.h> 39 #include <adt/list.h> 40 #include <ddi.h> 41 39 42 #include <usb/usb.h> 43 #include <usb/host/device_keeper.h> 44 #include <usbhc_iface.h> 40 45 41 #define USB_ADDRESS_COUNT (USB11_ADDRESS_MAX + 1) 46 #include "batch.h" 47 #include "ohci_regs.h" 48 #include "root_hub.h" 42 49 43 struct usb_device_info { 44 usb_speed_t speed; 45 bool occupied; 46 uint16_t toggle_status; 47 devman_handle_t handle; 48 }; 50 typedef struct hc { 51 ohci_regs_t *registers; 52 usb_address_t rh_address; 53 rh_t rh; 54 ddf_fun_t *ddf_instance; 55 usb_device_keeper_t manager; 56 fid_t interrupt_emulator; 57 } hc_t; 49 58 50 typedef struct device_keeper { 51 struct usb_device_info devices[USB_ADDRESS_COUNT]; 52 fibril_mutex_t guard; 53 fibril_condvar_t default_address_occupied; 54 usb_address_t last_address; 55 } device_keeper_t; 59 int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev, 60 uintptr_t regs, size_t reg_size, bool interrupts); 56 61 57 void device_keeper_init(device_keeper_t *instance);62 int hc_register_hub(hc_t *instance); 58 63 59 void device_keeper_reserve_default( 60 device_keeper_t *instance, usb_speed_t speed); 64 int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch); 61 65 62 void device_keeper_release_default(device_keeper_t *instance);66 void hc_interrupt(hc_t *instance, uint32_t status); 63 67 64 void device_keeper_reset_if_need( 65 device_keeper_t *instance, usb_target_t target, const unsigned char *setup_data); 68 /** Safely dispose host controller internal structures 69 * 70 * @param[in] instance Host controller structure to use. 71 */ 72 static inline void hc_fini(hc_t *instance) { /* TODO: implement*/ }; 66 73 67 int device_keeper_get_toggle(device_keeper_t *instance, usb_target_t target); 68 69 int device_keeper_set_toggle( 70 device_keeper_t *instance, usb_target_t target, bool toggle); 71 72 usb_address_t device_keeper_request( 73 device_keeper_t *instance, usb_speed_t speed); 74 75 void device_keeper_bind( 76 device_keeper_t *instance, usb_address_t address, devman_handle_t handle); 77 78 void device_keeper_release(device_keeper_t *instance, usb_address_t address); 79 80 usb_address_t device_keeper_find( 81 device_keeper_t *instance, devman_handle_t handle); 82 83 usb_speed_t device_keeper_speed( 84 device_keeper_t *instance, usb_address_t address); 74 /** Get and cast pointer to the driver data 75 * 76 * @param[in] fun DDF function pointer 77 * @return cast pointer to driver_data 78 */ 79 static inline hc_t * fun_to_hc(ddf_fun_t *fun) 80 { return (hc_t*)fun->driver_data; } 85 81 #endif 86 82 /** -
uspace/drv/uhci-hcd/Makefile
r18b3cfd r62f4212 37 37 transfer_list.c \ 38 38 uhci.c \ 39 uhci_hc.c \ 40 uhci_rh.c \ 41 uhci_struct/transfer_descriptor.c \ 42 utils/device_keeper.c \ 39 hc.c \ 40 root_hub.c \ 41 hw_struct/transfer_descriptor.c \ 43 42 pci.c \ 44 43 batch.c -
uspace/drv/uhci-hcd/batch.c
r18b3cfd r62f4212 40 40 #include "batch.h" 41 41 #include "transfer_list.h" 42 #include " uhci_hc.h"42 #include "hw_struct/transfer_descriptor.h" 43 43 #include "utils/malloc32.h" 44 44 45 45 #define DEFAULT_ERROR_COUNT 3 46 46 47 static void batch_control(batch_t *instance, 47 typedef struct uhci_batch { 48 qh_t *qh; 49 td_t *tds; 50 size_t packets; 51 usb_device_keeper_t *manager; 52 } uhci_batch_t; 53 54 static void batch_control(usb_transfer_batch_t *instance, 48 55 usb_packet_id data_stage, usb_packet_id status_stage); 49 static void batch_data(batch_t *instance, usb_packet_id pid); 50 static void batch_call_in(batch_t *instance); 51 static void batch_call_out(batch_t *instance); 52 static void batch_call_in_and_dispose(batch_t *instance); 53 static void batch_call_out_and_dispose(batch_t *instance); 56 static void batch_data(usb_transfer_batch_t *instance, usb_packet_id pid); 57 static void batch_call_in_and_dispose(usb_transfer_batch_t *instance); 58 static void batch_call_out_and_dispose(usb_transfer_batch_t *instance); 54 59 55 60 … … 76 81 * transaction and callback. 77 82 */ 78 batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,83 usb_transfer_batch_t * batch_get(ddf_fun_t *fun, usb_target_t target, 79 84 usb_transfer_type_t transfer_type, size_t max_packet_size, 80 usb_speed_t speed, char *buffer, size_t size,85 usb_speed_t speed, char *buffer, size_t buffer_size, 81 86 char* setup_buffer, size_t setup_size, 82 87 usbhc_iface_transfer_in_callback_t func_in, 83 88 usbhc_iface_transfer_out_callback_t func_out, void *arg, 84 device_keeper_t *manager89 usb_device_keeper_t *manager 85 90 ) 86 91 { … … 97 102 } else (void)0 98 103 99 batch_t *instance = malloc(sizeof(batch_t));104 usb_transfer_batch_t *instance = malloc(sizeof(usb_transfer_batch_t)); 100 105 CHECK_NULL_DISPOSE_RETURN(instance, 101 106 "Failed to allocate batch instance.\n"); 102 bzero(instance, sizeof(batch_t)); 103 104 instance->qh = malloc32(sizeof(qh_t)); 105 CHECK_NULL_DISPOSE_RETURN(instance->qh, 107 usb_transfer_batch_init(instance, target, transfer_type, speed, max_packet_size, 108 buffer, NULL, buffer_size, NULL, setup_size, func_in, 109 func_out, arg, fun, NULL); 110 111 112 uhci_batch_t *data = malloc(sizeof(uhci_batch_t)); 113 CHECK_NULL_DISPOSE_RETURN(instance, 114 "Failed to allocate batch instance.\n"); 115 bzero(data, sizeof(uhci_batch_t)); 116 data->manager = manager; 117 instance->private_data = data; 118 119 data->packets = (buffer_size + max_packet_size - 1) / max_packet_size; 120 if (transfer_type == USB_TRANSFER_CONTROL) { 121 data->packets += 2; 122 } 123 124 data->tds = malloc32(sizeof(td_t) * data->packets); 125 CHECK_NULL_DISPOSE_RETURN( 126 data->tds, "Failed to allocate transfer descriptors.\n"); 127 bzero(data->tds, sizeof(td_t) * data->packets); 128 129 data->qh = malloc32(sizeof(qh_t)); 130 CHECK_NULL_DISPOSE_RETURN(data->qh, 106 131 "Failed to allocate batch queue head.\n"); 107 qh_init(instance->qh); 108 109 instance->packets = (size + max_packet_size - 1) / max_packet_size; 110 if (transfer_type == USB_TRANSFER_CONTROL) { 111 instance->packets += 2; 112 } 113 114 instance->tds = malloc32(sizeof(td_t) * instance->packets); 115 CHECK_NULL_DISPOSE_RETURN( 116 instance->tds, "Failed to allocate transfer descriptors.\n"); 117 bzero(instance->tds, sizeof(td_t) * instance->packets); 118 119 if (size > 0) { 120 instance->transport_buffer = malloc32(size); 132 qh_init(data->qh); 133 qh_set_element_td(data->qh, addr_to_phys(data->tds)); 134 135 if (buffer_size > 0) { 136 instance->transport_buffer = malloc32(buffer_size); 121 137 CHECK_NULL_DISPOSE_RETURN(instance->transport_buffer, 122 138 "Failed to allocate device accessible buffer.\n"); … … 130 146 } 131 147 132 133 link_initialize(&instance->link);134 135 instance->max_packet_size = max_packet_size;136 instance->target = target;137 instance->transfer_type = transfer_type;138 instance->buffer = buffer;139 instance->buffer_size = size;140 instance->setup_size = setup_size;141 instance->fun = fun;142 instance->arg = arg;143 instance->speed = speed;144 instance->manager = manager;145 instance->callback_out = func_out;146 instance->callback_in = func_in;147 148 qh_set_element_td(instance->qh, addr_to_phys(instance->tds));149 150 148 usb_log_debug("Batch(%p) %d:%d memory structures ready.\n", 151 149 instance, target.address, target.endpoint); … … 153 151 } 154 152 /*----------------------------------------------------------------------------*/ 155 /** Mark batch as failed and continue with next step.156 *157 * @param[in] instance Batch structure to use.158 *159 */160 void batch_abort(batch_t *instance)161 {162 assert(instance);163 instance->error = EIO;164 instance->next_step(instance);165 }166 /*----------------------------------------------------------------------------*/167 153 /** Check batch TDs for activity. 168 154 * … … 174 160 * is reached. 175 161 */ 176 bool batch_is_complete(batch_t *instance) 177 { 178 assert(instance); 162 bool batch_is_complete(usb_transfer_batch_t *instance) 163 { 164 assert(instance); 165 uhci_batch_t *data = instance->private_data; 166 assert(data); 167 179 168 usb_log_debug2("Batch(%p) checking %d packet(s) for completion.\n", 180 instance, instance->packets);169 instance, data->packets); 181 170 instance->transfered_size = 0; 182 171 size_t i = 0; 183 for (;i < instance->packets; ++i) {184 if (td_is_active(& instance->tds[i])) {172 for (;i < data->packets; ++i) { 173 if (td_is_active(&data->tds[i])) { 185 174 return false; 186 175 } 187 176 188 instance->error = td_status(& instance->tds[i]);177 instance->error = td_status(&data->tds[i]); 189 178 if (instance->error != EOK) { 190 179 usb_log_debug("Batch(%p) found error TD(%d):%x.\n", 191 instance, i, instance->tds[i].status); 192 td_print_status(&instance->tds[i]); 193 194 device_keeper_set_toggle(instance->manager, 195 instance->target, td_toggle(&instance->tds[i])); 180 instance, i, data->tds[i].status); 181 td_print_status(&data->tds[i]); 182 183 usb_device_keeper_set_toggle(data->manager, 184 instance->target, instance->direction, 185 td_toggle(&data->tds[i])); 196 186 if (i > 0) 197 187 goto substract_ret; … … 199 189 } 200 190 201 instance->transfered_size += td_act_size(& instance->tds[i]);202 if (td_is_short(& instance->tds[i]))191 instance->transfered_size += td_act_size(&data->tds[i]); 192 if (td_is_short(&data->tds[i])) 203 193 goto substract_ret; 204 194 } … … 214 204 * Uses genercir control function with pids OUT and IN. 215 205 */ 216 void batch_control_write( batch_t *instance)206 void batch_control_write(usb_transfer_batch_t *instance) 217 207 { 218 208 assert(instance); … … 231 221 * Uses generic control with pids IN and OUT. 232 222 */ 233 void batch_control_read( batch_t *instance)223 void batch_control_read(usb_transfer_batch_t *instance) 234 224 { 235 225 assert(instance); … … 245 235 * Data transaction with PID_IN. 246 236 */ 247 void batch_interrupt_in(batch_t *instance) 248 { 249 assert(instance); 237 void batch_interrupt_in(usb_transfer_batch_t *instance) 238 { 239 assert(instance); 240 instance->direction = USB_DIRECTION_IN; 250 241 batch_data(instance, USB_PID_IN); 251 242 instance->next_step = batch_call_in_and_dispose; … … 259 250 * Data transaction with PID_OUT. 260 251 */ 261 void batch_interrupt_out(batch_t *instance) 262 { 263 assert(instance); 252 void batch_interrupt_out(usb_transfer_batch_t *instance) 253 { 254 assert(instance); 255 instance->direction = USB_DIRECTION_OUT; 264 256 /* We are data out, we are supposed to provide data */ 265 257 memcpy(instance->transport_buffer, instance->buffer, … … 276 268 * Data transaction with PID_IN. 277 269 */ 278 void batch_bulk_in( batch_t *instance)270 void batch_bulk_in(usb_transfer_batch_t *instance) 279 271 { 280 272 assert(instance); 281 273 batch_data(instance, USB_PID_IN); 274 instance->direction = USB_DIRECTION_IN; 282 275 instance->next_step = batch_call_in_and_dispose; 283 276 usb_log_debug("Batch(%p) BULK IN initialized.\n", instance); … … 290 283 * Data transaction with PID_OUT. 291 284 */ 292 void batch_bulk_out(batch_t *instance) 293 { 294 assert(instance); 285 void batch_bulk_out(usb_transfer_batch_t *instance) 286 { 287 assert(instance); 288 instance->direction = USB_DIRECTION_OUT; 295 289 /* We are data out, we are supposed to provide data */ 296 290 memcpy(instance->transport_buffer, instance->buffer, … … 309 303 * The last packet is marked with IOC flag. 310 304 */ 311 void batch_data(batch_t *instance, usb_packet_id pid) 312 { 313 assert(instance); 305 void batch_data(usb_transfer_batch_t *instance, usb_packet_id pid) 306 { 307 assert(instance); 308 uhci_batch_t *data = instance->private_data; 309 assert(data); 310 314 311 const bool low_speed = instance->speed == USB_SPEED_LOW; 315 int toggle = 316 d evice_keeper_get_toggle(instance->manager, instance->target);312 int toggle = usb_device_keeper_get_toggle( 313 data->manager, instance->target, instance->direction); 317 314 assert(toggle == 0 || toggle == 1); 318 315 … … 320 317 size_t remain_size = instance->buffer_size; 321 318 while (remain_size > 0) { 322 char * data =319 char *trans_data = 323 320 instance->transport_buffer + instance->buffer_size 324 321 - remain_size; … … 328 325 remain_size : instance->max_packet_size; 329 326 330 td_t *next_packet = (packet + 1 < instance->packets)331 ? & instance->tds[packet + 1] : NULL;332 333 assert(packet < instance->packets);327 td_t *next_packet = (packet + 1 < data->packets) 328 ? &data->tds[packet + 1] : NULL; 329 330 assert(packet < data->packets); 334 331 assert(packet_size <= remain_size); 335 332 336 333 td_init( 337 & instance->tds[packet], DEFAULT_ERROR_COUNT, packet_size,338 toggle, false, low_speed, instance->target, pid, data,334 &data->tds[packet], DEFAULT_ERROR_COUNT, packet_size, 335 toggle, false, low_speed, instance->target, pid, trans_data, 339 336 next_packet); 340 337 … … 344 341 ++packet; 345 342 } 346 td_set_ioc(&instance->tds[packet - 1]); 347 device_keeper_set_toggle(instance->manager, instance->target, toggle); 343 td_set_ioc(&data->tds[packet - 1]); 344 usb_device_keeper_set_toggle(data->manager, instance->target, 345 instance->direction, toggle); 348 346 } 349 347 /*----------------------------------------------------------------------------*/ … … 359 357 * The last packet is marked with IOC. 360 358 */ 361 void batch_control( batch_t *instance,359 void batch_control(usb_transfer_batch_t *instance, 362 360 usb_packet_id data_stage, usb_packet_id status_stage) 363 361 { 364 362 assert(instance); 363 uhci_batch_t *data = instance->private_data; 364 assert(data); 365 assert(data->packets >= 2); 365 366 366 367 const bool low_speed = instance->speed == USB_SPEED_LOW; 367 368 int toggle = 0; 368 369 /* setup stage */ 369 td_init(instance->tds, DEFAULT_ERROR_COUNT, 370 instance->setup_size, toggle, false, low_speed, instance->target, 371 USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]); 370 td_init( 371 data->tds, DEFAULT_ERROR_COUNT, instance->setup_size, toggle, false, 372 low_speed, instance->target, USB_PID_SETUP, instance->setup_buffer, 373 &data->tds[1]); 372 374 373 375 /* data stage */ … … 375 377 size_t remain_size = instance->buffer_size; 376 378 while (remain_size > 0) { 377 char * data =379 char *control_data = 378 380 instance->transport_buffer + instance->buffer_size 379 381 - remain_size; … … 386 388 387 389 td_init( 388 & instance->tds[packet], DEFAULT_ERROR_COUNT, packet_size,390 &data->tds[packet], DEFAULT_ERROR_COUNT, packet_size, 389 391 toggle, false, low_speed, instance->target, data_stage, 390 data, &instance->tds[packet + 1]);392 control_data, &data->tds[packet + 1]); 391 393 392 394 ++packet; 393 assert(packet < instance->packets);395 assert(packet < data->packets); 394 396 assert(packet_size <= remain_size); 395 397 remain_size -= packet_size; … … 397 399 398 400 /* status stage */ 399 assert(packet == instance->packets - 1); 400 td_init(&instance->tds[packet], DEFAULT_ERROR_COUNT, 401 0, 1, false, low_speed, instance->target, status_stage, NULL, NULL); 402 403 td_set_ioc(&instance->tds[packet]); 401 assert(packet == data->packets - 1); 402 403 td_init( 404 &data->tds[packet], DEFAULT_ERROR_COUNT, 0, 1, false, low_speed, 405 instance->target, status_stage, NULL, NULL); 406 td_set_ioc(&data->tds[packet]); 407 404 408 usb_log_debug2("Control last TD status: %x.\n", 405 instance->tds[packet].status); 406 } 407 /*----------------------------------------------------------------------------*/ 408 /** Prepare data, get error status and call callback in. 409 * 410 * @param[in] instance Batch structure to use. 411 * Copies data from transport buffer, and calls callback with appropriate 412 * parameters. 413 */ 414 void batch_call_in(batch_t *instance) 415 { 416 assert(instance); 417 assert(instance->callback_in); 418 419 /* We are data in, we need data */ 420 memcpy(instance->buffer, instance->transport_buffer, 421 instance->buffer_size); 422 423 int err = instance->error; 424 usb_log_debug("Batch(%p) callback IN(type:%d): %s(%d), %zu.\n", 425 instance, instance->transfer_type, str_error(err), err, 426 instance->transfered_size); 427 428 instance->callback_in( 429 instance->fun, err, instance->transfered_size, instance->arg); 430 } 431 /*----------------------------------------------------------------------------*/ 432 /** Get error status and call callback out. 433 * 434 * @param[in] instance Batch structure to use. 435 */ 436 void batch_call_out(batch_t *instance) 437 { 438 assert(instance); 439 assert(instance->callback_out); 440 441 int err = instance->error; 442 usb_log_debug("Batch(%p) callback OUT(type:%d): %s(%d).\n", 443 instance, instance->transfer_type, str_error(err), err); 444 instance->callback_out(instance->fun, 445 err, instance->arg); 409 data->tds[packet].status); 410 } 411 /*----------------------------------------------------------------------------*/ 412 qh_t * batch_qh(usb_transfer_batch_t *instance) 413 { 414 assert(instance); 415 uhci_batch_t *data = instance->private_data; 416 assert(data); 417 return data->qh; 446 418 } 447 419 /*----------------------------------------------------------------------------*/ … … 450 422 * @param[in] instance Batch structure to use. 451 423 */ 452 void batch_call_in_and_dispose( batch_t *instance)453 { 454 assert(instance); 455 batch_call_in(instance);424 void batch_call_in_and_dispose(usb_transfer_batch_t *instance) 425 { 426 assert(instance); 427 usb_transfer_batch_call_in(instance); 456 428 batch_dispose(instance); 457 429 } … … 461 433 * @param[in] instance Batch structure to use. 462 434 */ 463 void batch_call_out_and_dispose( batch_t *instance)464 { 465 assert(instance); 466 batch_call_out(instance);435 void batch_call_out_and_dispose(usb_transfer_batch_t *instance) 436 { 437 assert(instance); 438 usb_transfer_batch_call_out(instance); 467 439 batch_dispose(instance); 468 440 } … … 472 444 * @param[in] instance Batch structure to use. 473 445 */ 474 void batch_dispose(batch_t *instance) 475 { 476 assert(instance); 446 void batch_dispose(usb_transfer_batch_t *instance) 447 { 448 assert(instance); 449 uhci_batch_t *data = instance->private_data; 450 assert(data); 477 451 usb_log_debug("Batch(%p) disposing.\n", instance); 478 452 /* free32 is NULL safe */ 479 free32( instance->tds);480 free32( instance->qh);453 free32(data->tds); 454 free32(data->qh); 481 455 free32(instance->setup_buffer); 482 456 free32(instance->transport_buffer); 457 free(data); 483 458 free(instance); 484 459 } -
uspace/drv/uhci-hcd/batch.h
r18b3cfd r62f4212 39 39 #include <usbhc_iface.h> 40 40 #include <usb/usb.h> 41 #include <usb/host/device_keeper.h> 42 #include <usb/host/batch.h> 41 43 42 #include "uhci_struct/transfer_descriptor.h" 43 #include "uhci_struct/queue_head.h" 44 #include "utils/device_keeper.h" 44 #include "hw_struct/queue_head.h" 45 45 46 typedef struct batch 47 { 48 link_t link; 49 usb_speed_t speed; 50 usb_target_t target; 51 usb_transfer_type_t transfer_type; 52 usbhc_iface_transfer_in_callback_t callback_in; 53 usbhc_iface_transfer_out_callback_t callback_out; 54 void *arg; 55 char *transport_buffer; 56 char *setup_buffer; 57 size_t setup_size; 58 char *buffer; 59 size_t buffer_size; 60 size_t max_packet_size; 61 size_t packets; 62 size_t transfered_size; 63 int error; 64 ddf_fun_t *fun; 65 qh_t *qh; 66 td_t *tds; 67 void (*next_step)(struct batch*); 68 device_keeper_t *manager; 69 } batch_t; 70 71 batch_t * batch_get( 46 usb_transfer_batch_t * batch_get( 72 47 ddf_fun_t *fun, 73 48 usb_target_t target, … … 82 57 usbhc_iface_transfer_out_callback_t func_out, 83 58 void *arg, 84 device_keeper_t *manager59 usb_device_keeper_t *manager 85 60 ); 86 61 87 void batch_dispose( batch_t *instance);62 void batch_dispose(usb_transfer_batch_t *instance); 88 63 89 void batch_abort(batch_t *instance);64 bool batch_is_complete(usb_transfer_batch_t *instance); 90 65 91 bool batch_is_complete(batch_t *instance);66 void batch_control_write(usb_transfer_batch_t *instance); 92 67 93 void batch_control_ write(batch_t *instance);68 void batch_control_read(usb_transfer_batch_t *instance); 94 69 95 void batch_ control_read(batch_t *instance);70 void batch_interrupt_in(usb_transfer_batch_t *instance); 96 71 97 void batch_interrupt_ in(batch_t *instance);72 void batch_interrupt_out(usb_transfer_batch_t *instance); 98 73 99 void batch_ interrupt_out(batch_t *instance);74 void batch_bulk_in(usb_transfer_batch_t *instance); 100 75 101 void batch_bulk_ in(batch_t *instance);76 void batch_bulk_out(usb_transfer_batch_t *instance); 102 77 103 void batch_bulk_out(batch_t *instance);78 qh_t * batch_qh(usb_transfer_batch_t *instance); 104 79 #endif 105 80 /** -
uspace/drv/uhci-hcd/hc.c
r18b3cfd r62f4212 42 42 #include <usb_iface.h> 43 43 44 #include " uhci_hc.h"44 #include "hc.h" 45 45 46 46 static irq_cmd_t uhci_cmds[] = { … … 60 60 }; 61 61 /*----------------------------------------------------------------------------*/ 62 static int uhci_hc_init_transfer_lists(uhci_hc_t *instance);63 static int uhci_hc_init_mem_structures(uhci_hc_t *instance);64 static void uhci_hc_init_hw(uhci_hc_t *instance);65 66 static int uhci_hc_interrupt_emulator(void *arg);67 static int uhci_hc_debug_checker(void *arg);62 static int hc_init_transfer_lists(hc_t *instance); 63 static int hc_init_mem_structures(hc_t *instance); 64 static void hc_init_hw(hc_t *instance); 65 66 static int hc_interrupt_emulator(void *arg); 67 static int hc_debug_checker(void *arg); 68 68 69 69 static bool allowed_usb_packet( … … 82 82 * interrupt fibrils. 83 83 */ 84 int uhci_hc_init(uhci_hc_t *instance, ddf_fun_t *fun,84 int hc_init(hc_t *instance, ddf_fun_t *fun, 85 85 void *regs, size_t reg_size, bool interrupts) 86 86 { … … 112 112 io, reg_size); 113 113 114 ret = uhci_hc_init_mem_structures(instance);114 ret = hc_init_mem_structures(instance); 115 115 CHECK_RET_DEST_FUN_RETURN(ret, 116 116 "Failed to initialize UHCI memory structures.\n"); 117 117 118 uhci_hc_init_hw(instance);118 hc_init_hw(instance); 119 119 if (!interrupts) { 120 120 instance->cleaner = 121 fibril_create( uhci_hc_interrupt_emulator, instance);121 fibril_create(hc_interrupt_emulator, instance); 122 122 fibril_add_ready(instance->cleaner); 123 } 124 125 instance->debug_checker = fibril_create(uhci_hc_debug_checker, instance); 126 fibril_add_ready(instance->debug_checker); 127 128 usb_log_info("Started UHCI driver.\n"); 123 } else { 124 /* TODO: enable interrupts here */ 125 } 126 127 instance->debug_checker = 128 fibril_create(hc_debug_checker, instance); 129 // fibril_add_ready(instance->debug_checker); 130 129 131 return EOK; 130 132 #undef CHECK_RET_DEST_FUN_RETURN … … 136 138 * For magic values see UHCI Design Guide 137 139 */ 138 void uhci_hc_init_hw(uhci_hc_t *instance)140 void hc_init_hw(hc_t *instance) 139 141 { 140 142 assert(instance); … … 184 186 * - frame list page (needs to be one UHCI hw accessible 4K page) 185 187 */ 186 int uhci_hc_init_mem_structures(uhci_hc_t *instance)188 int hc_init_mem_structures(hc_t *instance) 187 189 { 188 190 assert(instance); … … 213 215 214 216 /* Init transfer lists */ 215 ret = uhci_hc_init_transfer_lists(instance);217 ret = hc_init_transfer_lists(instance); 216 218 CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to init transfer lists.\n"); 217 219 usb_log_debug("Initialized transfer lists.\n"); … … 234 236 235 237 /* Init device keeper*/ 236 device_keeper_init(&instance->device_manager);238 usb_device_keeper_init(&instance->manager); 237 239 usb_log_debug("Initialized device manager.\n"); 238 240 … … 250 252 * USB scheduling. Sets pointer table for quick access. 251 253 */ 252 int uhci_hc_init_transfer_lists(uhci_hc_t *instance)254 int hc_init_transfer_lists(hc_t *instance) 253 255 { 254 256 assert(instance); … … 316 318 * Checks for bandwidth availability and appends the batch to the proper queue. 317 319 */ 318 int uhci_hc_schedule(uhci_hc_t *instance,batch_t *batch)320 int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch) 319 321 { 320 322 assert(instance); … … 349 351 * - resume from suspend state (not implemented) 350 352 */ 351 void uhci_hc_interrupt(uhci_hc_t *instance, uint16_t status)353 void hc_interrupt(hc_t *instance, uint16_t status) 352 354 { 353 355 assert(instance); … … 371 373 if (instance->hw_failures < UHCI_ALLOWED_HW_FAIL) { 372 374 /* reinitialize hw, this triggers virtual disconnect*/ 373 uhci_hc_init_hw(instance);375 hc_init_hw(instance); 374 376 } else { 375 377 usb_log_fatal("Too many UHCI hardware failures!.\n"); 376 uhci_hc_fini(instance);378 hc_fini(instance); 377 379 } 378 380 } … … 384 386 * @return EOK (should never return) 385 387 */ 386 int uhci_hc_interrupt_emulator(void* arg)388 int hc_interrupt_emulator(void* arg) 387 389 { 388 390 usb_log_debug("Started interrupt emulator.\n"); 389 uhci_hc_t *instance = (uhci_hc_t*)arg;391 hc_t *instance = (hc_t*)arg; 390 392 assert(instance); 391 393 … … 396 398 if (status != 0) 397 399 usb_log_debug2("UHCI status: %x.\n", status); 398 uhci_hc_interrupt(instance, status);400 hc_interrupt(instance, status); 399 401 async_usleep(UHCI_CLEANER_TIMEOUT); 400 402 } … … 407 409 * @return EOK (should never return) 408 410 */ 409 int uhci_hc_debug_checker(void *arg)410 { 411 uhci_hc_t *instance = (uhci_hc_t*)arg;411 int hc_debug_checker(void *arg) 412 { 413 hc_t *instance = (hc_t*)arg; 412 414 assert(instance); 413 415 -
uspace/drv/uhci-hcd/hc.h
r18b3cfd r62f4212 42 42 43 43 #include <usbhc_iface.h> 44 #include <usb/host/device_keeper.h> 44 45 45 46 #include "batch.h" 46 47 #include "transfer_list.h" 47 #include "utils/device_keeper.h"48 48 49 49 typedef struct uhci_regs { … … 82 82 #define UHCI_ALLOWED_HW_FAIL 5 83 83 84 typedef struct uhci_hc {85 device_keeper_t device_manager;84 typedef struct hc { 85 usb_device_keeper_t manager; 86 86 87 87 regs_t *registers; … … 104 104 105 105 ddf_fun_t *ddf_instance; 106 } uhci_hc_t;106 } hc_t; 107 107 108 int uhci_hc_init(uhci_hc_t *instance, ddf_fun_t *fun,108 int hc_init(hc_t *instance, ddf_fun_t *fun, 109 109 void *regs, size_t reg_size, bool interupts); 110 110 111 int uhci_hc_schedule(uhci_hc_t *instance,batch_t *batch);111 int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch); 112 112 113 void uhci_hc_interrupt(uhci_hc_t *instance, uint16_t status);113 void hc_interrupt(hc_t *instance, uint16_t status); 114 114 115 115 /** Safely dispose host controller internal structures … … 117 117 * @param[in] instance Host controller structure to use. 118 118 */ 119 static inline void uhci_hc_fini(uhci_hc_t *instance) { /* TODO: implement*/ };119 static inline void hc_fini(hc_t *instance) { /* TODO: implement*/ }; 120 120 121 121 /** Get and cast pointer to the driver data … … 124 124 * @return cast pointer to driver_data 125 125 */ 126 static inline uhci_hc_t * fun_to_uhci_hc(ddf_fun_t *fun)127 { return ( uhci_hc_t*)fun->driver_data; }126 static inline hc_t * fun_to_hc(ddf_fun_t *fun) 127 { return (hc_t*)fun->driver_data; } 128 128 #endif 129 129 /** -
uspace/drv/uhci-hcd/hw_struct/link_pointer.h
r18b3cfd r62f4212 49 49 ((address & LINK_POINTER_ADDRESS_MASK) | LINK_POINTER_QUEUE_HEAD_FLAG) 50 50 51 #define LINK_POINTER_TD(address) \ 52 (address & LINK_POINTER_ADDRESS_MASK) 53 54 #define LINK_POINTER_TERM \ 55 ((link_pointer_t)LINK_POINTER_TERMINATE_FLAG) 56 51 57 #endif 52 58 /** -
uspace/drv/uhci-hcd/hw_struct/queue_head.h
r18b3cfd r62f4212 72 72 /* Address is valid and not terminal */ 73 73 if (pa && ((pa & LINK_POINTER_TERMINATE_FLAG) == 0)) { 74 instance->next = (pa & LINK_POINTER_ADDRESS_MASK) 75 | LINK_POINTER_QUEUE_HEAD_FLAG; 74 instance->next = LINK_POINTER_QH(pa); 76 75 } else { 77 instance->next = 0 | LINK_POINTER_TERMINATE_FLAG;76 instance->next = LINK_POINTER_TERM; 78 77 } 79 78 } … … 91 90 /* Address is valid and not terminal */ 92 91 if (pa && ((pa & LINK_POINTER_TERMINATE_FLAG) == 0)) { 93 instance->element = (pa & LINK_POINTER_ADDRESS_MASK) 94 | LINK_POINTER_QUEUE_HEAD_FLAG; 92 instance->element = LINK_POINTER_QH(pa); 95 93 } else { 96 instance->element = 0 | LINK_POINTER_TERMINATE_FLAG;94 instance->element = LINK_POINTER_TERM; 97 95 } 98 96 } … … 109 107 { 110 108 if (pa && ((pa & LINK_POINTER_TERMINATE_FLAG) == 0)) { 111 instance->element = (pa & LINK_POINTER_ADDRESS_MASK);109 instance->element = LINK_POINTER_TD(pa); 112 110 } else { 113 instance->element = 0 | LINK_POINTER_TERMINATE_FLAG;111 instance->element = LINK_POINTER_TERM; 114 112 } 115 113 } -
uspace/drv/uhci-hcd/hw_struct/transfer_descriptor.c
r18b3cfd r62f4212 69 69 || (pid == USB_PID_OUT)); 70 70 71 const uint32_t next_pa = addr_to_phys(next); 72 assert((next_pa & LINK_POINTER_ADDRESS_MASK) == next_pa); 73 71 74 instance->next = 0 72 75 | LINK_POINTER_VERTICAL_FLAG 73 | ( (next != NULL) ? addr_to_phys(next): LINK_POINTER_TERMINATE_FLAG);76 | (next_pa ? next_pa : LINK_POINTER_TERMINATE_FLAG); 74 77 75 78 instance->status = 0 … … 90 93 | ((pid & TD_DEVICE_PID_MASK) << TD_DEVICE_PID_POS); 91 94 92 instance->buffer_ptr = 0; 93 94 if (size) { 95 instance->buffer_ptr = (uintptr_t)addr_to_phys(buffer); 96 } 95 instance->buffer_ptr = addr_to_phys(buffer); 97 96 98 97 usb_log_debug2("Created TD(%p): %X:%X:%X:%X(%p).\n", … … 115 114 assert(instance); 116 115 117 if ((instance->status & TD_STATUS_ERROR_STALLED) != 0) 118 return ESTALL; 116 /* this is hc internal error it should never be reported */ 117 if ((instance->status & TD_STATUS_ERROR_BIT_STUFF) != 0) 118 return EAGAIN; 119 119 120 /* CRC or timeout error, like device not present or bad data, 121 * it won't be reported unless err count reached zero */ 120 122 if ((instance->status & TD_STATUS_ERROR_CRC) != 0) 121 123 return EBADCHECKSUM; 122 124 123 if ((instance->status & TD_STATUS_ERROR_BUFFER) != 0) 125 /* hc does not end transaction on these, it should never be reported */ 126 if ((instance->status & TD_STATUS_ERROR_NAK) != 0) 124 127 return EAGAIN; 125 128 129 /* buffer overrun or underrun */ 130 if ((instance->status & TD_STATUS_ERROR_BUFFER) != 0) 131 return ERANGE; 132 133 /* device babble is something serious */ 126 134 if ((instance->status & TD_STATUS_ERROR_BABBLE) != 0) 127 135 return EIO; 128 136 129 if ((instance->status & TD_STATUS_ERROR_NAK) != 0) 130 return EAGAIN; 131 132 if ((instance->status & TD_STATUS_ERROR_BIT_STUFF) != 0) 133 return EAGAIN; 137 /* stall might represent err count reaching zero or stall response from 138 * the device, is err count reached zero, one of the above is reported*/ 139 if ((instance->status & TD_STATUS_ERROR_STALLED) != 0) 140 return ESTALL; 134 141 135 142 return EOK; -
uspace/drv/uhci-hcd/iface.c
r18b3cfd r62f4212 33 33 */ 34 34 #include <ddf/driver.h> 35 #include < remote_usbhc.h>35 #include <errno.h> 36 36 37 37 #include <usb/debug.h> 38 38 39 #include <errno.h>40 41 39 #include "iface.h" 42 #include "uhci_hc.h" 43 #include "utils/device_keeper.h" 40 #include "hc.h" 44 41 45 42 /** Reserve default address interface function … … 49 46 * @return Error code. 50 47 */ 51 /*----------------------------------------------------------------------------*/52 48 static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed) 53 49 { 54 50 assert(fun); 55 uhci_hc_t *hc = fun_to_uhci_hc(fun);51 hc_t *hc = fun_to_hc(fun); 56 52 assert(hc); 57 53 usb_log_debug("Default address request with speed %d.\n", speed); 58 device_keeper_reserve_default(&hc->device_manager, speed);54 usb_device_keeper_reserve_default_address(&hc->manager, speed); 59 55 return EOK; 60 56 } … … 68 64 { 69 65 assert(fun); 70 uhci_hc_t *hc = fun_to_uhci_hc(fun);66 hc_t *hc = fun_to_hc(fun); 71 67 assert(hc); 72 68 usb_log_debug("Default address release.\n"); 73 device_keeper_release_default(&hc->device_manager);69 usb_device_keeper_release_default_address(&hc->manager); 74 70 return EOK; 75 71 } … … 82 78 * @return Error code. 83 79 */ 84 static int request_address( ddf_fun_t *fun, usb_speed_t speed,85 usb_address_t *address)86 { 87 assert(fun); 88 uhci_hc_t *hc = fun_to_uhci_hc(fun);80 static int request_address( 81 ddf_fun_t *fun, usb_speed_t speed, usb_address_t *address) 82 { 83 assert(fun); 84 hc_t *hc = fun_to_hc(fun); 89 85 assert(hc); 90 86 assert(address); 91 87 92 88 usb_log_debug("Address request with speed %d.\n", speed); 93 *address = device_keeper_ request(&hc->device_manager, speed);89 *address = device_keeper_get_free_address(&hc->manager, speed); 94 90 usb_log_debug("Address request with result: %d.\n", *address); 95 91 if (*address <= 0) 96 92 return *address; 97 93 return EOK; 98 94 } … … 109 105 { 110 106 assert(fun); 111 uhci_hc_t *hc = fun_to_uhci_hc(fun);107 hc_t *hc = fun_to_hc(fun); 112 108 assert(hc); 113 109 usb_log_debug("Address bind %d-%d.\n", address, handle); 114 device_keeper_bind(&hc->device_manager, address, handle);110 usb_device_keeper_bind(&hc->manager, address, handle); 115 111 return EOK; 116 112 } … … 125 121 { 126 122 assert(fun); 127 uhci_hc_t *hc = fun_to_uhci_hc(fun);123 hc_t *hc = fun_to_hc(fun); 128 124 assert(hc); 129 125 usb_log_debug("Address release %d.\n", address); 130 device_keeper_release(&hc->device_manager, address);126 usb_device_keeper_release(&hc->manager, address); 131 127 return EOK; 132 128 } … … 143 139 * @return Error code. 144 140 */ 145 static int interrupt_out(ddf_fun_t *fun, usb_target_t target, 146 size_t max_packet_size, void *data, size_t size, 147 usbhc_iface_transfer_out_callback_t callback, void *arg) 148 { 149 assert(fun); 150 uhci_hc_t *hc = fun_to_uhci_hc(fun); 151 assert(hc); 152 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address); 141 static int interrupt_out( 142 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data, 143 size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg) 144 { 145 assert(fun); 146 hc_t *hc = fun_to_hc(fun); 147 assert(hc); 148 usb_speed_t speed = 149 usb_device_keeper_get_speed(&hc->manager, target.address); 153 150 154 151 usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n", 155 152 target.address, target.endpoint, size, max_packet_size); 156 153 157 batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,158 max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,159 &hc->device_manager);154 usb_transfer_batch_t *batch = 155 batch_get(fun, target, USB_TRANSFER_INTERRUPT, max_packet_size, 156 speed, data, size, NULL, 0, NULL, callback, arg, &hc->manager); 160 157 if (!batch) 161 158 return ENOMEM; 162 159 batch_interrupt_out(batch); 163 const int ret = uhci_hc_schedule(hc, batch); 164 if (ret != EOK) { 165 batch_dispose(batch); 166 return ret; 167 } 168 return EOK; 160 const int ret = hc_schedule(hc, batch); 161 if (ret != EOK) { 162 batch_dispose(batch); 163 } 164 return ret; 169 165 } 170 166 /*----------------------------------------------------------------------------*/ … … 180 176 * @return Error code. 181 177 */ 182 static int interrupt_in(ddf_fun_t *fun, usb_target_t target, 183 size_t max_packet_size, void *data, size_t size, 184 usbhc_iface_transfer_in_callback_t callback, void *arg) 185 { 186 assert(fun); 187 uhci_hc_t *hc = fun_to_uhci_hc(fun); 188 assert(hc); 189 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address); 178 static int interrupt_in( 179 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data, 180 size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg) 181 { 182 assert(fun); 183 hc_t *hc = fun_to_hc(fun); 184 assert(hc); 185 usb_speed_t speed = 186 usb_device_keeper_get_speed(&hc->manager, target.address); 190 187 usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n", 191 188 target.address, target.endpoint, size, max_packet_size); 192 189 193 batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,194 max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,195 &hc->device_manager);190 usb_transfer_batch_t *batch = 191 batch_get(fun, target, USB_TRANSFER_INTERRUPT, max_packet_size, 192 speed, data, size, NULL, 0, callback, NULL, arg, &hc->manager); 196 193 if (!batch) 197 194 return ENOMEM; 198 195 batch_interrupt_in(batch); 199 const int ret = uhci_hc_schedule(hc, batch); 200 if (ret != EOK) { 201 batch_dispose(batch); 202 return ret; 203 } 204 return EOK; 196 const int ret = hc_schedule(hc, batch); 197 if (ret != EOK) { 198 batch_dispose(batch); 199 } 200 return ret; 205 201 } 206 202 /*----------------------------------------------------------------------------*/ … … 216 212 * @return Error code. 217 213 */ 218 static int bulk_out(ddf_fun_t *fun, usb_target_t target, 219 size_t max_packet_size, void *data, size_t size, 220 usbhc_iface_transfer_out_callback_t callback, void *arg) 221 { 222 assert(fun); 223 uhci_hc_t *hc = fun_to_uhci_hc(fun); 224 assert(hc); 225 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address); 214 static int bulk_out( 215 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data, 216 size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg) 217 { 218 assert(fun); 219 hc_t *hc = fun_to_hc(fun); 220 assert(hc); 221 usb_speed_t speed = 222 usb_device_keeper_get_speed(&hc->manager, target.address); 226 223 227 224 usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n", 228 225 target.address, target.endpoint, size, max_packet_size); 229 226 230 batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,231 max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,232 &hc->device_manager);227 usb_transfer_batch_t *batch = 228 batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed, 229 data, size, NULL, 0, NULL, callback, arg, &hc->manager); 233 230 if (!batch) 234 231 return ENOMEM; 235 232 batch_bulk_out(batch); 236 const int ret = uhci_hc_schedule(hc, batch); 237 if (ret != EOK) { 238 batch_dispose(batch); 239 return ret; 240 } 241 return EOK; 233 const int ret = hc_schedule(hc, batch); 234 if (ret != EOK) { 235 batch_dispose(batch); 236 } 237 return ret; 242 238 } 243 239 /*----------------------------------------------------------------------------*/ … … 253 249 * @return Error code. 254 250 */ 255 static int bulk_in(ddf_fun_t *fun, usb_target_t target, 256 size_t max_packet_size, void *data, size_t size, 257 usbhc_iface_transfer_in_callback_t callback, void *arg) 258 { 259 assert(fun); 260 uhci_hc_t *hc = fun_to_uhci_hc(fun); 261 assert(hc); 262 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address); 251 static int bulk_in( 252 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data, 253 size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg) 254 { 255 assert(fun); 256 hc_t *hc = fun_to_hc(fun); 257 assert(hc); 258 usb_speed_t speed = 259 usb_device_keeper_get_speed(&hc->manager, target.address); 263 260 usb_log_debug("Bulk IN %d:%d %zu(%zu).\n", 264 261 target.address, target.endpoint, size, max_packet_size); 265 262 266 batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,267 max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,268 &hc->device_manager);263 usb_transfer_batch_t *batch = 264 batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed, 265 data, size, NULL, 0, callback, NULL, arg, &hc->manager); 269 266 if (!batch) 270 267 return ENOMEM; 271 268 batch_bulk_in(batch); 272 const int ret = uhci_hc_schedule(hc, batch); 273 if (ret != EOK) { 274 batch_dispose(batch); 275 return ret; 276 } 277 return EOK; 269 const int ret = hc_schedule(hc, batch); 270 if (ret != EOK) { 271 batch_dispose(batch); 272 } 273 return ret; 278 274 } 279 275 /*----------------------------------------------------------------------------*/ … … 291 287 * @return Error code. 292 288 */ 293 static int control_write( ddf_fun_t *fun, usb_target_t target,294 size_t max_packet_size,289 static int control_write( 290 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, 295 291 void *setup_data, size_t setup_size, void *data, size_t size, 296 292 usbhc_iface_transfer_out_callback_t callback, void *arg) 297 293 { 298 294 assert(fun); 299 uhci_hc_t *hc = fun_to_uhci_hc(fun); 300 assert(hc); 301 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address); 295 hc_t *hc = fun_to_hc(fun); 296 assert(hc); 297 usb_speed_t speed = 298 usb_device_keeper_get_speed(&hc->manager, target.address); 302 299 usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n", 303 300 speed, target.address, target.endpoint, size, max_packet_size); … … 306 303 return EINVAL; 307 304 308 batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL, 309 max_packet_size, speed, data, size, setup_data, setup_size, 310 NULL, callback, arg, &hc->device_manager); 311 if (!batch) 312 return ENOMEM; 313 device_keeper_reset_if_need(&hc->device_manager, target, setup_data); 305 usb_transfer_batch_t *batch = 306 batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed, 307 data, size, setup_data, setup_size, NULL, callback, arg, 308 &hc->manager); 309 if (!batch) 310 return ENOMEM; 311 usb_device_keeper_reset_if_need(&hc->manager, target, setup_data); 314 312 batch_control_write(batch); 315 const int ret = uhci_hc_schedule(hc, batch); 316 if (ret != EOK) { 317 batch_dispose(batch); 318 return ret; 319 } 320 return EOK; 313 const int ret = hc_schedule(hc, batch); 314 if (ret != EOK) { 315 batch_dispose(batch); 316 } 317 return ret; 321 318 } 322 319 /*----------------------------------------------------------------------------*/ … … 334 331 * @return Error code. 335 332 */ 336 static int control_read( ddf_fun_t *fun, usb_target_t target,337 size_t max_packet_size,333 static int control_read( 334 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, 338 335 void *setup_data, size_t setup_size, void *data, size_t size, 339 336 usbhc_iface_transfer_in_callback_t callback, void *arg) 340 337 { 341 338 assert(fun); 342 uhci_hc_t *hc = fun_to_uhci_hc(fun); 343 assert(hc); 344 usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address); 339 hc_t *hc = fun_to_hc(fun); 340 assert(hc); 341 usb_speed_t speed = 342 usb_device_keeper_get_speed(&hc->manager, target.address); 345 343 346 344 usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n", 347 345 speed, target.address, target.endpoint, size, max_packet_size); 348 batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL, 349 max_packet_size, speed, data, size, setup_data, setup_size, callback, 350 NULL, arg, &hc->device_manager); 346 usb_transfer_batch_t *batch = 347 batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed, 348 data, size, setup_data, setup_size, callback, NULL, arg, 349 &hc->manager); 351 350 if (!batch) 352 351 return ENOMEM; 353 352 batch_control_read(batch); 354 const int ret = uhci_hc_schedule(hc, batch); 355 if (ret != EOK) { 356 batch_dispose(batch); 357 return ret; 358 } 359 return EOK; 360 } 361 /*----------------------------------------------------------------------------*/ 362 usbhc_iface_t uhci_hc_iface = { 353 const int ret = hc_schedule(hc, batch); 354 if (ret != EOK) { 355 batch_dispose(batch); 356 } 357 return ret; 358 } 359 /*----------------------------------------------------------------------------*/ 360 usbhc_iface_t hc_iface = { 363 361 .reserve_default_address = reserve_default_address, 364 362 .release_default_address = release_default_address, … … 370 368 .interrupt_in = interrupt_in, 371 369 370 .bulk_out = bulk_out, 372 371 .bulk_in = bulk_in, 373 .bulk_out = bulk_out, 374 372 373 .control_write = control_write, 375 374 .control_read = control_read, 376 .control_write = control_write,377 375 }; 378 376 /** -
uspace/drv/uhci-hcd/iface.h
r18b3cfd r62f4212 38 38 #include <usbhc_iface.h> 39 39 40 extern usbhc_iface_t uhci_hc_iface;40 extern usbhc_iface_t hc_iface; 41 41 42 42 #endif -
uspace/drv/uhci-hcd/main.c
r18b3cfd r62f4212 62 62 int uhci_add_device(ddf_dev_t *device) 63 63 { 64 usb_log_ info("uhci_add_device() called\n");64 usb_log_debug("uhci_add_device() called\n"); 65 65 assert(device); 66 66 uhci_t *uhci = malloc(sizeof(uhci_t)); … … 72 72 int ret = uhci_init(uhci, device); 73 73 if (ret != EOK) { 74 usb_log_error("Failed to initialzie UHCI driver.\n"); 74 usb_log_error("Failed to initialize UHCI driver: %s.\n", 75 str_error(ret)); 75 76 return ret; 76 77 } 77 78 device->driver_data = uhci; 79 80 usb_log_info("Controlling new UHCI device `%s'.\n", device->name); 81 78 82 return EOK; 79 83 } … … 89 93 int main(int argc, char *argv[]) 90 94 { 95 printf(NAME ": HelenOS UHCI driver.\n"); 96 91 97 sleep(3); /* TODO: remove in final version */ 92 usb_log_enable(USB_LOG_LEVEL_DE BUG, NAME);98 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 93 99 94 100 return ddf_driver_main(&uhci_driver); -
uspace/drv/uhci-hcd/root_hub.c
r18b3cfd r62f4212 39 39 #include <usb/debug.h> 40 40 41 #include "uhci_rh.h" 42 #include "uhci_hc.h" 41 #include "root_hub.h" 43 42 44 43 /** Root hub initialization … … 49 48 * @return Error code. 50 49 */ 51 int uhci_rh_init(52 uhci_rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size)50 int rh_init( 51 rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size) 53 52 { 54 53 assert(fun); -
uspace/drv/uhci-hcd/root_hub.h
r18b3cfd r62f4212 39 39 #include <ops/hw_res.h> 40 40 41 typedef struct uhci_rh {41 typedef struct rh { 42 42 hw_resource_list_t resource_list; 43 43 hw_resource_t io_regs; 44 } uhci_rh_t;44 } rh_t; 45 45 46 int uhci_rh_init(47 uhci_rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size);46 int rh_init( 47 rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size); 48 48 49 49 #endif -
uspace/drv/uhci-hcd/transfer_list.c
r18b3cfd r62f4212 38 38 39 39 static void transfer_list_remove_batch( 40 transfer_list_t *instance, batch_t *batch);40 transfer_list_t *instance, usb_transfer_batch_t *batch); 41 41 /*----------------------------------------------------------------------------*/ 42 42 /** Initialize transfer list structures. … … 79 79 if (!instance->queue_head) 80 80 return; 81 /* Set both next and element to point to the same QH*/81 /* Set both queue_head.next to point to the follower */ 82 82 qh_set_next_qh(instance->queue_head, next->queue_head_pa); 83 qh_set_element_qh(instance->queue_head, next->queue_head_pa);84 83 } 85 84 /*----------------------------------------------------------------------------*/ … … 92 91 * The batch is added to the end of the list and queue. 93 92 */ 94 void transfer_list_add_batch(transfer_list_t *instance, batch_t *batch)93 void transfer_list_add_batch(transfer_list_t *instance, usb_transfer_batch_t *batch) 95 94 { 96 95 assert(instance); … … 98 97 usb_log_debug2("Queue %s: Adding batch(%p).\n", instance->name, batch); 99 98 100 const uint32_t pa = addr_to_phys(batch->qh);101 assert((pa & LINK_POINTER_ADDRESS_MASK) == pa);102 103 /* New batch will be added to the end of the current list104 * so set the link accordingly */105 qh_set_next_qh(batch->qh, instance->queue_head->next);106 107 99 fibril_mutex_lock(&instance->guard); 108 100 101 qh_t *last_qh = NULL; 109 102 /* Add to the hardware queue. */ 110 103 if (list_empty(&instance->batch_list)) { 111 104 /* There is nothing scheduled */ 112 qh_t *qh = instance->queue_head; 113 assert(qh->element == qh->next); 114 qh_set_element_qh(qh, pa); 105 last_qh = instance->queue_head; 115 106 } else { 116 107 /* There is something scheduled */ 117 batch_t *last = list_get_instance( 118 instance->batch_list.prev, batch_t, link); 119 qh_set_next_qh(last->qh, pa); 120 } 108 usb_transfer_batch_t *last = list_get_instance( 109 instance->batch_list.prev, usb_transfer_batch_t, link); 110 last_qh = batch_qh(last); 111 } 112 const uint32_t pa = addr_to_phys(batch_qh(batch)); 113 assert((pa & LINK_POINTER_ADDRESS_MASK) == pa); 114 115 /* keep link */ 116 batch_qh(batch)->next = last_qh->next; 117 qh_set_next_qh(last_qh, pa); 118 121 119 /* Add to the driver list */ 122 120 list_append(&batch->link, &instance->batch_list); 123 121 124 batch_t *first = list_get_instance(125 instance->batch_list.next, batch_t, link);122 usb_transfer_batch_t *first = list_get_instance( 123 instance->batch_list.next, usb_transfer_batch_t, link); 126 124 usb_log_debug("Batch(%p) added to queue %s, first is %p.\n", 127 125 batch, instance->name, first); … … 148 146 while (current != &instance->batch_list) { 149 147 link_t *next = current->next; 150 batch_t *batch = list_get_instance(current,batch_t, link);148 usb_transfer_batch_t *batch = list_get_instance(current, usb_transfer_batch_t, link); 151 149 152 150 if (batch_is_complete(batch)) { … … 162 160 link_t *item = done.next; 163 161 list_remove(item); 164 batch_t *batch = list_get_instance(item,batch_t, link);162 usb_transfer_batch_t *batch = list_get_instance(item, usb_transfer_batch_t, link); 165 163 batch->next_step(batch); 166 164 } … … 174 172 { 175 173 fibril_mutex_lock(&instance->guard); 176 while ( list_empty(&instance->batch_list)) {174 while (!list_empty(&instance->batch_list)) { 177 175 link_t *current = instance->batch_list.next; 178 batch_t *batch = list_get_instance(current,batch_t, link);176 usb_transfer_batch_t *batch = list_get_instance(current, usb_transfer_batch_t, link); 179 177 transfer_list_remove_batch(instance, batch); 180 batch_abort(batch);178 usb_transfer_batch_finish(batch, EIO); 181 179 } 182 180 fibril_mutex_unlock(&instance->guard); … … 191 189 * Does not lock the transfer list, caller is responsible for that. 192 190 */ 193 void transfer_list_remove_batch(transfer_list_t *instance, batch_t *batch) 194 { 195 assert(instance); 191 void transfer_list_remove_batch(transfer_list_t *instance, usb_transfer_batch_t *batch) 192 { 193 assert(instance); 194 assert(instance->queue_head); 196 195 assert(batch); 197 assert(instance->queue_head); 198 assert(batch->qh); 196 assert(batch_qh(batch)); 197 assert(fibril_mutex_is_locked(&instance->guard)); 198 199 199 usb_log_debug2( 200 200 "Queue %s: removing batch(%p).\n", instance->name, batch); 201 201 202 const char * 202 const char *qpos = NULL; 203 203 /* Remove from the hardware queue */ 204 if ( batch->link.prev == &instance->batch_list) {204 if (instance->batch_list.next == &batch->link) { 205 205 /* I'm the first one here */ 206 qh_set_element_qh(instance->queue_head, batch->qh->next); 207 pos = "FIRST"; 206 assert((instance->queue_head->next & LINK_POINTER_ADDRESS_MASK) 207 == addr_to_phys(batch_qh(batch))); 208 instance->queue_head->next = batch_qh(batch)->next; 209 qpos = "FIRST"; 208 210 } else { 209 batch_t *prev = 210 list_get_instance(batch->link.prev, batch_t, link); 211 qh_set_next_qh(prev->qh, batch->qh->next); 212 pos = "NOT FIRST"; 213 } 214 /* Remove from the driver list */ 211 usb_transfer_batch_t *prev = 212 list_get_instance(batch->link.prev, usb_transfer_batch_t, link); 213 assert((batch_qh(prev)->next & LINK_POINTER_ADDRESS_MASK) 214 == addr_to_phys(batch_qh(batch))); 215 batch_qh(prev)->next = batch_qh(batch)->next; 216 qpos = "NOT FIRST"; 217 } 218 /* Remove from the batch list */ 215 219 list_remove(&batch->link); 216 usb_log_debug("Batch(%p) removed (%s) from %s, next element%x.\n",217 batch, pos, instance->name, batch->qh->next);220 usb_log_debug("Batch(%p) removed (%s) from %s, next %x.\n", 221 batch, qpos, instance->name, batch_qh(batch)->next); 218 222 } 219 223 /** -
uspace/drv/uhci-hcd/transfer_list.h
r18b3cfd r62f4212 37 37 #include <fibril_synch.h> 38 38 39 #include "uhci_struct/queue_head.h"40 41 39 #include "batch.h" 40 #include "hw_struct/queue_head.h" 42 41 43 42 typedef struct transfer_list … … 66 65 void transfer_list_set_next(transfer_list_t *instance, transfer_list_t *next); 67 66 68 void transfer_list_add_batch(transfer_list_t *instance, batch_t *batch);67 void transfer_list_add_batch(transfer_list_t *instance, usb_transfer_batch_t *batch); 69 68 70 69 void transfer_list_remove_finished(transfer_list_t *instance); -
uspace/drv/uhci-hcd/uhci.c
r18b3cfd r62f4212 54 54 { 55 55 assert(dev); 56 uhci_hc_t *hc = &((uhci_t*)dev->driver_data)->hc;56 hc_t *hc = &((uhci_t*)dev->driver_data)->hc; 57 57 uint16_t status = IPC_GET_ARG1(*call); 58 58 assert(hc); 59 uhci_hc_interrupt(hc, status);59 hc_interrupt(hc, status); 60 60 } 61 61 /*----------------------------------------------------------------------------*/ … … 70 70 { 71 71 assert(fun); 72 device_keeper_t *manager = &((uhci_t*)fun->dev->driver_data)->hc.device_manager;73 74 usb_address_t addr = device_keeper_find(manager, handle);72 usb_device_keeper_t *manager = &((uhci_t*)fun->dev->driver_data)->hc.manager; 73 74 usb_address_t addr = usb_device_keeper_find(manager, handle); 75 75 if (addr < 0) { 76 76 return addr; … … 107 107 }; 108 108 /*----------------------------------------------------------------------------*/ 109 static ddf_dev_ops_t uhci_hc_ops = {109 static ddf_dev_ops_t hc_ops = { 110 110 .interfaces[USB_DEV_IFACE] = &usb_iface, 111 .interfaces[USBHC_DEV_IFACE] = & uhci_hc_iface, /* see iface.h/c */111 .interfaces[USBHC_DEV_IFACE] = &hc_iface, /* see iface.h/c */ 112 112 }; 113 113 /*----------------------------------------------------------------------------*/ … … 120 120 { 121 121 assert(fun); 122 return &(( uhci_rh_t*)fun->driver_data)->resource_list;122 return &((rh_t*)fun->driver_data)->resource_list; 123 123 } 124 124 /*----------------------------------------------------------------------------*/ … … 128 128 }; 129 129 /*----------------------------------------------------------------------------*/ 130 static ddf_dev_ops_t uhci_rh_ops = {130 static ddf_dev_ops_t rh_ops = { 131 131 .interfaces[USB_DEV_IFACE] = &usb_iface, 132 132 .interfaces[HW_RES_DEV_IFACE] = &hw_res_iface … … 167 167 CHECK_RET_DEST_FUN_RETURN(ret, 168 168 "Failed(%d) to get I/O addresses:.\n", ret, device->handle); 169 usb_log_ info("I/O regs at 0x%X (size %zu), IRQ %d.\n",169 usb_log_debug("I/O regs at 0x%X (size %zu), IRQ %d.\n", 170 170 io_reg_base, io_reg_size, irq); 171 171 … … 190 190 "Failed(%d) to create HC function.\n", ret); 191 191 192 ret = uhci_hc_init(&instance->hc, instance->hc_fun,192 ret = hc_init(&instance->hc, instance->hc_fun, 193 193 (void*)io_reg_base, io_reg_size, interrupts); 194 194 CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to init uhci-hcd.\n", ret); 195 instance->hc_fun->ops = & uhci_hc_ops;195 instance->hc_fun->ops = &hc_ops; 196 196 instance->hc_fun->driver_data = &instance->hc; 197 197 ret = ddf_fun_bind(instance->hc_fun); … … 208 208 if (instance->rh_fun) \ 209 209 ddf_fun_destroy(instance->rh_fun); \ 210 uhci_hc_fini(&instance->hc); \210 hc_fini(&instance->hc); \ 211 211 return ret; \ 212 212 } … … 223 223 "Failed(%d) to create root hub function.\n", ret); 224 224 225 ret = uhci_rh_init(&instance->rh, instance->rh_fun,225 ret = rh_init(&instance->rh, instance->rh_fun, 226 226 (uintptr_t)instance->hc.registers + 0x10, 4); 227 227 CHECK_RET_FINI_RETURN(ret, 228 228 "Failed(%d) to setup UHCI root hub.\n", ret); 229 229 230 instance->rh_fun->ops = & uhci_rh_ops;230 instance->rh_fun->ops = &rh_ops; 231 231 instance->rh_fun->driver_data = &instance->rh; 232 232 ret = ddf_fun_bind(instance->rh_fun); -
uspace/drv/uhci-hcd/uhci.h
r18b3cfd r62f4212 38 38 #include <ddf/driver.h> 39 39 40 #include " uhci_hc.h"41 #include " uhci_rh.h"40 #include "hc.h" 41 #include "root_hub.h" 42 42 43 43 typedef struct uhci { … … 45 45 ddf_fun_t *rh_fun; 46 46 47 uhci_hc_t hc;48 uhci_rh_t rh;47 hc_t hc; 48 rh_t rh; 49 49 } uhci_t; 50 50 -
uspace/drv/uhci-hcd/utils/malloc32.h
r18b3cfd r62f4212 50 50 static inline uintptr_t addr_to_phys(void *addr) 51 51 { 52 if (addr == NULL) 53 return 0; 54 52 55 uintptr_t result; 53 56 int ret = as_get_physical_mapping(addr, &result); -
uspace/drv/uhci-rhd/main.c
r18b3cfd r62f4212 36 36 #include <device/hw_res.h> 37 37 #include <errno.h> 38 #include <str_error.h> 38 39 #include <usb_iface.h> 39 40 #include <usb/ddfiface.h> … … 86 87 int ret = hc_get_my_registers(device, &io_regs, &io_size); 87 88 if (ret != EOK) { 88 usb_log_error("Failed (%d) to get registers from parent hc.",89 ret);90 } 91 usb_log_ info("I/O regs at %#X (size %zu).\n", io_regs, io_size);89 usb_log_error("Failed to get registers from parent HC: %s.\n", 90 str_error(ret)); 91 } 92 usb_log_debug("I/O regs at %#X (size %zu).\n", io_regs, io_size); 92 93 93 94 uhci_root_hub_t *rh = malloc(sizeof(uhci_root_hub_t)); … … 99 100 ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device); 100 101 if (ret != EOK) { 101 usb_log_error("Failed(%d) to initialize driver instance.\n", ret); 102 usb_log_error("Failed to initialize driver instance: %s.\n", 103 str_error(ret)); 102 104 free(rh); 103 105 return ret; … … 105 107 106 108 device->driver_data = rh; 107 usb_log_info(" Sucessfully initialized driver instance for device:%d.\n",108 device-> handle);109 usb_log_info("Controlling root hub `%s' (%llu).\n", 110 device->name, device->handle); 109 111 return EOK; 110 112 } … … 129 131 int main(int argc, char *argv[]) 130 132 { 131 usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME); 133 printf(NAME ": HelenOS UHCI root hub driver.\n"); 134 135 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 136 132 137 return ddf_driver_main(&uhci_rh_driver); 133 138 } -
uspace/drv/uhci-rhd/port.c
r18b3cfd r62f4212 256 256 assert(usb_hc_connection_is_opened(&port->hc_connection)); 257 257 258 usb_log_ info("%s: Detected new device.\n", port->id_string);258 usb_log_debug("%s: Detected new device.\n", port->id_string); 259 259 260 260 usb_address_t dev_addr; … … 270 270 } 271 271 272 usb_log_info(" %s: New device has address %d (handle %zu).\n",273 port-> id_string, dev_addr, port->attached_device);272 usb_log_info("New device at port %u, address %d (handle %llu).\n", 273 port->number, dev_addr, port->attached_device); 274 274 275 275 return EOK; … … 315 315 uhci_port_write_status(port, port_status); 316 316 317 usb_log_ info("%s: %sabled port.\n",317 usb_log_debug("%s: %sabled port.\n", 318 318 port->id_string, enabled ? "En" : "Dis"); 319 319 return EOK; -
uspace/drv/usbhid/hiddev.c
r18b3cfd r62f4212 184 184 * successfuly initialize the structure. 185 185 * 186 * @sa usb_ endpoint_pipe_initialize_from_configuration(),186 * @sa usb_pipe_initialize_from_configuration(), 187 187 * usbhid_dev_get_report_descriptor() 188 188 */ … … 192 192 assert(hid_dev != NULL); 193 193 194 usb_log_ info("Processing descriptors...\n");194 usb_log_debug("Processing descriptors...\n"); 195 195 196 196 int rc; … … 218 218 }; 219 219 220 rc = usb_ endpoint_pipe_initialize_from_configuration(220 rc = usb_pipe_initialize_from_configuration( 221 221 endpoint_mapping, 1, descriptors, descriptors_size, 222 222 &hid_dev->wire); … … 359 359 * @return Other value inherited from one of functions 360 360 * usb_device_connection_initialize_from_device(), 361 * usb_ endpoint_pipe_initialize_default_control(),362 * usb_ endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),361 * usb_pipe_initialize_default_control(), 362 * usb_pipe_start_session(), usb_pipe_end_session(), 363 363 * usbhid_dev_process_descriptors(). 364 364 * … … 368 368 usb_endpoint_description_t *poll_ep_desc) 369 369 { 370 usb_log_ info("Initializing HID device structure.\n");370 usb_log_debug("Initializing HID device structure.\n"); 371 371 372 372 if (hid_dev == NULL) { … … 404 404 * Initialize device pipes. 405 405 */ 406 rc = usb_ endpoint_pipe_initialize_default_control(&hid_dev->ctrl_pipe,406 rc = usb_pipe_initialize_default_control(&hid_dev->ctrl_pipe, 407 407 &hid_dev->wire); 408 408 if (rc != EOK) { … … 411 411 return rc; 412 412 } 413 rc = usb_ endpoint_pipe_probe_default_control(&hid_dev->ctrl_pipe);413 rc = usb_pipe_probe_default_control(&hid_dev->ctrl_pipe); 414 414 if (rc != EOK) { 415 415 usb_log_error("Probing default control pipe failed: %s.\n", … … 430 430 * Get descriptors, parse descriptors and save endpoints. 431 431 */ 432 rc = usb_ endpoint_pipe_start_session(&hid_dev->ctrl_pipe);432 rc = usb_pipe_start_session(&hid_dev->ctrl_pipe); 433 433 if (rc != EOK) { 434 434 usb_log_error("Failed to start session on the control pipe: %s" … … 440 440 if (rc != EOK) { 441 441 /* TODO: end session?? */ 442 usb_ endpoint_pipe_end_session(&hid_dev->ctrl_pipe);442 usb_pipe_end_session(&hid_dev->ctrl_pipe); 443 443 usb_log_error("Failed to process descriptors: %s.\n", 444 444 str_error(rc)); … … 446 446 } 447 447 448 rc = usb_ endpoint_pipe_end_session(&hid_dev->ctrl_pipe);448 rc = usb_pipe_end_session(&hid_dev->ctrl_pipe); 449 449 if (rc != EOK) { 450 450 usb_log_warning("Failed to start session on the control pipe: " … … 454 454 455 455 hid_dev->initialized = 1; 456 usb_log_ info("HID device structure initialized.\n");456 usb_log_debug("HID device structure initialized.\n"); 457 457 458 458 return EOK; -
uspace/drv/usbhid/hiddev.h
r18b3cfd r62f4212 68 68 usb_device_connection_t wire; 69 69 /** USB pipe corresponding to the default Control endpoint. */ 70 usb_ endpoint_pipe_t ctrl_pipe;70 usb_pipe_t ctrl_pipe; 71 71 /** USB pipe corresponding to the Interrupt In (polling) pipe. */ 72 usb_ endpoint_pipe_t poll_pipe;72 usb_pipe_t poll_pipe; 73 73 74 74 /** Polling interval retreived from the Interface descriptor. */ -
uspace/drv/usbhid/hidreq.c
r18b3cfd r62f4212 57 57 * @retval EINVAL if no HID device is given. 58 58 * @return Other value inherited from one of functions 59 * usb_ endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),59 * usb_pipe_start_session(), usb_pipe_end_session(), 60 60 * usb_control_request_set(). 61 61 */ … … 76 76 int rc, sess_rc; 77 77 78 sess_rc = usb_ endpoint_pipe_start_session(&hid_dev->ctrl_pipe);78 sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe); 79 79 if (sess_rc != EOK) { 80 80 usb_log_warning("Failed to start a session: %s.\n", … … 92 92 USB_HIDREQ_SET_REPORT, value, hid_dev->iface, buffer, buf_size); 93 93 94 sess_rc = usb_ endpoint_pipe_end_session(&hid_dev->ctrl_pipe);94 sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe); 95 95 96 96 if (rc != EOK) { … … 119 119 * @retval EINVAL if no HID device is given. 120 120 * @return Other value inherited from one of functions 121 * usb_ endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),121 * usb_pipe_start_session(), usb_pipe_end_session(), 122 122 * usb_control_request_set(). 123 123 */ … … 137 137 int rc, sess_rc; 138 138 139 sess_rc = usb_ endpoint_pipe_start_session(&hid_dev->ctrl_pipe);139 sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe); 140 140 if (sess_rc != EOK) { 141 141 usb_log_warning("Failed to start a session: %s.\n", … … 151 151 USB_HIDREQ_SET_PROTOCOL, protocol, hid_dev->iface, NULL, 0); 152 152 153 sess_rc = usb_ endpoint_pipe_end_session(&hid_dev->ctrl_pipe);153 sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe); 154 154 155 155 if (rc != EOK) { … … 179 179 * @retval EINVAL if no HID device is given. 180 180 * @return Other value inherited from one of functions 181 * usb_ endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),181 * usb_pipe_start_session(), usb_pipe_end_session(), 182 182 * usb_control_request_set(). 183 183 */ … … 197 197 int rc, sess_rc; 198 198 199 sess_rc = usb_ endpoint_pipe_start_session(&hid_dev->ctrl_pipe);199 sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe); 200 200 if (sess_rc != EOK) { 201 201 usb_log_warning("Failed to start a session: %s.\n", … … 213 213 USB_HIDREQ_SET_IDLE, value, hid_dev->iface, NULL, 0); 214 214 215 sess_rc = usb_ endpoint_pipe_end_session(&hid_dev->ctrl_pipe);215 sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe); 216 216 217 217 if (rc != EOK) { … … 244 244 * @retval EINVAL if no HID device is given. 245 245 * @return Other value inherited from one of functions 246 * usb_ endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),246 * usb_pipe_start_session(), usb_pipe_end_session(), 247 247 * usb_control_request_set(). 248 248 */ … … 263 263 int rc, sess_rc; 264 264 265 sess_rc = usb_ endpoint_pipe_start_session(&hid_dev->ctrl_pipe);265 sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe); 266 266 if (sess_rc != EOK) { 267 267 usb_log_warning("Failed to start a session: %s.\n", … … 280 280 actual_size); 281 281 282 sess_rc = usb_ endpoint_pipe_end_session(&hid_dev->ctrl_pipe);282 sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe); 283 283 284 284 if (rc != EOK) { … … 307 307 * @retval EINVAL if no HID device is given. 308 308 * @return Other value inherited from one of functions 309 * usb_ endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),309 * usb_pipe_start_session(), usb_pipe_end_session(), 310 310 * usb_control_request_set(). 311 311 */ … … 325 325 int rc, sess_rc; 326 326 327 sess_rc = usb_ endpoint_pipe_start_session(&hid_dev->ctrl_pipe);327 sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe); 328 328 if (sess_rc != EOK) { 329 329 usb_log_warning("Failed to start a session: %s.\n", … … 342 342 USB_HIDREQ_GET_PROTOCOL, 0, hid_dev->iface, buffer, 1, &actual_size); 343 343 344 sess_rc = usb_ endpoint_pipe_end_session(&hid_dev->ctrl_pipe);344 sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe); 345 345 346 346 if (rc != EOK) { … … 378 378 * @retval EINVAL if no HID device is given. 379 379 * @return Other value inherited from one of functions 380 * usb_ endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),380 * usb_pipe_start_session(), usb_pipe_end_session(), 381 381 * usb_control_request_set(). 382 382 */ … … 396 396 int rc, sess_rc; 397 397 398 sess_rc = usb_ endpoint_pipe_start_session(&hid_dev->ctrl_pipe);398 sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe); 399 399 if (sess_rc != EOK) { 400 400 usb_log_warning("Failed to start a session: %s.\n", … … 415 415 &actual_size); 416 416 417 sess_rc = usb_ endpoint_pipe_end_session(&hid_dev->ctrl_pipe);417 sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe); 418 418 419 419 if (rc != EOK) { -
uspace/drv/usbhid/kbddev.c
r18b3cfd r62f4212 662 662 int rc; 663 663 664 usb_log_ info("Initializing HID/KBD structure...\n");664 usb_log_debug("Initializing HID/KBD structure...\n"); 665 665 666 666 if (kbd_dev == NULL) { … … 742 742 743 743 kbd_dev->initialized = USBHID_KBD_STATUS_INITIALIZED; 744 usb_log_ info("HID/KBD device structure initialized.\n");744 usb_log_debug("HID/KBD device structure initialized.\n"); 745 745 746 746 return EOK; … … 769 769 size_t actual_size; 770 770 771 usb_log_ info("Polling keyboard...\n");771 usb_log_debug("Polling keyboard...\n"); 772 772 773 773 if (!kbd_dev->initialized) { … … 780 780 781 781 while (true) { 782 sess_rc = usb_ endpoint_pipe_start_session(782 sess_rc = usb_pipe_start_session( 783 783 &kbd_dev->hid_dev->poll_pipe); 784 784 if (sess_rc != EOK) { … … 788 788 } 789 789 790 rc = usb_ endpoint_pipe_read(&kbd_dev->hid_dev->poll_pipe,790 rc = usb_pipe_read(&kbd_dev->hid_dev->poll_pipe, 791 791 buffer, BOOTP_BUFFER_SIZE, &actual_size); 792 792 793 sess_rc = usb_ endpoint_pipe_end_session(793 sess_rc = usb_pipe_end_session( 794 794 &kbd_dev->hid_dev->poll_pipe); 795 795 … … 907 907 * Initialize device (get and process descriptors, get address, etc.) 908 908 */ 909 usb_log_ info("Initializing USB/HID KBD device...\n");909 usb_log_debug("Initializing USB/HID KBD device...\n"); 910 910 911 911 usbhid_kbd_t *kbd_dev = usbhid_kbd_new(); … … 926 926 } 927 927 928 usb_log_ info("USB/HID KBD device structure initialized.\n");928 usb_log_debug("USB/HID KBD device structure initialized.\n"); 929 929 930 930 /* … … 937 937 rc = ddf_fun_bind(kbd_fun); 938 938 if (rc != EOK) { 939 usb_log_error("Could not bind DDF function.\n"); 939 usb_log_error("Could not bind DDF function: %s.\n", 940 str_error(rc)); 940 941 // TODO: Can / should I destroy the DDF function? 941 942 ddf_fun_destroy(kbd_fun); … … 946 947 rc = ddf_fun_add_to_class(kbd_fun, "keyboard"); 947 948 if (rc != EOK) { 948 usb_log_error("Could not add DDF function to class 'keyboard'" 949 "\n"); 949 usb_log_error( 950 "Could not add DDF function to class 'keyboard': %s.\n", 951 str_error(rc)); 950 952 // TODO: Can / should I destroy the DDF function? 951 953 ddf_fun_destroy(kbd_fun); … … 959 961 fid_t fid = fibril_create(usbhid_kbd_fibril, kbd_dev); 960 962 if (fid == 0) { 961 usb_log_error("Failed to start fibril for KBD device\n"); 963 usb_log_error("Failed to start fibril for `%s' device.\n", 964 dev->name); 962 965 return ENOMEM; 963 966 } -
uspace/drv/usbhid/main.c
r18b3cfd r62f4212 39 39 #include <usb/debug.h> 40 40 #include <errno.h> 41 #include <str_error.h> 41 42 42 43 #include "kbddev.h" … … 64 65 65 66 if (rc != EOK) { 66 usb_log_info("Device is not a supported keyboard.\n"); 67 usb_log_error("Failed to add HID device.\n"); 68 return EREFUSED; 67 usb_log_warning("Device is not a supported keyboard.\n"); 68 usb_log_error("Failed to add HID device: %s.\n", 69 str_error(rc)); 70 return rc; 69 71 } 70 72 73 usb_log_info("Keyboard `%s' ready to use.\n", dev->name); 74 71 75 return EOK; 72 76 } … … 89 93 int main(int argc, char *argv[]) 90 94 { 91 usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME); 95 printf(NAME ": HelenOS USB HID driver.\n"); 96 97 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 98 92 99 return ddf_driver_main(&kbd_driver); 93 100 } -
uspace/drv/usbhub/main.c
r18b3cfd r62f4212 36 36 #include <stdio.h> 37 37 38 #include <usb/devdrv.h> 39 #include <usb/classes/classes.h> 40 38 41 #include "usbhub.h" 39 42 #include "usbhub_private.h" 40 43 41 42 usb_general_list_t usb_hub_list; 43 fibril_mutex_t usb_hub_list_lock; 44 45 static driver_ops_t hub_driver_ops = { 46 .add_device = usb_add_hub_device, 44 /** Hub status-change endpoint description. 45 * 46 * For more information see section 11.15.1 of USB 1.1 specification. 47 */ 48 static usb_endpoint_description_t hub_status_change_endpoint_description = { 49 .transfer_type = USB_TRANSFER_INTERRUPT, 50 .direction = USB_DIRECTION_IN, 51 .interface_class = USB_CLASS_HUB, 52 .interface_subclass = 0, 53 .interface_protocol = 0, 54 .flags = 0 47 55 }; 48 56 49 static driver_t hub_driver = { 50 .name = "usbhub", 51 . driver_ops = &hub_driver_ops57 58 static usb_driver_ops_t usb_hub_driver_ops = { 59 .add_device = usb_hub_add_device 52 60 }; 61 62 static usb_endpoint_description_t *usb_hub_endpoints[] = { 63 &hub_status_change_endpoint_description, 64 NULL 65 }; 66 67 static usb_driver_t usb_hub_driver = { 68 .name = NAME, 69 .ops = &usb_hub_driver_ops, 70 .endpoints = usb_hub_endpoints 71 }; 72 53 73 54 74 int main(int argc, char *argv[]) 55 75 { 56 usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME); 57 dprintf(USB_LOG_LEVEL_INFO, "starting hub driver"); 76 printf(NAME ": HelenOS USB hub driver.\n"); 58 77 59 //this is probably not needed anymore 60 fibril_mutex_initialize(&usb_hub_list_lock); 61 fibril_mutex_lock(&usb_hub_list_lock); 62 usb_lst_init(&usb_hub_list); 63 fibril_mutex_unlock(&usb_hub_list_lock); 78 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 64 79 65 return ddf_driver_main(&hub_driver);80 return usb_driver_main(&usb_hub_driver); 66 81 } 67 82 -
uspace/drv/usbhub/usbhub.c
r18b3cfd r62f4212 53 53 #include "usb/classes/classes.h" 54 54 55 static ddf_dev_ops_t hub_device_ops = {56 .interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl57 };58 59 /** Hub status-change endpoint description60 *61 * For more see usb hub specification in 11.15.1 of62 */63 static usb_endpoint_description_t status_change_endpoint_description = {64 .transfer_type = USB_TRANSFER_INTERRUPT,65 .direction = USB_DIRECTION_IN,66 .interface_class = USB_CLASS_HUB,67 .interface_subclass = 0,68 .interface_protocol = 0,69 .flags = 070 };71 72 55 int usb_hub_control_loop(void * hub_info_param){ 73 56 usb_hub_info_t * hub_info = (usb_hub_info_t*)hub_info_param; … … 78 61 async_usleep(1000 * 1000 );/// \TODO proper number once 79 62 } 80 usb_log_error("something in ctrl loop went wrong, errno %d ",errorCode);63 usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode); 81 64 82 65 return 0; … … 91 74 92 75 /** 93 * Initialize connnections to host controller, device, and device 94 * control endpoint 95 * @param hub 96 * @param device 97 * @return 98 */ 99 static int usb_hub_init_communication(usb_hub_info_t * hub){ 100 usb_log_debug("Initializing hub USB communication (hub->device->handle=%zu).\n", hub->device->handle); 101 int opResult; 102 opResult = usb_device_connection_initialize_from_device( 103 &hub->device_connection, 104 hub->device); 105 if(opResult != EOK){ 106 usb_log_error("could not initialize connection to hc, errno %d",opResult); 107 return opResult; 108 } 109 usb_log_debug("Initializing USB wire abstraction.\n"); 110 opResult = usb_hc_connection_initialize_from_device(&hub->connection, 111 hub->device); 112 if(opResult != EOK){ 113 usb_log_error("could not initialize connection to device, errno %d", 114 opResult); 115 return opResult; 116 } 117 usb_log_debug("Initializing default control pipe.\n"); 118 opResult = usb_endpoint_pipe_initialize_default_control(&hub->endpoints.control, 119 &hub->device_connection); 120 if(opResult != EOK){ 121 usb_log_error("could not initialize connection to device endpoint, errno %d", 122 opResult); 123 return opResult; 124 } 125 126 opResult = usb_endpoint_pipe_probe_default_control(&hub->endpoints.control); 127 if (opResult != EOK) { 128 usb_log_error("failed probing endpoint 0, %d", opResult); 129 return opResult; 130 } 131 132 return EOK; 133 } 134 135 /** 136 * When entering this function, hub->endpoints.control should be active. 137 * @param hub 138 * @return 139 */ 140 static int usb_hub_process_configuration_descriptors( 141 usb_hub_info_t * hub){ 142 if(hub==NULL) { 143 return EINVAL; 144 } 145 int opResult; 146 147 //device descriptor 148 usb_standard_device_descriptor_t std_descriptor; 149 opResult = usb_request_get_device_descriptor(&hub->endpoints.control, 150 &std_descriptor); 151 if(opResult!=EOK){ 152 usb_log_error("could not get device descriptor, %d",opResult); 153 return opResult; 154 } 155 usb_log_info("hub has %d configurations", 156 std_descriptor.configuration_count); 157 if(std_descriptor.configuration_count<1){ 158 usb_log_error("THERE ARE NO CONFIGURATIONS AVAILABLE"); 159 //shouldn`t I return? 160 } 161 162 /* Retrieve full configuration descriptor. */ 163 uint8_t *descriptors = NULL; 164 size_t descriptors_size = 0; 165 opResult = usb_request_get_full_configuration_descriptor_alloc( 166 &hub->endpoints.control, 0, 167 (void **) &descriptors, &descriptors_size); 168 if (opResult != EOK) { 169 usb_log_error("Could not get configuration descriptor: %s.\n", 170 str_error(opResult)); 171 return opResult; 172 } 173 usb_standard_configuration_descriptor_t *config_descriptor 174 = (usb_standard_configuration_descriptor_t *) descriptors; 175 176 /* Set configuration. */ 177 opResult = usb_request_set_configuration(&hub->endpoints.control, 178 config_descriptor->configuration_number); 179 180 if (opResult != EOK) { 181 usb_log_error("Failed to set hub configuration: %s.\n", 182 str_error(opResult)); 183 return opResult; 184 } 185 usb_log_debug("\tused configuration %d", 186 config_descriptor->configuration_number); 187 188 usb_endpoint_mapping_t endpoint_mapping[1] = { 189 { 190 .pipe = &hub->endpoints.status_change, 191 .description = &status_change_endpoint_description, 192 .interface_no = 193 usb_device_get_assigned_interface(hub->device) 194 } 195 }; 196 opResult = usb_endpoint_pipe_initialize_from_configuration( 197 endpoint_mapping, 1, 198 descriptors, descriptors_size, 199 &hub->device_connection); 200 if (opResult != EOK) { 201 usb_log_error("Failed to initialize status change pipe: %s", 202 str_error(opResult)); 203 return opResult; 204 } 205 if (!endpoint_mapping[0].present) { 206 usb_log_error("Not accepting device, " \ 207 "cannot understand what is happenning"); 208 return EREFUSED; 209 } 210 211 free(descriptors); 212 return EOK; 213 214 } 215 216 217 /** 218 * Create hub representation from device information. 219 * @param device 220 * @return pointer to created structure or NULL in case of error 221 */ 222 usb_hub_info_t * usb_create_hub_info(ddf_dev_t * device) { 223 usb_hub_info_t* result = usb_new(usb_hub_info_t); 224 result->device = device; 225 int opResult; 226 opResult = usb_hub_init_communication(result); 227 if(opResult != EOK){ 228 free(result); 229 return NULL; 230 } 231 232 //result->device = device; 233 result->port_count = -1; 234 result->device = device; 76 * create usb_hub_info_t structure 77 * 78 * Does only basic copying of known information into new structure. 79 * @param usb_dev usb device structure 80 * @return basic usb_hub_info_t structure 81 */ 82 static usb_hub_info_t * usb_hub_info_create(usb_device_t * usb_dev) { 83 usb_hub_info_t * result = usb_new(usb_hub_info_t); 84 if(!result) return NULL; 85 result->usb_device = usb_dev; 86 result->status_change_pipe = usb_dev->pipes[0].pipe; 87 result->control_pipe = &usb_dev->ctrl_pipe; 235 88 result->is_default_address_used = false; 236 237 //result->usb_device = usb_new(usb_hcd_attached_device_info_t); 238 size_t received_size; 239 89 return result; 90 } 91 92 /** 93 * Load hub-specific information into hub_info structure. 94 * 95 * Particularly read port count and initialize structure holding port 96 * information. 97 * This function is hub-specific and should be run only after the hub is 98 * configured using usb_hub_set_configuration function. 99 * @param hub_info pointer to structure with usb hub data 100 * @return error code 101 */ 102 static int usb_hub_get_hub_specific_info(usb_hub_info_t * hub_info){ 240 103 // get hub descriptor 241 usb_log_debug("creating serialized descripto n");104 usb_log_debug("creating serialized descriptor\n"); 242 105 void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE); 243 106 usb_hub_descriptor_t * descriptor; 244 usb_log_debug("starting control transaction"); 245 usb_endpoint_pipe_start_session(&result->endpoints.control); 246 opResult = usb_request_set_configuration(&result->endpoints.control, 1); 247 assert(opResult == EOK); 248 249 opResult = usb_request_get_descriptor(&result->endpoints.control, 107 108 /* this was one fix of some bug, should not be needed anymore 109 int opResult = usb_request_set_configuration(&result->endpoints.control, 1); 110 if(opResult!=EOK){ 111 usb_log_error("could not set default configuration, errno %d",opResult); 112 return opResult; 113 } 114 */ 115 size_t received_size; 116 int opResult = usb_request_get_descriptor(&hub_info->usb_device->ctrl_pipe, 250 117 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE, 251 118 USB_DESCTYPE_HUB, 252 119 0, 0, serialized_descriptor, 253 120 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 254 usb_endpoint_pipe_end_session(&result->endpoints.control); 255 256 if (opResult != EOK) { 257 usb_log_error("failed when receiving hub descriptor, badcode = %d", 121 122 if (opResult != EOK) { 123 usb_log_error("failed when receiving hub descriptor, badcode = %d\n", 258 124 opResult); 259 125 free(serialized_descriptor); 260 free(result); 261 return NULL; 262 } 263 usb_log_debug2("deserializing descriptor"); 126 return opResult; 127 } 128 usb_log_debug2("deserializing descriptor\n"); 264 129 descriptor = usb_deserialize_hub_desriptor(serialized_descriptor); 265 130 if(descriptor==NULL){ 266 usb_log_warning("could not deserialize descriptor "); 267 free(result); 268 return NULL; 269 } 270 271 usb_log_info("setting port count to %d",descriptor->ports_count); 272 result->port_count = descriptor->ports_count; 273 result->attached_devs = (usb_hc_attached_device_t*) 274 malloc((result->port_count+1) * sizeof(usb_hc_attached_device_t)); 131 usb_log_warning("could not deserialize descriptor \n"); 132 return opResult; 133 } 134 usb_log_debug("setting port count to %d\n",descriptor->ports_count); 135 hub_info->port_count = descriptor->ports_count; 136 hub_info->attached_devs = (usb_hc_attached_device_t*) 137 malloc((hub_info->port_count+1) * sizeof(usb_hc_attached_device_t)); 275 138 int i; 276 for(i=0;i< result->port_count+1;++i){277 result->attached_devs[i].handle=0;278 result->attached_devs[i].address=0;279 } 280 usb_log_debug2("freeing data ");139 for(i=0;i<hub_info->port_count+1;++i){ 140 hub_info->attached_devs[i].handle=0; 141 hub_info->attached_devs[i].address=0; 142 } 143 usb_log_debug2("freeing data\n"); 281 144 free(serialized_descriptor); 282 145 free(descriptor->devices_removable); 283 146 free(descriptor); 284 285 //finish 286 287 usb_log_info("hub info created"); 288 289 return result; 290 } 291 292 /** 293 * Create hub representation and add it into hub list 294 * @param dev 147 return EOK; 148 } 149 /** 150 * Set configuration of hub 151 * 152 * Check whether there is at least one configuration and sets the first one. 153 * This function should be run prior to running any hub-specific action. 154 * @param hub_info 295 155 * @return 296 156 */ 297 int usb_add_hub_device(ddf_dev_t *dev) { 298 usb_log_info("add_hub_device(handle=%d)", (int) dev->handle); 299 300 //dev->ops = &hub_device_ops; 301 (void) hub_device_ops; 302 303 usb_hub_info_t * hub_info = usb_create_hub_info(dev); 304 if(!hub_info){ 305 return EINTR; 306 } 307 308 int opResult; 309 310 //perform final configurations 311 usb_endpoint_pipe_start_session(&hub_info->endpoints.control); 312 // process descriptors 313 opResult = usb_hub_process_configuration_descriptors(hub_info); 157 static int usb_hub_set_configuration(usb_hub_info_t * hub_info){ 158 //device descriptor 159 usb_standard_device_descriptor_t *std_descriptor 160 = &hub_info->usb_device->descriptors.device; 161 usb_log_debug("hub has %d configurations\n", 162 std_descriptor->configuration_count); 163 if(std_descriptor->configuration_count<1){ 164 usb_log_error("THERE ARE NO CONFIGURATIONS AVAILABLE\n"); 165 //shouldn`t I return? 166 //definitely 167 return EINVAL; 168 } 169 170 usb_standard_configuration_descriptor_t *config_descriptor 171 = (usb_standard_configuration_descriptor_t *) 172 hub_info->usb_device->descriptors.configuration; 173 174 /* Set configuration. */ 175 int opResult = usb_request_set_configuration( 176 &hub_info->usb_device->ctrl_pipe, 177 config_descriptor->configuration_number); 178 179 if (opResult != EOK) { 180 usb_log_error("Failed to set hub configuration: %s.\n", 181 str_error(opResult)); 182 return opResult; 183 } 184 usb_log_debug("\tused configuration %d\n", 185 config_descriptor->configuration_number); 186 187 return EOK; 188 } 189 190 /** 191 * Initialize hub device driver fibril 192 * 193 * Creates hub representation and fibril that periodically checks hub`s status. 194 * Hub representation is passed to the fibril. 195 * @param usb_dev generic usb device information 196 * @return error code 197 */ 198 int usb_hub_add_device(usb_device_t * usb_dev){ 199 if(!usb_dev) return EINVAL; 200 usb_hub_info_t * hub_info = usb_hub_info_create(usb_dev); 201 //create hc connection 202 usb_log_debug("Initializing USB wire abstraction.\n"); 203 int opResult = usb_hc_connection_initialize_from_device( 204 &hub_info->connection, 205 hub_info->usb_device->ddf_dev); 314 206 if(opResult != EOK){ 315 usb_log_error("could not get configuration descriptors, %d",207 usb_log_error("could not initialize connection to device, errno %d\n", 316 208 opResult); 317 return opResult;318 }319 //power ports320 usb_device_request_setup_packet_t request;321 int port;322 for (port = 1; port < hub_info->port_count+1; ++port) {323 usb_hub_set_power_port_request(&request, port);324 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control,325 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0);326 usb_log_info("powering port %d",port);327 if (opResult != EOK) {328 usb_log_warning("something went wrong when setting hub`s %dth port", port);329 }330 }331 //ports powered, hub seems to be enabled332 usb_endpoint_pipe_end_session(&hub_info->endpoints.control);333 334 //add the hub to list335 //is this needed now?336 fibril_mutex_lock(&usb_hub_list_lock);337 usb_lst_append(&usb_hub_list, hub_info); 338 fibril_mutex_unlock(&usb_hub_list_lock); 339 usb_log_debug("hub info added to list");340 341 usb_log_debug("adding to ddf");342 ddf_fun_t *hub_fun = ddf_fun_create(dev,fun_exposed, "hub");209 free(hub_info); 210 return opResult; 211 } 212 213 usb_pipe_start_session(hub_info->control_pipe); 214 //set hub configuration 215 opResult = usb_hub_set_configuration(hub_info); 216 if(opResult!=EOK){ 217 usb_log_error("could not set hub configuration, errno %d\n",opResult); 218 free(hub_info); 219 return opResult; 220 } 221 //get port count and create attached_devs 222 opResult = usb_hub_get_hub_specific_info(hub_info); 223 if(opResult!=EOK){ 224 usb_log_error("could not set hub configuration, errno %d\n",opResult); 225 free(hub_info); 226 return opResult; 227 } 228 usb_pipe_end_session(hub_info->control_pipe); 229 230 231 /// \TODO what is this? 232 usb_log_debug("Creating `hub' function.\n"); 233 ddf_fun_t *hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev, 234 fun_exposed, "hub"); 343 235 assert(hub_fun != NULL); 344 236 hub_fun->ops = NULL; … … 349 241 assert(rc == EOK); 350 242 243 //create fibril for the hub control loop 351 244 fid_t fid = fibril_create(usb_hub_control_loop, hub_info); 352 245 if (fid == 0) { 353 usb_log_error("failed to start monitoring fibril for new hub ");246 usb_log_error("failed to start monitoring fibril for new hub.\n"); 354 247 return ENOMEM; 355 248 } 356 249 fibril_add_ready(fid); 357 358 usb_log_debug("hub fibril created"); 359 //(void)hub_info; 360 //usb_hub_check_hub_changes(); 361 362 usb_log_info("hub dev added"); 363 //address is lost... 364 usb_log_debug("\taddress %d, has %d ports ", 365 //hub_info->endpoints.control., 366 hub_info->port_count); 367 250 usb_log_debug("Hub fibril created.\n"); 251 252 usb_log_info("Controlling hub `%s' (%d ports).\n", 253 hub_info->usb_device->ddf_dev->name, hub_info->port_count); 368 254 return EOK; 369 //return ENOTSUP;370 255 } 371 256 … … 388 273 int opResult = usb_hc_release_default_address(&hub->connection); 389 274 if(opResult!=EOK){ 390 usb_log_error("could not release default address, errno %d ",opResult);275 usb_log_error("could not release default address, errno %d\n",opResult); 391 276 return opResult; 392 277 } … … 405 290 //if this hub already uses default address, it cannot request it once more 406 291 if(hub->is_default_address_used) return; 407 292 usb_log_debug("some connection changed\n"); 293 assert(hub->control_pipe->hc_phone); 294 int opResult = usb_hub_clear_port_feature(hub->control_pipe, 295 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 296 if(opResult != EOK){ 297 usb_log_warning("could not clear port-change-connection flag\n"); 298 } 408 299 usb_device_request_setup_packet_t request; 409 int opResult; 410 usb_log_info("some connection changed"); 411 assert(hub->endpoints.control.hc_phone); 300 412 301 //get default address 413 302 opResult = usb_hc_reserve_default_address(&hub->connection, speed); 414 303 415 304 if (opResult != EOK) { 416 usb_log_warning("cannot assign default address, it is probably used %d ",305 usb_log_warning("cannot assign default address, it is probably used %d\n", 417 306 opResult); 418 307 return; … … 421 310 //reset port 422 311 usb_hub_set_reset_port_request(&request, port); 423 opResult = usb_ endpoint_pipe_control_write(424 &hub->endpoints.control,312 opResult = usb_pipe_control_write( 313 hub->control_pipe, 425 314 &request,sizeof(usb_device_request_setup_packet_t), 426 315 NULL, 0 427 316 ); 428 317 if (opResult != EOK) { 429 usb_log_error("something went wrong when reseting a port %d ",opResult);318 usb_log_error("something went wrong when reseting a port %d\n",opResult); 430 319 //usb_hub_release_default_address(hc); 431 320 usb_hub_release_default_address(hub); 432 321 } 322 return; 433 323 } 434 324 … … 440 330 */ 441 331 static void usb_hub_finalize_add_device( usb_hub_info_t * hub, 442 uint16_t port, bool isLowSpeed) {332 uint16_t port, usb_speed_t speed) { 443 333 444 334 int opResult; 445 usb_log_ info("finalizing add device");446 opResult = usb_hub_clear_port_feature( &hub->endpoints.control,335 usb_log_debug("finalizing add device\n"); 336 opResult = usb_hub_clear_port_feature(hub->control_pipe, 447 337 port, USB_HUB_FEATURE_C_PORT_RESET); 448 338 449 339 if (opResult != EOK) { 450 usb_log_error("failed to clear port reset feature ");340 usb_log_error("failed to clear port reset feature\n"); 451 341 usb_hub_release_default_address(hub); 452 342 return; 453 343 } 454 344 //create connection to device 455 usb_ endpoint_pipe_t new_device_pipe;345 usb_pipe_t new_device_pipe; 456 346 usb_device_connection_t new_device_connection; 457 347 usb_device_connection_initialize_on_default_address( … … 459 349 &hub->connection 460 350 ); 461 usb_ endpoint_pipe_initialize_default_control(351 usb_pipe_initialize_default_control( 462 352 &new_device_pipe, 463 353 &new_device_connection); 464 usb_endpoint_pipe_probe_default_control(&new_device_pipe); 465 /// \TODO get highspeed info 466 usb_speed_t speed = isLowSpeed?USB_SPEED_LOW:USB_SPEED_FULL; 467 354 usb_pipe_probe_default_control(&new_device_pipe); 468 355 469 356 /* Request address from host controller. */ … … 473 360 ); 474 361 if (new_device_address < 0) { 475 usb_log_error("failed to get free USB address ");362 usb_log_error("failed to get free USB address\n"); 476 363 opResult = new_device_address; 477 364 usb_hub_release_default_address(hub); 478 365 return; 479 366 } 480 usb_log_ info("setting new address %d",new_device_address);367 usb_log_debug("setting new address %d\n",new_device_address); 481 368 //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 482 369 // new_device_address); 483 usb_ endpoint_pipe_start_session(&new_device_pipe);370 usb_pipe_start_session(&new_device_pipe); 484 371 opResult = usb_request_set_address(&new_device_pipe,new_device_address); 485 usb_ endpoint_pipe_end_session(&new_device_pipe);486 if (opResult != EOK) { 487 usb_log_error("could not set address for new device %d ",opResult);372 usb_pipe_end_session(&new_device_pipe); 373 if (opResult != EOK) { 374 usb_log_error("could not set address for new device %d\n",opResult); 488 375 usb_hub_release_default_address(hub); 489 376 return; … … 500 387 //?? 501 388 opResult = usb_device_register_child_in_devman(new_device_address, 502 hub->connection.hc_handle, hub-> device, &child_handle,389 hub->connection.hc_handle, hub->usb_device->ddf_dev, &child_handle, 503 390 NULL, NULL, NULL); 504 391 505 392 if (opResult != EOK) { 506 usb_log_error("could not start driver for new device %d ",opResult);393 usb_log_error("could not start driver for new device %d\n",opResult); 507 394 return; 508 395 } … … 515 402 &hub->attached_devs[port]); 516 403 if (opResult != EOK) { 517 usb_log_error("could not assign address of device in hcd %d",opResult); 518 return; 519 } 520 usb_log_info("new device address %d, handle %zu", 404 usb_log_error("could not assign address of device in hcd %d\n",opResult); 405 return; 406 } 407 usb_log_info("Detected new device on `%s' (port %d), " \ 408 "address %d (handle %llu).\n", 409 hub->usb_device->ddf_dev->name, (int) port, 521 410 new_device_address, child_handle); 522 523 411 } 524 412 … … 531 419 static void usb_hub_removed_device( 532 420 usb_hub_info_t * hub,uint16_t port) { 533 421 422 int opResult = usb_hub_clear_port_feature(hub->control_pipe, 423 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 424 if(opResult != EOK){ 425 usb_log_warning("could not clear port-change-connection flag\n"); 426 } 534 427 /** \TODO remove device from device manager - not yet implemented in 535 428 * devide manager … … 549 442 */ 550 443 }else{ 551 usb_log_warning("this is strange, disconnected device had no address ");444 usb_log_warning("this is strange, disconnected device had no address\n"); 552 445 //device was disconnected before it`s port was reset - return default address 553 446 usb_hub_release_default_address(hub); … … 567 460 uint16_t port){ 568 461 int opResult; 569 opResult = usb_hub_clear_port_feature( &hub->endpoints.control,462 opResult = usb_hub_clear_port_feature(hub->control_pipe, 570 463 port, USB_HUB_FEATURE_PORT_POWER); 571 464 if(opResult!=EOK){ 572 usb_log_error("cannot power off port %d; %d ",465 usb_log_error("cannot power off port %d; %d\n", 573 466 port, opResult); 574 467 } … … 583 476 static void usb_hub_process_interrupt(usb_hub_info_t * hub, 584 477 uint16_t port) { 585 usb_log_debug("interrupt at port %d ", port);478 usb_log_debug("interrupt at port %d\n", port); 586 479 //determine type of change 587 usb_ endpoint_pipe_t *pipe = &hub->endpoints.control;480 usb_pipe_t *pipe = hub->control_pipe; 588 481 589 482 int opResult; … … 596 489 //endpoint 0 597 490 598 opResult = usb_ endpoint_pipe_control_read(491 opResult = usb_pipe_control_read( 599 492 pipe, 600 493 &request, sizeof(usb_device_request_setup_packet_t), … … 602 495 ); 603 496 if (opResult != EOK) { 604 usb_log_error("could not get port status ");497 usb_log_error("could not get port status\n"); 605 498 return; 606 499 } 607 500 if (rcvd_size != sizeof (usb_port_status_t)) { 608 usb_log_error("received status has incorrect size ");501 usb_log_error("received status has incorrect size\n"); 609 502 return; 610 503 } 611 504 //something connected/disconnected 612 505 if (usb_port_connect_change(&status)) { 613 opResult = usb_hub_clear_port_feature(pipe,614 port, USB_HUB_FEATURE_C_PORT_CONNECTION);615 // TODO: check opResult616 506 if (usb_port_dev_connected(&status)) { 617 usb_log_ info("some connection changed");507 usb_log_debug("some connection changed\n"); 618 508 usb_hub_init_add_device(hub, port, usb_port_speed(&status)); 619 509 } else { … … 627 517 usb_hub_over_current(hub,port); 628 518 }else{ 629 usb_log_ info("over current condition was auto-resolved on port %d",519 usb_log_debug("over current condition was auto-resolved on port %d\n", 630 520 port); 631 521 } … … 633 523 //port reset 634 524 if (usb_port_reset_completed(&status)) { 635 usb_log_ info("port reset complete");525 usb_log_debug("port reset complete\n"); 636 526 if (usb_port_enabled(&status)) { 637 usb_hub_finalize_add_device(hub, port, usb_port_ low_speed(&status));527 usb_hub_finalize_add_device(hub, port, usb_port_speed(&status)); 638 528 } else { 639 usb_log_warning("port reset, but port still not enabled ");529 usb_log_warning("port reset, but port still not enabled\n"); 640 530 } 641 531 } … … 646 536 usb_port_set_dev_connected(&status, false); 647 537 if (status>>16) { 648 usb_log_info("there was some unsupported change on port %d: %X ",538 usb_log_info("there was some unsupported change on port %d: %X\n", 649 539 port,status); 650 540 651 541 } 652 /// \TODO handle other changes - is there any?653 542 } 654 543 … … 661 550 int usb_hub_check_hub_changes(usb_hub_info_t * hub_info){ 662 551 int opResult; 663 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change); 552 opResult = usb_pipe_start_session( 553 hub_info->status_change_pipe); 664 554 if(opResult != EOK){ 665 usb_log_error("could not initialize communication for hub; %d ",555 usb_log_error("could not initialize communication for hub; %d\n", 666 556 opResult); 667 557 return opResult; … … 678 568 * Send the request. 679 569 */ 680 opResult = usb_ endpoint_pipe_read(681 &hub_info->endpoints.status_change,570 opResult = usb_pipe_read( 571 hub_info->status_change_pipe, 682 572 change_bitmap, byte_length, &actual_size 683 573 ); … … 685 575 if (opResult != EOK) { 686 576 free(change_bitmap); 687 usb_log_warning("something went wrong while getting status of hub ");688 usb_ endpoint_pipe_end_session(&hub_info->endpoints.status_change);577 usb_log_warning("something went wrong while getting status of hub\n"); 578 usb_pipe_end_session(hub_info->status_change_pipe); 689 579 return opResult; 690 580 } 691 581 unsigned int port; 692 opResult = usb_ endpoint_pipe_start_session(&hub_info->endpoints.control);693 if(opResult!=EOK){ 694 usb_log_error("could not start control pipe session %d ", opResult);695 usb_ endpoint_pipe_end_session(&hub_info->endpoints.status_change);582 opResult = usb_pipe_start_session(hub_info->control_pipe); 583 if(opResult!=EOK){ 584 usb_log_error("could not start control pipe session %d\n", opResult); 585 usb_pipe_end_session(hub_info->status_change_pipe); 696 586 return opResult; 697 587 } 698 588 opResult = usb_hc_connection_open(&hub_info->connection); 699 589 if(opResult!=EOK){ 700 usb_log_error("could not start host controller session %d ",590 usb_log_error("could not start host controller session %d\n", 701 591 opResult); 702 usb_ endpoint_pipe_end_session(&hub_info->endpoints.control);703 usb_ endpoint_pipe_end_session(&hub_info->endpoints.status_change);592 usb_pipe_end_session(hub_info->control_pipe); 593 usb_pipe_end_session(hub_info->status_change_pipe); 704 594 return opResult; 705 595 } … … 715 605 } 716 606 usb_hc_connection_close(&hub_info->connection); 717 usb_ endpoint_pipe_end_session(&hub_info->endpoints.control);718 usb_ endpoint_pipe_end_session(&hub_info->endpoints.status_change);607 usb_pipe_end_session(hub_info->control_pipe); 608 usb_pipe_end_session(hub_info->status_change_pipe); 719 609 free(change_bitmap); 720 610 return EOK; -
uspace/drv/usbhub/usbhub.h
r18b3cfd r62f4212 45 45 46 46 #include <usb/pipes.h> 47 48 /* Hub endpoints. */ 49 typedef struct { 50 usb_endpoint_pipe_t control; 51 usb_endpoint_pipe_t status_change; 52 } usb_hub_endpoints_t; 53 47 #include <usb/devdrv.h> 54 48 55 49 … … 58 52 /** Number of ports. */ 59 53 int port_count; 54 60 55 /** attached device handles, for each port one */ 61 56 usb_hc_attached_device_t * attached_devs; 62 /** General usb device info. */ 63 //usb_hcd_attached_device_info_t * usb_device; 64 /** General device info*/ 65 ddf_dev_t * device; 57 66 58 /** connection to hcd */ 67 //usb_device_connection_t connection;68 59 usb_hc_connection_t connection; 69 /** */70 usb_device_connection_t device_connection;71 /** hub endpoints */72 usb_hub_endpoints_t endpoints;73 60 61 /** default address is used indicator 62 * 63 * If default address is requested by this device, it cannot 64 * be requested by the same hub again, otherwise a deadlock will occur. 65 */ 74 66 bool is_default_address_used; 67 68 /** convenience pointer to status change pipe 69 * 70 * Status change pipe is initialized in usb_device structure. This is 71 * pointer into this structure, so that it does not have to be 72 * searched again and again for the 'right pipe'. 73 */ 74 usb_pipe_t * status_change_pipe; 75 76 /** convenience pointer to control pipe 77 * 78 * Control pipe is initialized in usb_device structure. This is 79 * pointer into this structure, so that it does not have to be 80 * searched again and again for the 'right pipe'. 81 */ 82 usb_pipe_t * control_pipe; 83 84 /** generic usb device data*/ 85 usb_device_t * usb_device; 75 86 } usb_hub_info_t; 76 87 … … 80 91 */ 81 92 int usb_hub_control_loop(void * hub_info_param); 82 83 /** Callback when new hub device is detected.84 *85 * @param dev New device.86 * @return Error code.87 */88 int usb_add_hub_device(ddf_dev_t *dev);89 93 90 94 /** … … 97 101 98 102 99 100 103 int usb_hub_add_device(usb_device_t * usb_dev); 101 104 102 105 #endif -
uspace/drv/usbhub/usbhub_private.h
r18b3cfd r62f4212 58 58 59 59 60 //************61 //62 // convenience debug printf for usb hub63 //64 //************65 #define dprintf(level, format, ...) \66 usb_log_printf((level), format "\n", ##__VA_ARGS__)67 68 69 60 /** 70 61 * Create hub structure instance … … 77 68 */ 78 69 usb_hub_info_t * usb_create_hub_info(ddf_dev_t * device); 79 80 /** List of hubs maanged by this driver */81 extern usb_general_list_t usb_hub_list;82 83 /** Lock for hub list*/84 extern fibril_mutex_t usb_hub_list_lock;85 86 87 /**88 * Perform complete control read transaction89 *90 * Manages all three steps of transaction: setup, read and finalize91 * @param phone92 * @param target93 * @param request Request packet94 * @param rcvd_buffer Received data95 * @param rcvd_size96 * @param actual_size Actual size of received data97 * @return error code98 */99 /*100 int usb_drv_sync_control_read(101 usb_endpoint_pipe_t *pipe,102 usb_device_request_setup_packet_t * request,103 void * rcvd_buffer, size_t rcvd_size, size_t * actual_size104 );*/105 106 /**107 * Perform complete control write transaction108 *109 * Manages all three steps of transaction: setup, write and finalize110 * @param phone111 * @param target112 * @param request Request packet to send data113 * @param sent_buffer114 * @param sent_size115 * @return error code116 */117 /*int usb_drv_sync_control_write(118 usb_endpoint_pipe_t *pipe,119 usb_device_request_setup_packet_t * request,120 void * sent_buffer, size_t sent_size121 );*/122 70 123 71 /** … … 147 95 * @return Operation result 148 96 */ 149 static inline int usb_hub_clear_port_feature(usb_ endpoint_pipe_t *pipe,97 static inline int usb_hub_clear_port_feature(usb_pipe_t *pipe, 150 98 int port_index, 151 99 usb_hub_class_feature_t feature) { … … 158 106 }; 159 107 clear_request.value = feature; 160 return usb_ endpoint_pipe_control_write(pipe, &clear_request,108 return usb_pipe_control_write(pipe, &clear_request, 161 109 sizeof(clear_request), NULL, 0); 162 110 } 163 111 164 112 /** 165 * @briefcreate uint8_t array with serialized descriptor113 * create uint8_t array with serialized descriptor 166 114 * 167 115 * @param descriptor … … 171 119 172 120 /** 173 * @briefcreate deserialized desriptor structure out of serialized descriptor121 * create deserialized desriptor structure out of serialized descriptor 174 122 * 175 123 * The serialized descriptor must be proper usb hub descriptor, -
uspace/drv/usbhub/utils.c
r18b3cfd r62f4212 88 88 89 89 if (sdescriptor[1] != USB_DESCTYPE_HUB) { 90 dprintf(1,"[usb_hub]wrong descriptor %x\n",sdescriptor[1]);90 usb_log_warning("trying to deserialize wrong descriptor %x\n",sdescriptor[1]); 91 91 return NULL; 92 92 } … … 103 103 ? 1 : 0); 104 104 result->devices_removable = (uint8_t*) malloc(var_size); 105 //printf("[usb_hub] getting removable devices data \n"); 105 106 106 size_t i; 107 107 for (i = 0; i < var_size; ++i) { … … 111 111 } 112 112 113 //control transactions114 /*115 int usb_drv_sync_control_read(116 int phone, usb_target_t target,117 usb_device_request_setup_packet_t * request,118 void * rcvd_buffer, size_t rcvd_size, size_t * actual_size119 ) {120 usb_handle_t handle;121 int opResult;122 //setup123 opResult = usb_drv_async_control_read_setup(phone, target,124 request, sizeof (usb_device_request_setup_packet_t),125 &handle);126 if (opResult != EOK) {127 return opResult;128 }129 opResult = usb_drv_async_wait_for(handle);130 if (opResult != EOK) {131 return opResult;132 }133 //read134 opResult = usb_drv_async_control_read_data(phone, target,135 rcvd_buffer, rcvd_size, actual_size,136 &handle);137 if (opResult != EOK) {138 return opResult;139 }140 opResult = usb_drv_async_wait_for(handle);141 if (opResult != EOK) {142 return opResult;143 }144 //finalize145 opResult = usb_drv_async_control_read_status(phone, target,146 &handle);147 if (opResult != EOK) {148 return opResult;149 }150 opResult = usb_drv_async_wait_for(handle);151 if (opResult != EOK) {152 return opResult;153 }154 return EOK;155 }156 157 int usb_drv_sync_control_write(158 int phone, usb_target_t target,159 usb_device_request_setup_packet_t * request,160 void * sent_buffer, size_t sent_size161 ) {162 usb_handle_t handle;163 int opResult;164 //setup165 opResult = usb_drv_async_control_write_setup(phone, target,166 request, sizeof (usb_device_request_setup_packet_t),167 &handle);168 if (opResult != EOK) {169 return opResult;170 }171 opResult = usb_drv_async_wait_for(handle);172 if (opResult != EOK) {173 return opResult;174 }175 //write176 opResult = usb_drv_async_control_write_data(phone, target,177 sent_buffer, sent_size,178 &handle);179 if (opResult != EOK) {180 return opResult;181 }182 opResult = usb_drv_async_wait_for(handle);183 if (opResult != EOK) {184 return opResult;185 }186 //finalize187 opResult = usb_drv_async_control_write_status(phone, target,188 &handle);189 if (opResult != EOK) {190 return opResult;191 }192 opResult = usb_drv_async_wait_for(handle);193 if (opResult != EOK) {194 return opResult;195 }196 return EOK;197 }198 199 */200 201 113 202 114 -
uspace/drv/usbmid/main.c
r18b3cfd r62f4212 61 61 int rc; 62 62 63 rc = usb_ endpoint_pipe_start_session(&dev->ctrl_pipe);63 rc = usb_pipe_start_session(&dev->ctrl_pipe); 64 64 if (rc != EOK) { 65 65 usb_log_error("Failed to start session on control pipe: %s.\n", … … 70 70 bool accept = usbmid_explore_device(dev); 71 71 72 rc = usb_ endpoint_pipe_end_session(&dev->ctrl_pipe);72 rc = usb_pipe_end_session(&dev->ctrl_pipe); 73 73 if (rc != EOK) { 74 74 usb_log_warning("Failed to end session on control pipe: %s.\n", … … 106 106 printf(NAME ": USB multi interface device driver.\n"); 107 107 108 usb_log_enable(USB_LOG_LEVEL_ INFO, NAME);108 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 109 109 return ddf_driver_main(&mid_driver); 110 110 } -
uspace/drv/usbmid/usbmid.c
r18b3cfd r62f4212 108 108 } 109 109 110 rc = usb_ endpoint_pipe_initialize_default_control(&mid->ctrl_pipe,110 rc = usb_pipe_initialize_default_control(&mid->ctrl_pipe, 111 111 &mid->wire); 112 112 if (rc != EOK) { … … 116 116 return NULL; 117 117 } 118 rc = usb_ endpoint_pipe_probe_default_control(&mid->ctrl_pipe);118 rc = usb_pipe_probe_default_control(&mid->ctrl_pipe); 119 119 if (rc != EOK) { 120 120 usb_log_error("Probing default control pipe failed: %s.\n", -
uspace/drv/usbmid/usbmid.h
r18b3cfd r62f4212 52 52 usb_device_connection_t wire; 53 53 /** Default control pipe. */ 54 usb_ endpoint_pipe_t ctrl_pipe;54 usb_pipe_t ctrl_pipe; 55 55 } usbmid_device_t; 56 56 -
uspace/drv/usbmouse/init.c
r18b3cfd r62f4212 124 124 goto leave; 125 125 } 126 127 /* Open the control pipe. */ 128 rc = usb_pipe_start_session(&dev->ctrl_pipe); 129 if (rc != EOK) { 130 goto leave; 131 } 132 133 /* Set the boot protocol. */ 134 rc = usb_control_request_set(&dev->ctrl_pipe, 135 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 136 USB_HIDREQ_SET_PROTOCOL, USB_HID_PROTOCOL_BOOT, dev->interface_no, 137 NULL, 0); 138 if (rc != EOK) { 139 goto leave; 140 } 141 142 /* Close the control pipe (ignore errors). */ 143 usb_pipe_end_session(&dev->ctrl_pipe); 144 126 145 127 146 /* Everything allright. */ -
uspace/drv/usbmouse/main.c
r18b3cfd r62f4212 90 90 int main(int argc, char *argv[]) 91 91 { 92 usb_log_enable(USB_LOG_LEVEL_DE BUG, NAME);92 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 93 93 94 94 return usb_driver_main(&mouse_driver); -
uspace/drv/vhc/hcd.c
r18b3cfd r62f4212 122 122 //sleep(5); 123 123 124 usb_log_enable(USB_LOG_LEVEL_DE BUG, NAME);124 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 125 125 126 126 printf(NAME ": virtual USB host controller driver.\n"); -
uspace/lib/usb/Makefile
r18b3cfd r62f4212 49 49 src/request.c \ 50 50 src/usb.c \ 51 src/usbdevice.c 51 src/usbdevice.c \ 52 src/host/device_keeper.c \ 53 src/host/batch.c 52 54 53 55 include $(USPACE_PREFIX)/Makefile.common -
uspace/lib/usb/include/usb/classes/hub.h
r18b3cfd r62f4212 60 60 } usb_hub_class_feature_t; 61 61 62 /** Header of standard hub descriptor without the "variadic" part. */ 63 typedef struct { 64 /** Descriptor length. */ 65 uint8_t length; 66 /** Descriptor type (0x29). */ 67 uint8_t descriptor_type; 68 /** Number of downstream ports. */ 69 uint8_t port_count; 70 /** Characteristics bitmask. */ 71 uint16_t characteristics; 72 /** Time from power-on to stabilization of current on the port. */ 73 uint8_t power_good_time; 74 /** Maximum current requirements in mA. */ 75 uint8_t max_current; 76 } __attribute__ ((packed)) usb_hub_descriptor_header_t; 62 77 63 78 /** -
uspace/lib/usb/include/usb/debug.h
r18b3cfd r62f4212 79 79 } usb_log_level_t; 80 80 81 /** Default log level. */ 82 #define USB_LOG_LEVEL_DEFAULT USB_LOG_LEVEL_DEBUG 83 81 84 82 85 void usb_log_enable(usb_log_level_t, const char *); -
uspace/lib/usb/include/usb/devdrv.h
r18b3cfd r62f4212 38 38 #include <usb/pipes.h> 39 39 40 /** Descriptors for USB device. */ 41 typedef struct { 42 /** Standard device descriptor. */ 43 usb_standard_device_descriptor_t device; 44 /** Full configuration descriptor of current configuration. */ 45 uint8_t *configuration; 46 size_t configuration_size; 47 } usb_device_descriptors_t; 48 40 49 /** USB device structure. */ 41 50 typedef struct { 42 51 /** The default control pipe. */ 43 usb_ endpoint_pipe_t ctrl_pipe;52 usb_pipe_t ctrl_pipe; 44 53 /** Other endpoint pipes. 45 54 * This is an array of other endpoint pipes in the same order as … … 47 56 */ 48 57 usb_endpoint_mapping_t *pipes; 58 /** Current interface. 59 * Usually, drivers operate on single interface only. 60 * This item contains the value of the interface or -1 for any. 61 */ 62 int interface_no; 63 64 /** Some useful descriptors. */ 65 usb_device_descriptors_t descriptors; 66 49 67 /** Generic DDF device backing this one. */ 50 68 ddf_dev_t *ddf_dev; … … 74 92 */ 75 93 const char *name; 76 /** Expected endpoints description. */ 94 /** Expected endpoints description, excluding default control endpoint. 95 * 96 * It MUST be of size expected_enpoints_count(excluding default ctrl) + 1 97 * where the last record MUST BE NULL, otherwise catastrophic things may 98 * happen. 99 */ 77 100 usb_endpoint_description_t **endpoints; 78 101 /** Driver ops. */ -
uspace/lib/usb/include/usb/pipes.h
r18b3cfd r62f4212 80 80 */ 81 81 int hc_phone; 82 } usb_ endpoint_pipe_t;82 } usb_pipe_t; 83 83 84 84 … … 102 102 typedef struct { 103 103 /** Endpoint pipe. */ 104 usb_ endpoint_pipe_t *pipe;104 usb_pipe_t *pipe; 105 105 /** Endpoint description. */ 106 106 const usb_endpoint_description_t *description; … … 125 125 usb_address_t usb_device_get_assigned_address(devman_handle_t); 126 126 127 int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *, 128 usb_device_connection_t *, 127 int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *, 129 128 usb_endpoint_t, usb_transfer_type_t, size_t, usb_direction_t); 130 int usb_ endpoint_pipe_initialize_default_control(usb_endpoint_pipe_t *,129 int usb_pipe_initialize_default_control(usb_pipe_t *, 131 130 usb_device_connection_t *); 132 int usb_ endpoint_pipe_probe_default_control(usb_endpoint_pipe_t *);133 int usb_ endpoint_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,131 int usb_pipe_probe_default_control(usb_pipe_t *); 132 int usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *, 134 133 size_t, uint8_t *, size_t, usb_device_connection_t *); 135 int usb_endpoint_pipe_register(usb_endpoint_pipe_t *, unsigned int, 136 usb_hc_connection_t *); 137 int usb_endpoint_pipe_unregister(usb_endpoint_pipe_t *, usb_hc_connection_t *); 134 int usb_pipe_register(usb_pipe_t *, unsigned int, usb_hc_connection_t *); 135 int usb_pipe_unregister(usb_pipe_t *, usb_hc_connection_t *); 138 136 139 int usb_ endpoint_pipe_start_session(usb_endpoint_pipe_t *);140 int usb_ endpoint_pipe_end_session(usb_endpoint_pipe_t *);141 bool usb_ endpoint_pipe_is_session_started(usb_endpoint_pipe_t *);137 int usb_pipe_start_session(usb_pipe_t *); 138 int usb_pipe_end_session(usb_pipe_t *); 139 bool usb_pipe_is_session_started(usb_pipe_t *); 142 140 143 int usb_ endpoint_pipe_read(usb_endpoint_pipe_t *, void *, size_t, size_t *);144 int usb_ endpoint_pipe_write(usb_endpoint_pipe_t *, void *, size_t);141 int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *); 142 int usb_pipe_write(usb_pipe_t *, void *, size_t); 145 143 146 int usb_ endpoint_pipe_control_read(usb_endpoint_pipe_t *, void *, size_t,144 int usb_pipe_control_read(usb_pipe_t *, void *, size_t, 147 145 void *, size_t, size_t *); 148 int usb_ endpoint_pipe_control_write(usb_endpoint_pipe_t *, void *, size_t,146 int usb_pipe_control_write(usb_pipe_t *, void *, size_t, 149 147 void *, size_t); 150 148 -
uspace/lib/usb/include/usb/recognise.h
r18b3cfd r62f4212 48 48 const usb_standard_interface_descriptor_t *, match_id_list_t *); 49 49 50 int usb_device_create_match_ids(usb_ endpoint_pipe_t *, match_id_list_t *);50 int usb_device_create_match_ids(usb_pipe_t *, match_id_list_t *); 51 51 52 52 int usb_device_register_child_in_devman(usb_address_t, devman_handle_t, -
uspace/lib/usb/include/usb/request.h
r18b3cfd r62f4212 86 86 } __attribute__ ((packed)) usb_device_request_setup_packet_t; 87 87 88 int usb_control_request_set(usb_ endpoint_pipe_t *,88 int usb_control_request_set(usb_pipe_t *, 89 89 usb_request_type_t, usb_request_recipient_t, uint8_t, 90 90 uint16_t, uint16_t, void *, size_t); 91 91 92 int usb_control_request_get(usb_ endpoint_pipe_t *,92 int usb_control_request_get(usb_pipe_t *, 93 93 usb_request_type_t, usb_request_recipient_t, uint8_t, 94 94 uint16_t, uint16_t, void *, size_t, size_t *); 95 95 96 int usb_request_set_address(usb_endpoint_pipe_t *, usb_address_t); 97 int usb_request_get_descriptor(usb_endpoint_pipe_t *, usb_request_type_t, 96 int usb_request_get_status(usb_pipe_t *, usb_request_recipient_t, 97 uint16_t, uint16_t *); 98 int usb_request_clear_feature(usb_pipe_t *, usb_request_type_t, 99 usb_request_recipient_t, uint16_t, uint16_t); 100 int usb_request_set_feature(usb_pipe_t *, usb_request_type_t, 101 usb_request_recipient_t, uint16_t, uint16_t); 102 int usb_request_set_address(usb_pipe_t *, usb_address_t); 103 int usb_request_get_descriptor(usb_pipe_t *, usb_request_type_t, 98 104 usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void *, size_t, 99 105 size_t *); 100 int usb_request_get_descriptor_alloc(usb_ endpoint_pipe_t *, usb_request_type_t,106 int usb_request_get_descriptor_alloc(usb_pipe_t *, usb_request_type_t, 101 107 usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void **, size_t *); 102 int usb_request_get_device_descriptor(usb_ endpoint_pipe_t *,108 int usb_request_get_device_descriptor(usb_pipe_t *, 103 109 usb_standard_device_descriptor_t *); 104 int usb_request_get_bare_configuration_descriptor(usb_ endpoint_pipe_t *, int,110 int usb_request_get_bare_configuration_descriptor(usb_pipe_t *, int, 105 111 usb_standard_configuration_descriptor_t *); 106 int usb_request_get_full_configuration_descriptor(usb_ endpoint_pipe_t *, int,112 int usb_request_get_full_configuration_descriptor(usb_pipe_t *, int, 107 113 void *, size_t, size_t *); 108 int usb_request_get_full_configuration_descriptor_alloc(usb_ endpoint_pipe_t *,114 int usb_request_get_full_configuration_descriptor_alloc(usb_pipe_t *, 109 115 int, void **, size_t *); 110 int usb_request_set_configuration(usb_endpoint_pipe_t *, uint8_t); 116 int usb_request_set_descriptor(usb_pipe_t *, usb_request_type_t, 117 usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void *, size_t); 118 int usb_request_get_configuration(usb_pipe_t *, uint8_t *); 119 int usb_request_set_configuration(usb_pipe_t *, uint8_t); 120 int usb_request_get_interface(usb_pipe_t *, uint8_t, uint8_t *); 121 int usb_request_set_interface(usb_pipe_t *, uint8_t, uint8_t); 111 122 112 int usb_request_get_supported_languages(usb_ endpoint_pipe_t *,123 int usb_request_get_supported_languages(usb_pipe_t *, 113 124 l18_win_locales_t **, size_t *); 114 int usb_request_get_string(usb_ endpoint_pipe_t *, size_t, l18_win_locales_t,125 int usb_request_get_string(usb_pipe_t *, size_t, l18_win_locales_t, 115 126 char **); 116 127 -
uspace/lib/usb/include/usb/usb.h
r18b3cfd r62f4212 61 61 62 62 const char * usb_str_transfer_type(usb_transfer_type_t t); 63 const char * usb_str_transfer_type_short(usb_transfer_type_t t); 63 64 64 65 /** USB data transfer direction. */ … … 78 79 USB_SPEED_HIGH 79 80 } usb_speed_t; 81 82 const char *usb_str_speed(usb_speed_t); 83 80 84 81 85 /** USB request type target. */ -
uspace/lib/usb/src/devdrv.c
r18b3cfd r62f4212 109 109 { 110 110 int rc; 111 int my_interface= usb_device_get_assigned_interface(dev->ddf_dev);111 dev->interface_no = usb_device_get_assigned_interface(dev->ddf_dev); 112 112 113 113 size_t pipe_count = count_other_pipes(drv); … … 126 126 127 127 for (i = 0; i < pipe_count; i++) { 128 dev->pipes[i].pipe = malloc(sizeof(usb_ endpoint_pipe_t));128 dev->pipes[i].pipe = malloc(sizeof(usb_pipe_t)); 129 129 if (dev->pipes[i].pipe == NULL) { 130 130 usb_log_oom(dev->ddf_dev); … … 134 134 135 135 dev->pipes[i].description = drv->endpoints[i]; 136 dev->pipes[i].interface_no = my_interface; 137 } 138 139 void *config_descriptor; 140 size_t config_descriptor_size; 141 rc = usb_request_get_full_configuration_descriptor_alloc( 142 &dev->ctrl_pipe, 0, &config_descriptor, &config_descriptor_size); 143 if (rc != EOK) { 144 usb_log_error("Failed retrieving configuration of `%s': %s.\n", 145 dev->ddf_dev->name, str_error(rc)); 146 goto rollback; 147 } 148 149 rc = usb_endpoint_pipe_initialize_from_configuration(dev->pipes, 150 pipe_count, config_descriptor, config_descriptor_size, &dev->wire); 136 dev->pipes[i].interface_no = dev->interface_no; 137 } 138 139 rc = usb_pipe_initialize_from_configuration(dev->pipes, pipe_count, 140 dev->descriptors.configuration, dev->descriptors.configuration_size, 141 &dev->wire); 151 142 if (rc != EOK) { 152 143 usb_log_error("Failed initializing USB endpoints: %s.\n", … … 172 163 for (i = 0; i < pipe_count; i++) { 173 164 if (dev->pipes[i].present) { 174 rc = usb_ endpoint_pipe_register(dev->pipes[i].pipe,165 rc = usb_pipe_register(dev->pipes[i].pipe, 175 166 dev->pipes[i].descriptor->poll_interval, 176 167 &hc_conn); … … 206 197 * @return Error code. 207 198 */ 208 static int initialize_pipes(usb_d river_t *drv, usb_device_t *dev)199 static int initialize_pipes(usb_device_t *dev) 209 200 { 210 201 int rc; … … 219 210 } 220 211 221 rc = usb_ endpoint_pipe_initialize_default_control(&dev->ctrl_pipe,212 rc = usb_pipe_initialize_default_control(&dev->ctrl_pipe, 222 213 &dev->wire); 223 214 if (rc != EOK) { … … 228 219 } 229 220 230 rc = usb_ endpoint_pipe_probe_default_control(&dev->ctrl_pipe);221 rc = usb_pipe_probe_default_control(&dev->ctrl_pipe); 231 222 if (rc != EOK) { 232 223 usb_log_error( … … 237 228 238 229 /* 239 * Initialization of other pipes requires open session on 240 * default control pipe. 230 * For further actions, we need open session on default control pipe. 241 231 */ 242 rc = usb_ endpoint_pipe_start_session(&dev->ctrl_pipe);232 rc = usb_pipe_start_session(&dev->ctrl_pipe); 243 233 if (rc != EOK) { 244 234 usb_log_error("Failed to start an IPC session: %s.\n", 245 235 str_error(rc)); 236 return rc; 237 } 238 239 /* Get the device descriptor. */ 240 rc = usb_request_get_device_descriptor(&dev->ctrl_pipe, 241 &dev->descriptors.device); 242 if (rc != EOK) { 243 usb_log_error("Failed to retrieve device descriptor: %s.\n", 244 str_error(rc)); 245 return rc; 246 } 247 248 /* Get the full configuration descriptor. */ 249 rc = usb_request_get_full_configuration_descriptor_alloc( 250 &dev->ctrl_pipe, 0, (void **) &dev->descriptors.configuration, 251 &dev->descriptors.configuration_size); 252 if (rc != EOK) { 253 usb_log_error("Failed retrieving configuration descriptor: %s.\n", 254 dev->ddf_dev->name, str_error(rc)); 246 255 return rc; 247 256 } … … 252 261 253 262 /* No checking here. */ 254 usb_endpoint_pipe_end_session(&dev->ctrl_pipe); 263 usb_pipe_end_session(&dev->ctrl_pipe); 264 265 /* Rollback actions. */ 266 if (rc != EOK) { 267 if (dev->descriptors.configuration != NULL) { 268 free(dev->descriptors.configuration); 269 } 270 } 255 271 256 272 return rc; … … 283 299 dev->ddf_dev->driver_data = dev; 284 300 dev->driver_data = NULL; 285 286 rc = initialize_pipes(driver, dev); 301 dev->descriptors.configuration = NULL; 302 303 rc = initialize_pipes(dev); 287 304 if (rc != EOK) { 288 305 free(dev); -
uspace/lib/usb/src/devpoll.c
r18b3cfd r62f4212 64 64 assert(polling_data); 65 65 66 usb_ endpoint_pipe_t *pipe66 usb_pipe_t *pipe 67 67 = polling_data->dev->pipes[polling_data->pipe_index].pipe; 68 68 … … 71 71 int rc; 72 72 73 rc = usb_ endpoint_pipe_start_session(pipe);73 rc = usb_pipe_start_session(pipe); 74 74 if (rc != EOK) { 75 75 failed_attempts++; … … 78 78 79 79 size_t actual_size; 80 rc = usb_ endpoint_pipe_read(pipe, polling_data->buffer,80 rc = usb_pipe_read(pipe, polling_data->buffer, 81 81 polling_data->request_size, &actual_size); 82 82 83 83 /* Quit the session regardless of errors. */ 84 usb_ endpoint_pipe_end_session(pipe);84 usb_pipe_end_session(pipe); 85 85 86 86 if (rc != EOK) { -
uspace/lib/usb/src/host/device_keeper.c
r18b3cfd r62f4212 27 27 */ 28 28 29 /** @addtogroup drvusbuhcihc29 /** @addtogroup libusb 30 30 * @{ 31 31 */ 32 32 /** @file 33 * @brief UHCI driver33 * Device keeper structure and functions (implementation). 34 34 */ 35 35 #include <assert.h> 36 36 #include <errno.h> 37 37 #include <usb/debug.h> 38 39 #include "device_keeper.h" 38 #include <usb/host/device_keeper.h> 40 39 41 40 /*----------------------------------------------------------------------------*/ … … 46 45 * Set all values to false/0. 47 46 */ 48 void device_keeper_init(device_keeper_t *instance)47 void usb_device_keeper_init(usb_device_keeper_t *instance) 49 48 { 50 49 assert(instance); … … 56 55 instance->devices[i].occupied = false; 57 56 instance->devices[i].handle = 0; 58 instance->devices[i].toggle_status = 0; 57 instance->devices[i].toggle_status[0] = 0; 58 instance->devices[i].toggle_status[1] = 0; 59 59 } 60 60 } … … 65 65 * @param[in] speed Speed of the device requesting default address. 66 66 */ 67 void device_keeper_reserve_default(device_keeper_t *instance, usb_speed_t speed) 67 void usb_device_keeper_reserve_default_address(usb_device_keeper_t *instance, 68 usb_speed_t speed) 68 69 { 69 70 assert(instance); … … 83 84 * @param[in] speed Speed of the device requesting default address. 84 85 */ 85 void device_keeper_release_default(device_keeper_t *instance)86 void usb_device_keeper_release_default_address(usb_device_keeper_t *instance) 86 87 { 87 88 assert(instance); … … 100 101 * Really ugly one. 101 102 */ 102 void device_keeper_reset_if_need(103 device_keeper_t *instance, usb_target_t target, const unsigned char*data)103 void usb_device_keeper_reset_if_need(usb_device_keeper_t *instance, 104 usb_target_t target, const uint8_t *data) 104 105 { 105 106 assert(instance); … … 119 120 if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) { 120 121 /* endpoint number is < 16, thus first byte is enough */ 121 instance->devices[target.address].toggle_status &= 122 instance->devices[target.address].toggle_status[0] &= 123 ~(1 << data[4]); 124 instance->devices[target.address].toggle_status[1] &= 122 125 ~(1 << data[4]); 123 126 } … … 128 131 /* target must be device */ 129 132 if ((data[0] & 0xf) == 0) { 130 instance->devices[target.address].toggle_status = 0; 133 instance->devices[target.address].toggle_status[0] = 0; 134 instance->devices[target.address].toggle_status[1] = 0; 131 135 } 132 136 break; … … 141 145 * @return Error code 142 146 */ 143 int device_keeper_get_toggle(device_keeper_t *instance, usb_target_t target) 144 { 145 assert(instance); 147 int usb_device_keeper_get_toggle(usb_device_keeper_t *instance, 148 usb_target_t target, usb_direction_t direction) 149 { 150 assert(instance); 151 /* only control pipes are bi-directional and those do not need toggle */ 152 if (direction == USB_DIRECTION_BOTH) 153 return ENOENT; 146 154 int ret; 147 155 fibril_mutex_lock(&instance->guard); … … 152 160 ret = EINVAL; 153 161 } else { 154 ret = (instance->devices[target.address].toggle_status 162 ret = (instance->devices[target.address].toggle_status[direction] 155 163 >> target.endpoint) & 1; 156 164 } … … 166 174 * @return Error code. 167 175 */ 168 int device_keeper_set_toggle( 169 device_keeper_t *instance, usb_target_t target, bool toggle) 170 { 171 assert(instance); 176 int usb_device_keeper_set_toggle(usb_device_keeper_t *instance, 177 usb_target_t target, usb_direction_t direction, bool toggle) 178 { 179 assert(instance); 180 /* only control pipes are bi-directional and those do not need toggle */ 181 if (direction == USB_DIRECTION_BOTH) 182 return ENOENT; 172 183 int ret; 173 184 fibril_mutex_lock(&instance->guard); … … 179 190 } else { 180 191 if (toggle) { 181 instance->devices[target.address].toggle_status |= (1 << target.endpoint); 192 instance->devices[target.address].toggle_status[direction] 193 |= (1 << target.endpoint); 182 194 } else { 183 instance->devices[target.address].toggle_status &= ~(1 << target.endpoint); 195 instance->devices[target.address].toggle_status[direction] 196 &= ~(1 << target.endpoint); 184 197 } 185 198 ret = EOK; … … 195 208 * @return Free address, or error code. 196 209 */ 197 usb_address_t device_keeper_request( 198 device_keeper_t *instance, usb_speed_t speed) 199 { 200 assert(instance); 201 fibril_mutex_lock(&instance->guard); 202 203 usb_address_t new_address = instance->last_address + 1; 204 while (instance->devices[new_address].occupied) { 210 usb_address_t device_keeper_get_free_address(usb_device_keeper_t *instance, 211 usb_speed_t speed) 212 { 213 assert(instance); 214 fibril_mutex_lock(&instance->guard); 215 216 usb_address_t new_address = instance->last_address; 217 do { 218 ++new_address; 219 if (new_address > USB11_ADDRESS_MAX) 220 new_address = 1; 205 221 if (new_address == instance->last_address) { 206 222 fibril_mutex_unlock(&instance->guard); 207 223 return ENOSPC; 208 224 } 209 if (new_address == USB11_ADDRESS_MAX) 210 new_address = 1; 211 ++new_address; 212 } 225 } while (instance->devices[new_address].occupied); 213 226 214 227 assert(new_address != USB_ADDRESS_DEFAULT); … … 216 229 instance->devices[new_address].occupied = true; 217 230 instance->devices[new_address].speed = speed; 218 instance->devices[new_address].toggle_status = 0; 231 instance->devices[new_address].toggle_status[0] = 0; 232 instance->devices[new_address].toggle_status[1] = 0; 219 233 instance->last_address = new_address; 220 234 fibril_mutex_unlock(&instance->guard); … … 228 242 * @param[in] handle Devman handle of the device. 229 243 */ 230 void device_keeper_bind(231 device_keeper_t *instance,usb_address_t address, devman_handle_t handle)244 void usb_device_keeper_bind(usb_device_keeper_t *instance, 245 usb_address_t address, devman_handle_t handle) 232 246 { 233 247 assert(instance); … … 245 259 * @param[in] address Device address 246 260 */ 247 void device_keeper_release(device_keeper_t *instance, usb_address_t address) 261 void usb_device_keeper_release(usb_device_keeper_t *instance, 262 usb_address_t address) 248 263 { 249 264 assert(instance); … … 263 278 * @return USB Address, or error code. 264 279 */ 265 usb_address_t device_keeper_find(266 dev ice_keeper_t *instance, devman_handle_t handle)280 usb_address_t usb_device_keeper_find(usb_device_keeper_t *instance, 281 devman_handle_t handle) 267 282 { 268 283 assert(instance); … … 286 301 * @return USB speed. 287 302 */ 288 usb_speed_t device_keeper_speed(289 device_keeper_t *instance,usb_address_t address)303 usb_speed_t usb_device_keeper_get_speed(usb_device_keeper_t *instance, 304 usb_address_t address) 290 305 { 291 306 assert(instance); … … 294 309 return instance->devices[address].speed; 295 310 } 311 296 312 /** 297 313 * @} -
uspace/lib/usb/src/hub.c
r18b3cfd r62f4212 228 228 } 229 229 230 usb_ endpoint_pipe_t ctrl_pipe;231 rc = usb_ endpoint_pipe_initialize_default_control(&ctrl_pipe,230 usb_pipe_t ctrl_pipe; 231 rc = usb_pipe_initialize_default_control(&ctrl_pipe, 232 232 &dev_conn); 233 233 if (rc != EOK) { … … 235 235 goto leave_release_default_address; 236 236 } 237 rc = usb_ endpoint_pipe_probe_default_control(&ctrl_pipe);237 rc = usb_pipe_probe_default_control(&ctrl_pipe); 238 238 if (rc != EOK) { 239 239 rc = ENOTCONN; … … 241 241 } 242 242 243 rc = usb_ endpoint_pipe_start_session(&ctrl_pipe);243 rc = usb_pipe_start_session(&ctrl_pipe); 244 244 if (rc != EOK) { 245 245 rc = ENOTCONN; … … 253 253 } 254 254 255 usb_ endpoint_pipe_end_session(&ctrl_pipe);255 usb_pipe_end_session(&ctrl_pipe); 256 256 257 257 /* … … 306 306 307 307 leave_stop_session: 308 usb_ endpoint_pipe_end_session(&ctrl_pipe);308 usb_pipe_end_session(&ctrl_pipe); 309 309 310 310 leave_release_default_address: -
uspace/lib/usb/src/pipes.c
r18b3cfd r62f4212 42 42 #include <assert.h> 43 43 44 #define IPC_AGAIN_DELAY (1000 * 2) /* 2ms */ 45 44 46 /** Tell USB address assigned to given device. 45 47 * … … 150 152 } 151 153 152 my_address = get_my_address(parent_phone, dev); 153 if (my_address < 0) { 154 rc = my_address; 155 goto leave; 156 } 154 /* 155 * Asking for "my" address may require several attempts. 156 * That is because following scenario may happen: 157 * - parent driver (i.e. driver of parent device) announces new device 158 * and devman launches current driver 159 * - parent driver is preempted and thus does not send address-handle 160 * binding to HC driver 161 * - this driver gets here and wants the binding 162 * - the HC does not know the binding yet and thus it answers ENOENT 163 * So, we need to wait for the HC to learn the binding. 164 */ 165 do { 166 my_address = get_my_address(parent_phone, dev); 167 168 if (my_address == ENOENT) { 169 /* Be nice, let other fibrils run and try again. */ 170 async_usleep(IPC_AGAIN_DELAY); 171 } else if (my_address < 0) { 172 /* Some other problem, no sense trying again. */ 173 rc = my_address; 174 goto leave; 175 } 176 177 } while (my_address < 0); 157 178 158 179 rc = usb_device_connection_initialize(connection, … … 212 233 * A session is something inside what any communication occurs. 213 234 * It is expected that sessions would be started right before the transfer 214 * and ended - see usb_ endpoint_pipe_end_session() - after the last235 * and ended - see usb_pipe_end_session() - after the last 215 236 * transfer. 216 237 * The reason for this is that session actually opens some communication … … 223 244 * @return Error code. 224 245 */ 225 int usb_ endpoint_pipe_start_session(usb_endpoint_pipe_t *pipe)246 int usb_pipe_start_session(usb_pipe_t *pipe) 226 247 { 227 248 assert(pipe); 228 249 229 if (usb_ endpoint_pipe_is_session_started(pipe)) {250 if (usb_pipe_is_session_started(pipe)) { 230 251 return EBUSY; 231 252 } … … 244 265 /** Ends a session on the endpoint pipe. 245 266 * 246 * @see usb_ endpoint_pipe_start_session267 * @see usb_pipe_start_session 247 268 * 248 269 * @param pipe Endpoint pipe to end the session on. 249 270 * @return Error code. 250 271 */ 251 int usb_ endpoint_pipe_end_session(usb_endpoint_pipe_t *pipe)272 int usb_pipe_end_session(usb_pipe_t *pipe) 252 273 { 253 274 assert(pipe); 254 275 255 if (!usb_ endpoint_pipe_is_session_started(pipe)) {276 if (!usb_pipe_is_session_started(pipe)) { 256 277 return ENOENT; 257 278 } … … 275 296 * @return Whether @p pipe has opened a session. 276 297 */ 277 bool usb_ endpoint_pipe_is_session_started(usb_endpoint_pipe_t *pipe)298 bool usb_pipe_is_session_started(usb_pipe_t *pipe) 278 299 { 279 300 return (pipe->hc_phone >= 0); -
uspace/lib/usb/src/pipesinit.c
r18b3cfd r62f4212 193 193 } 194 194 195 int rc = usb_ endpoint_pipe_initialize(ep_mapping->pipe, wire,195 int rc = usb_pipe_initialize(ep_mapping->pipe, wire, 196 196 ep_no, description.transfer_type, endpoint->max_packet_size, 197 197 description.direction); … … 276 276 * @return Error code. 277 277 */ 278 int usb_ endpoint_pipe_initialize_from_configuration(278 int usb_pipe_initialize_from_configuration( 279 279 usb_endpoint_mapping_t *mapping, size_t mapping_count, 280 280 uint8_t *configuration_descriptor, size_t configuration_descriptor_size, … … 342 342 * @return Error code. 343 343 */ 344 int usb_ endpoint_pipe_initialize(usb_endpoint_pipe_t *pipe,344 int usb_pipe_initialize(usb_pipe_t *pipe, 345 345 usb_device_connection_t *connection, usb_endpoint_t endpoint_no, 346 346 usb_transfer_type_t transfer_type, size_t max_packet_size, … … 367 367 * @return Error code. 368 368 */ 369 int usb_ endpoint_pipe_initialize_default_control(usb_endpoint_pipe_t *pipe,369 int usb_pipe_initialize_default_control(usb_pipe_t *pipe, 370 370 usb_device_connection_t *connection) 371 371 { … … 373 373 assert(connection); 374 374 375 int rc = usb_ endpoint_pipe_initialize(pipe, connection,375 int rc = usb_pipe_initialize(pipe, connection, 376 376 0, USB_TRANSFER_CONTROL, CTRL_PIPE_MIN_PACKET_SIZE, 377 377 USB_DIRECTION_BOTH); … … 390 390 * @return Error code. 391 391 */ 392 int usb_ endpoint_pipe_probe_default_control(usb_endpoint_pipe_t *pipe)392 int usb_pipe_probe_default_control(usb_pipe_t *pipe) 393 393 { 394 394 assert(pipe); … … 408 408 409 409 TRY_LOOP(failed_attempts) { 410 rc = usb_ endpoint_pipe_start_session(pipe);410 rc = usb_pipe_start_session(pipe); 411 411 if (rc == EOK) { 412 412 break; … … 433 433 } 434 434 } 435 usb_ endpoint_pipe_end_session(pipe);435 usb_pipe_end_session(pipe); 436 436 if (rc != EOK) { 437 437 return rc; … … 451 451 * @return Error code. 452 452 */ 453 int usb_ endpoint_pipe_register(usb_endpoint_pipe_t *pipe,453 int usb_pipe_register(usb_pipe_t *pipe, 454 454 unsigned int interval, 455 455 usb_hc_connection_t *hc_connection) … … 479 479 * @return Error code. 480 480 */ 481 int usb_ endpoint_pipe_unregister(usb_endpoint_pipe_t *pipe,481 int usb_pipe_unregister(usb_pipe_t *pipe, 482 482 usb_hc_connection_t *hc_connection) 483 483 { -
uspace/lib/usb/src/pipesio.c
r18b3cfd r62f4212 58 58 * @return Error code. 59 59 */ 60 static int usb_ endpoint_pipe_read_no_checks(usb_endpoint_pipe_t *pipe,60 static int usb_pipe_read_no_checks(usb_pipe_t *pipe, 61 61 void *buffer, size_t size, size_t *size_transfered) 62 62 { … … 140 140 * @return Error code. 141 141 */ 142 int usb_ endpoint_pipe_read(usb_endpoint_pipe_t *pipe,142 int usb_pipe_read(usb_pipe_t *pipe, 143 143 void *buffer, size_t size, size_t *size_transfered) 144 144 { … … 153 153 } 154 154 155 if (!usb_ endpoint_pipe_is_session_started(pipe)) {155 if (!usb_pipe_is_session_started(pipe)) { 156 156 return EBADF; 157 157 } … … 168 168 int rc; 169 169 170 rc = usb_ endpoint_pipe_read_no_checks(pipe, buffer, size, &act_size);170 rc = usb_pipe_read_no_checks(pipe, buffer, size, &act_size); 171 171 if (rc != EOK) { 172 172 return rc; … … 190 190 * @return Error code. 191 191 */ 192 static int usb_ endpoint_pipe_write_no_check(usb_endpoint_pipe_t *pipe,192 static int usb_pipe_write_no_check(usb_pipe_t *pipe, 193 193 void *buffer, size_t size) 194 194 { … … 247 247 * @return Error code. 248 248 */ 249 int usb_ endpoint_pipe_write(usb_endpoint_pipe_t *pipe,249 int usb_pipe_write(usb_pipe_t *pipe, 250 250 void *buffer, size_t size) 251 251 { … … 260 260 } 261 261 262 if (!usb_ endpoint_pipe_is_session_started(pipe)) {262 if (!usb_pipe_is_session_started(pipe)) { 263 263 return EBADF; 264 264 } … … 272 272 } 273 273 274 int rc = usb_ endpoint_pipe_write_no_check(pipe, buffer, size);274 int rc = usb_pipe_write_no_check(pipe, buffer, size); 275 275 276 276 return rc; … … 289 289 * @return Error code. 290 290 */ 291 static int usb_ endpoint_pipe_control_read_no_check(usb_endpoint_pipe_t *pipe,291 static int usb_pipe_control_read_no_check(usb_pipe_t *pipe, 292 292 void *setup_buffer, size_t setup_buffer_size, 293 293 void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size) … … 365 365 * @return Error code. 366 366 */ 367 int usb_ endpoint_pipe_control_read(usb_endpoint_pipe_t *pipe,367 int usb_pipe_control_read(usb_pipe_t *pipe, 368 368 void *setup_buffer, size_t setup_buffer_size, 369 369 void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size) … … 379 379 } 380 380 381 if (!usb_ endpoint_pipe_is_session_started(pipe)) {381 if (!usb_pipe_is_session_started(pipe)) { 382 382 return EBADF; 383 383 } … … 389 389 390 390 size_t act_size = 0; 391 int rc = usb_ endpoint_pipe_control_read_no_check(pipe,391 int rc = usb_pipe_control_read_no_check(pipe, 392 392 setup_buffer, setup_buffer_size, 393 393 data_buffer, data_buffer_size, &act_size); … … 414 414 * @return Error code. 415 415 */ 416 static int usb_ endpoint_pipe_control_write_no_check(usb_endpoint_pipe_t *pipe,416 static int usb_pipe_control_write_no_check(usb_pipe_t *pipe, 417 417 void *setup_buffer, size_t setup_buffer_size, 418 418 void *data_buffer, size_t data_buffer_size) … … 473 473 * @return Error code. 474 474 */ 475 int usb_ endpoint_pipe_control_write(usb_endpoint_pipe_t *pipe,475 int usb_pipe_control_write(usb_pipe_t *pipe, 476 476 void *setup_buffer, size_t setup_buffer_size, 477 477 void *data_buffer, size_t data_buffer_size) … … 491 491 } 492 492 493 if (!usb_ endpoint_pipe_is_session_started(pipe)) {493 if (!usb_pipe_is_session_started(pipe)) { 494 494 return EBADF; 495 495 } … … 500 500 } 501 501 502 int rc = usb_ endpoint_pipe_control_write_no_check(pipe,502 int rc = usb_pipe_control_write_no_check(pipe, 503 503 setup_buffer, setup_buffer_size, data_buffer, data_buffer_size); 504 504 -
uspace/lib/usb/src/recognise.c
r18b3cfd r62f4212 247 247 #undef VENDOR_ONLY_FMT 248 248 #undef VENDOR_ONLY_ARGS 249 250 /* As a last resort, try fallback driver. */ 251 ADD_MATCHID_OR_RETURN(matches, 10, "usb&interface&fallback"); 249 252 250 253 return EOK; … … 291 294 } 292 295 296 /* As a last resort, try fallback driver. */ 297 ADD_MATCHID_OR_RETURN(matches, 10, "usb&fallback"); 298 293 299 return EOK; 294 300 } … … 305 311 * @return Error code. 306 312 */ 307 int usb_device_create_match_ids(usb_ endpoint_pipe_t *ctrl_pipe,313 int usb_device_create_match_ids(usb_pipe_t *ctrl_pipe, 308 314 match_id_list_t *matches) 309 315 { … … 357 363 int rc; 358 364 usb_device_connection_t dev_connection; 359 usb_ endpoint_pipe_t ctrl_pipe;365 usb_pipe_t ctrl_pipe; 360 366 361 367 rc = usb_device_connection_initialize(&dev_connection, hc_handle, address); … … 364 370 } 365 371 366 rc = usb_ endpoint_pipe_initialize_default_control(&ctrl_pipe,372 rc = usb_pipe_initialize_default_control(&ctrl_pipe, 367 373 &dev_connection); 368 374 if (rc != EOK) { 369 375 goto failure; 370 376 } 371 rc = usb_ endpoint_pipe_probe_default_control(&ctrl_pipe);377 rc = usb_pipe_probe_default_control(&ctrl_pipe); 372 378 if (rc != EOK) { 373 379 goto failure; … … 398 404 child->driver_data = dev_data; 399 405 400 rc = usb_ endpoint_pipe_start_session(&ctrl_pipe);406 rc = usb_pipe_start_session(&ctrl_pipe); 401 407 if (rc != EOK) { 402 408 goto failure; … … 408 414 } 409 415 410 rc = usb_ endpoint_pipe_end_session(&ctrl_pipe);416 rc = usb_pipe_end_session(&ctrl_pipe); 411 417 if (rc != EOK) { 412 418 goto failure; -
uspace/lib/usb/src/request.c
r18b3cfd r62f4212 42 42 /** Generic wrapper for SET requests using standard control request format. 43 43 * 44 * @see usb_ endpoint_pipe_control_write44 * @see usb_pipe_control_write 45 45 * 46 46 * @param pipe Pipe used for the communication. … … 60 60 * @retval ERANGE Data buffer too large. 61 61 */ 62 int usb_control_request_set(usb_ endpoint_pipe_t *pipe,62 int usb_control_request_set(usb_pipe_t *pipe, 63 63 usb_request_type_t request_type, usb_request_recipient_t recipient, 64 64 uint8_t request, … … 90 90 setup_packet.length = (uint16_t) data_size; 91 91 92 int rc = usb_ endpoint_pipe_control_write(pipe,92 int rc = usb_pipe_control_write(pipe, 93 93 &setup_packet, sizeof(setup_packet), 94 94 data, data_size); … … 99 99 /** Generic wrapper for GET requests using standard control request format. 100 100 * 101 * @see usb_ endpoint_pipe_control_read101 * @see usb_pipe_control_read 102 102 * 103 103 * @param pipe Pipe used for the communication. … … 120 120 * @retval ERANGE Data buffer too large. 121 121 */ 122 int usb_control_request_get(usb_ endpoint_pipe_t *pipe,122 int usb_control_request_get(usb_pipe_t *pipe, 123 123 usb_request_type_t request_type, usb_request_recipient_t recipient, 124 124 uint8_t request, … … 150 150 setup_packet.length = (uint16_t) data_size; 151 151 152 int rc = usb_ endpoint_pipe_control_read(pipe,152 int rc = usb_pipe_control_read(pipe, 153 153 &setup_packet, sizeof(setup_packet), 154 154 data, data_size, actual_data_size); 155 156 return rc; 157 } 158 159 /** Retrieve status of a USB device. 160 * 161 * @param[in] pipe Control endpoint pipe (session must be already started). 162 * @param[in] index Recipient index (in native endianness). 163 * @param[in] recipient Recipient of the GET_STATUS request. 164 * @param[out] status Recipient status (in native endianness). 165 * @return Error code. 166 */ 167 int usb_request_get_status(usb_pipe_t *pipe, 168 usb_request_recipient_t recipient, uint16_t index, 169 uint16_t *status) 170 { 171 if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) && (index != 0)) { 172 return EINVAL; 173 } 174 175 if (status == NULL) { 176 return EBADMEM; 177 } 178 179 uint16_t status_usb_endianess; 180 size_t data_transfered_size; 181 int rc = usb_control_request_get(pipe, USB_REQUEST_TYPE_STANDARD, 182 recipient, USB_DEVREQ_GET_STATUS, 0, uint16_host2usb(index), 183 &status_usb_endianess, 2, &data_transfered_size); 184 if (rc != EOK) { 185 return rc; 186 } 187 if (data_transfered_size != 2) { 188 return ELIMIT; 189 } 190 191 *status = uint16_usb2host(status_usb_endianess); 192 193 return EOK; 194 } 195 196 /** Clear or disable specific device feature. 197 * 198 * @param[in] pipe Control endpoint pipe (session must be already started). 199 * @param[in] request_type Request type (standard/class/vendor). 200 * @param[in] recipient Recipient of the CLEAR_FEATURE request. 201 * @param[in] feature_selector Feature selector (in native endianness). 202 * @param[in] index Recipient index (in native endianness). 203 * @return Error code. 204 */ 205 int usb_request_clear_feature(usb_pipe_t *pipe, 206 usb_request_type_t request_type, usb_request_recipient_t recipient, 207 uint16_t feature_selector, uint16_t index) 208 { 209 if (request_type == USB_REQUEST_TYPE_STANDARD) { 210 if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) 211 && (index != 0)) { 212 return EINVAL; 213 } 214 } 215 216 int rc = usb_control_request_set(pipe, request_type, recipient, 217 USB_DEVREQ_CLEAR_FEATURE, 218 uint16_host2usb(feature_selector), uint16_host2usb(index), 219 NULL, 0); 220 221 return rc; 222 } 223 224 /** Set or enable specific device feature. 225 * 226 * @param[in] pipe Control endpoint pipe (session must be already started). 227 * @param[in] request_type Request type (standard/class/vendor). 228 * @param[in] recipient Recipient of the SET_FEATURE request. 229 * @param[in] feature_selector Feature selector (in native endianness). 230 * @param[in] index Recipient index (in native endianness). 231 * @return Error code. 232 */ 233 int usb_request_set_feature(usb_pipe_t *pipe, 234 usb_request_type_t request_type, usb_request_recipient_t recipient, 235 uint16_t feature_selector, uint16_t index) 236 { 237 if (request_type == USB_REQUEST_TYPE_STANDARD) { 238 if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) 239 && (index != 0)) { 240 return EINVAL; 241 } 242 } 243 244 int rc = usb_control_request_set(pipe, request_type, recipient, 245 USB_DEVREQ_SET_FEATURE, 246 uint16_host2usb(feature_selector), uint16_host2usb(index), 247 NULL, 0); 155 248 156 249 return rc; … … 165 258 * @return Error code. 166 259 */ 167 int usb_request_set_address(usb_ endpoint_pipe_t *pipe,260 int usb_request_set_address(usb_pipe_t *pipe, 168 261 usb_address_t new_address) 169 262 { … … 204 297 * @return Error code. 205 298 */ 206 int usb_request_get_descriptor(usb_ endpoint_pipe_t *pipe,299 int usb_request_get_descriptor(usb_pipe_t *pipe, 207 300 usb_request_type_t request_type, usb_request_recipient_t recipient, 208 301 uint8_t descriptor_type, uint8_t descriptor_index, … … 238 331 * @return 239 332 */ 240 int usb_request_get_descriptor_alloc(usb_ endpoint_pipe_t * pipe,333 int usb_request_get_descriptor_alloc(usb_pipe_t * pipe, 241 334 usb_request_type_t request_type, usb_request_recipient_t recipient, 242 335 uint8_t descriptor_type, uint8_t descriptor_index, … … 307 400 * @return Error code. 308 401 */ 309 int usb_request_get_device_descriptor(usb_ endpoint_pipe_t *pipe,402 int usb_request_get_device_descriptor(usb_pipe_t *pipe, 310 403 usb_standard_device_descriptor_t *descriptor) 311 404 { … … 349 442 * @return Error code. 350 443 */ 351 int usb_request_get_bare_configuration_descriptor(usb_ endpoint_pipe_t *pipe,444 int usb_request_get_bare_configuration_descriptor(usb_pipe_t *pipe, 352 445 int index, usb_standard_configuration_descriptor_t *descriptor) 353 446 { … … 395 488 * @return Error code. 396 489 */ 397 int usb_request_get_full_configuration_descriptor(usb_ endpoint_pipe_t *pipe,490 int usb_request_get_full_configuration_descriptor(usb_pipe_t *pipe, 398 491 int index, void *descriptor, size_t descriptor_size, size_t *actual_size) 399 492 { … … 421 514 */ 422 515 int usb_request_get_full_configuration_descriptor_alloc( 423 usb_ endpoint_pipe_t *pipe, int index,516 usb_pipe_t *pipe, int index, 424 517 void **descriptor_ptr, size_t *descriptor_size) 425 518 { … … 473 566 } 474 567 568 /** Update existing or add new USB descriptor to a USB device. 569 * 570 * @param[in] pipe Control endpoint pipe (session must be already started). 571 * @param[in] request_type Request type (standard/class/vendor). 572 * @param[in] recipient Request recipient (device/interface/endpoint). 573 * @param[in] descriptor_type Descriptor type (device/configuration/HID/...). 574 * @param[in] descriptor_index Descriptor index. 575 * @param[in] language Language index (in native endianness). 576 * @param[in] buffer Buffer with the new descriptor (in USB endianness). 577 * @param[in] size Size of the @p buffer in bytes (in native endianness). 578 * @return Error code. 579 */ 580 int usb_request_set_descriptor(usb_pipe_t *pipe, 581 usb_request_type_t request_type, usb_request_recipient_t recipient, 582 uint8_t descriptor_type, uint8_t descriptor_index, 583 uint16_t language, 584 void *buffer, size_t size) 585 { 586 if (buffer == NULL) { 587 return EBADMEM; 588 } 589 if (size == 0) { 590 return EINVAL; 591 } 592 593 /* FIXME: proper endianness. */ 594 uint16_t wValue = descriptor_index | (descriptor_type << 8); 595 596 return usb_control_request_set(pipe, 597 request_type, recipient, 598 USB_DEVREQ_SET_DESCRIPTOR, 599 wValue, language, 600 buffer, size); 601 } 602 603 /** Get current configuration value of USB device. 604 * 605 * @param[in] pipe Control endpoint pipe (session must be already started). 606 * @param[out] configuration_value Current configuration value. 607 * @return Error code. 608 */ 609 int usb_request_get_configuration(usb_pipe_t *pipe, 610 uint8_t *configuration_value) 611 { 612 uint8_t value; 613 size_t actual_size; 614 615 int rc = usb_control_request_get(pipe, 616 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE, 617 USB_DEVREQ_GET_CONFIGURATION, 618 0, 0, 619 &value, 1, &actual_size); 620 621 if (rc != EOK) { 622 return rc; 623 } 624 if (actual_size != 1) { 625 return ELIMIT; 626 } 627 628 if (configuration_value != NULL) { 629 *configuration_value = value; 630 } 631 632 return EOK; 633 } 634 475 635 /** Set configuration of USB device. 476 636 * … … 479 639 * @return Error code. 480 640 */ 481 int usb_request_set_configuration(usb_ endpoint_pipe_t *pipe,641 int usb_request_set_configuration(usb_pipe_t *pipe, 482 642 uint8_t configuration_value) 483 643 { … … 491 651 } 492 652 653 /** Get selected alternate setting for USB interface. 654 * 655 * @param[in] pipe Control endpoint pipe (session must be already started). 656 * @param[in] interface_index Interface index. 657 * @param[out] alternate_setting Alternate setting for the interface. 658 * @return Error code. 659 */ 660 int usb_request_get_interface(usb_pipe_t *pipe, 661 uint8_t interface_index, uint8_t *alternate_setting) 662 { 663 uint8_t value; 664 size_t actual_size; 665 666 int rc = usb_control_request_get(pipe, 667 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE, 668 USB_DEVREQ_GET_INTERFACE, 669 0, uint16_host2usb((uint16_t) interface_index), 670 &value, 1, &actual_size); 671 672 if (rc != EOK) { 673 return rc; 674 } 675 if (actual_size != 1) { 676 return ELIMIT; 677 } 678 679 if (alternate_setting != NULL) { 680 *alternate_setting = value; 681 } 682 683 return EOK; 684 } 685 686 /** Select alternate setting for USB interface. 687 * 688 * @param[in] pipe Control endpoint pipe (session must be already started). 689 * @param[in] interface_index Interface index. 690 * @param[in] alternate_setting Alternate setting to select. 691 * @return Error code. 692 */ 693 int usb_request_set_interface(usb_pipe_t *pipe, 694 uint8_t interface_index, uint8_t alternate_setting) 695 { 696 return usb_control_request_set(pipe, 697 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE, 698 USB_DEVREQ_SET_INTERFACE, 699 uint16_host2usb((uint16_t) alternate_setting), 700 uint16_host2usb((uint16_t) interface_index), 701 NULL, 0); 702 } 703 493 704 /** Get list of supported languages by USB device. 494 705 * … … 499 710 * @return Error code. 500 711 */ 501 int usb_request_get_supported_languages(usb_ endpoint_pipe_t *pipe,712 int usb_request_get_supported_languages(usb_pipe_t *pipe, 502 713 l18_win_locales_t **languages_ptr, size_t *languages_count) 503 714 { … … 571 782 * @return Error code. 572 783 */ 573 int usb_request_get_string(usb_ endpoint_pipe_t *pipe,784 int usb_request_get_string(usb_pipe_t *pipe, 574 785 size_t index, l18_win_locales_t lang, char **string_ptr) 575 786 { -
uspace/lib/usb/src/usb.c
r18b3cfd r62f4212 36 36 #include <errno.h> 37 37 38 #define ARR_SIZE(arr) (sizeof(arr)/sizeof(arr[0])) 39 40 static const char *str_speed[] = { 41 "low", 42 "full", 43 "high" 44 }; 45 46 static const char *str_transfer_type[] = { 47 "control", 48 "isochronous", 49 "bulk", 50 "interrupt" 51 }; 52 53 static const char *str_transfer_type_short[] = { 54 "ctrl", 55 "iso", 56 "bulk", 57 "intr" 58 }; 38 59 39 60 /** String representation for USB transfer type. … … 42 63 * @return Transfer type as a string (in English). 43 64 */ 44 const char * 65 const char *usb_str_transfer_type(usb_transfer_type_t t) 45 66 { 46 switch (t) { 47 case USB_TRANSFER_ISOCHRONOUS: 48 return "isochronous"; 49 case USB_TRANSFER_INTERRUPT: 50 return "interrupt"; 51 case USB_TRANSFER_CONTROL: 52 return "control"; 53 case USB_TRANSFER_BULK: 54 return "bulk"; 55 default: 56 return "unknown"; 67 if (t >= ARR_SIZE(str_transfer_type)) { 68 return "invalid"; 57 69 } 70 return str_transfer_type[t]; 71 } 72 73 /** String representation for USB transfer type (short version). 74 * 75 * @param t Transfer type. 76 * @return Transfer type as a short string for debugging messages. 77 */ 78 const char *usb_str_transfer_type_short(usb_transfer_type_t t) 79 { 80 if (t >= ARR_SIZE(str_transfer_type_short)) { 81 return "invl"; 82 } 83 return str_transfer_type_short[t]; 84 } 85 86 /** String representation of USB speed. 87 * 88 * @param s The speed. 89 * @return USB speed as a string (in English). 90 */ 91 const char *usb_str_speed(usb_speed_t s) 92 { 93 if (s >= ARR_SIZE(str_speed)) { 94 return "invalid"; 95 } 96 return str_speed[s]; 58 97 } 59 98
Note:
See TracChangeset
for help on using the changeset viewer.