Changes in / [f50f722:68b614e] in mainline
- Location:
- uspace
- Files:
-
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/lsusb/main.c
rf50f722 r68b614e 44 44 #include <devman.h> 45 45 #include <devmap.h> 46 #include <usb/hub.h>47 46 #include <usb/host.h> 48 47 49 48 #define NAME "lsusb" 50 49 51 #define MAX_FAILED_ATTEMPTS 1050 #define MAX_FAILED_ATTEMPTS 4 52 51 #define MAX_PATH_LENGTH 1024 53 54 static void print_found_hc(size_t class_index, const char *path)55 {56 // printf(NAME ": host controller %zu is `%s'.\n", class_index, path);57 printf("Bus %02zu: %s\n", class_index, path);58 }59 static void print_found_dev(usb_address_t addr, const char *path)60 {61 // printf(NAME ": device with address %d is `%s'.\n", addr, path);62 printf(" Device %02d: %s\n", addr, path);63 }64 65 static void print_hc_devices(devman_handle_t hc_handle)66 {67 int rc;68 usb_hc_connection_t conn;69 70 usb_hc_connection_initialize(&conn, hc_handle);71 rc = usb_hc_connection_open(&conn);72 if (rc != EOK) {73 printf(NAME ": failed to connect to HC: %s.\n",74 str_error(rc));75 return;76 }77 usb_address_t addr;78 for (addr = 1; addr < 5; addr++) {79 devman_handle_t dev_handle;80 rc = usb_hc_get_handle_by_address(&conn, addr, &dev_handle);81 if (rc != EOK) {82 continue;83 }84 char path[MAX_PATH_LENGTH];85 rc = devman_get_device_path(dev_handle, path, MAX_PATH_LENGTH);86 if (rc != EOK) {87 continue;88 }89 print_found_dev(addr, path);90 }91 usb_hc_connection_close(&conn);92 }93 52 94 53 int main(int argc, char *argv[]) … … 110 69 continue; 111 70 } 112 print _found_hc(class_index, path);113 print_hc_devices(hc_handle);71 printf(NAME ": host controller %zu is `%s'.\n", 72 class_index, path); 114 73 } 115 74 -
uspace/app/usbinfo/dev.c
rf50f722 r68b614e 40 40 #include "usbinfo.h" 41 41 42 usbinfo_device_t *prepare_device( const char *name,43 devman_handle_t hc_handle,usb_address_t dev_addr)42 usbinfo_device_t *prepare_device(devman_handle_t hc_handle, 43 usb_address_t dev_addr) 44 44 { 45 45 usbinfo_device_t *dev = malloc(sizeof(usbinfo_device_t)); … … 55 55 if (rc != EOK) { 56 56 fprintf(stderr, 57 NAME ": failed to create connection to device %s: %s.\n",58 name,str_error(rc));57 NAME ": failed to create connection to the device: %s.\n", 58 str_error(rc)); 59 59 goto leave; 60 60 } … … 64 64 if (rc != EOK) { 65 65 fprintf(stderr, 66 NAME ": failed to create default control pipe to %s: %s.\n",67 name,str_error(rc));66 NAME ": failed to create default control pipe: %s.\n", 67 str_error(rc)); 68 68 goto leave; 69 69 } … … 71 71 rc = usb_pipe_probe_default_control(&dev->ctrl_pipe); 72 72 if (rc != EOK) { 73 if (rc == ENOENT) { 74 fprintf(stderr, NAME ": " \ 75 "device %s not present or malfunctioning.\n", 76 name); 77 } else { 78 fprintf(stderr, NAME ": " \ 79 "probing default control pipe of %s failed: %s.\n", 80 name, str_error(rc)); 81 } 73 fprintf(stderr, 74 NAME ": probing default control pipe failed: %s.\n", 75 str_error(rc)); 82 76 goto leave; 83 77 } … … 90 84 if (rc != EOK) { 91 85 fprintf(stderr, 92 NAME ": failed to retrieve device descriptor of %s: %s.\n",93 name,str_error(rc));86 NAME ": failed to retrieve device descriptor: %s.\n", 87 str_error(rc)); 94 88 goto leave; 95 89 } … … 99 93 &dev->full_configuration_descriptor_size); 100 94 if (rc != EOK) { 101 fprintf(stderr, NAME ": " \102 "failed to retrieve configuration descriptor of %s: %s.\n",103 name,str_error(rc));95 fprintf(stderr, 96 NAME ": failed to retrieve configuration descriptor: %s.\n", 97 str_error(rc)); 104 98 goto leave; 105 99 } -
uspace/app/usbinfo/main.c
rf50f722 r68b614e 308 308 } 309 309 310 usbinfo_device_t *dev = prepare_device(devpath, 311 hc_handle, dev_addr); 310 usbinfo_device_t *dev = prepare_device(hc_handle, dev_addr); 312 311 if (dev == NULL) { 313 312 continue; -
uspace/app/usbinfo/usbinfo.h
rf50f722 r68b614e 71 71 } 72 72 73 usbinfo_device_t *prepare_device( const char *,devman_handle_t, usb_address_t);73 usbinfo_device_t *prepare_device(devman_handle_t, usb_address_t); 74 74 void destroy_device(usbinfo_device_t *); 75 75 -
uspace/drv/ehci-hcd/hc_iface.c
rf50f722 r68b614e 106 106 } 107 107 108 /** Find device handle by USB address.109 *110 * @param[in] fun DDF function that was called.111 * @param[in] address Address in question.112 * @param[out] handle Where to store device handle if found.113 * @return Error code.114 */115 static int find_by_address(ddf_fun_t *fun, usb_address_t address,116 devman_handle_t *handle)117 {118 UNSUPPORTED("find_by_address");119 120 return ENOTSUP;121 }122 123 108 /** Release previously requested address. 124 109 * … … 336 321 .request_address = request_address, 337 322 .bind_address = bind_address, 338 .find_by_address = find_by_address,339 323 .release_address = release_address, 340 324 -
uspace/drv/ohci/hc.c
rf50f722 r68b614e 95 95 } 96 96 /*----------------------------------------------------------------------------*/ 97 int hc_init(hc_t *instance, uintptr_t regs, size_t reg_size, bool interrupts) 97 int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev, 98 uintptr_t regs, size_t reg_size, bool interrupts) 98 99 { 99 100 assert(instance); -
uspace/drv/ohci/hc.h
rf50f722 r68b614e 77 77 int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun); 78 78 79 int hc_init(hc_t *instance, uintptr_t regs, size_t reg_size, bool interrupts); 79 int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev, 80 uintptr_t regs, size_t reg_size, bool interrupts); 80 81 81 82 void hc_start_hw(hc_t *instance); -
uspace/drv/ohci/iface.c
rf50f722 r68b614e 122 122 return EOK; 123 123 } 124 125 126 /** Find device handle by address interface function.127 *128 * @param[in] fun DDF function that was called.129 * @param[in] address Address in question.130 * @param[out] handle Where to store device handle if found.131 * @return Error code.132 */133 static int find_by_address(ddf_fun_t *fun, usb_address_t address,134 devman_handle_t *handle)135 {136 assert(fun);137 hc_t *hc = fun_to_hc(fun);138 assert(hc);139 bool found =140 usb_device_keeper_find_by_address(&hc->manager, address, handle);141 return found ? EOK : ENOENT;142 }143 144 124 /*----------------------------------------------------------------------------*/ 145 125 /** Release address interface function … … 422 402 .request_address = request_address, 423 403 .bind_address = bind_address, 424 .find_by_address = find_by_address,425 404 .release_address = release_address, 426 405 -
uspace/drv/ohci/main.c
rf50f722 r68b614e 43 43 #define NAME "ohci" 44 44 45 /** Initializes a new ddf driver instance of OHCI hcd. 46 * 47 * @param[in] device DDF instance of the device to initialize. 48 * @return Error code. 49 */ 50 static int ohci_add_device(ddf_dev_t *device) 51 { 52 usb_log_debug("ohci_add_device() called\n"); 53 assert(device); 54 55 int ret = device_setup_ohci(device); 56 if (ret != EOK) { 57 usb_log_error("Failed to initialize OHCI driver: %s.\n", 58 str_error(ret)); 59 return ret; 60 } 61 usb_log_info("Controlling new OHCI device '%s'.\n", device->name); 62 63 return EOK; 64 } 45 static int ohci_add_device(ddf_dev_t *device); 65 46 /*----------------------------------------------------------------------------*/ 66 47 static driver_ops_t ohci_driver_ops = { … … 72 53 .driver_ops = &ohci_driver_ops 73 54 }; 55 /*----------------------------------------------------------------------------*/ 56 /** Initializes a new ddf driver instance of OHCI hcd. 57 * 58 * @param[in] device DDF instance of the device to initialize. 59 * @return Error code. 60 */ 61 int ohci_add_device(ddf_dev_t *device) 62 { 63 usb_log_debug("ohci_add_device() called\n"); 64 assert(device); 65 ohci_t *ohci = malloc(sizeof(ohci_t)); 66 if (ohci == NULL) { 67 usb_log_error("Failed to allocate OHCI driver.\n"); 68 return ENOMEM; 69 } 70 71 int ret = ohci_init(ohci, device); 72 if (ret != EOK) { 73 usb_log_error("Failed to initialize OHCI driver: %s.\n", 74 str_error(ret)); 75 return ret; 76 } 77 // device->driver_data = ohci; 78 hc_register_hub(&ohci->hc, ohci->rh_fun); 79 80 usb_log_info("Controlling new OHCI device `%s'.\n", device->name); 81 82 return EOK; 83 } 74 84 /*----------------------------------------------------------------------------*/ 75 85 /** Initializes global driver structures (NONE). -
uspace/drv/ohci/ohci.c
rf50f722 r68b614e 44 44 #include "iface.h" 45 45 #include "pci.h" 46 #include "hc.h"47 #include "root_hub.h"48 49 typedef struct ohci {50 ddf_fun_t *hc_fun;51 ddf_fun_t *rh_fun;52 53 hc_t hc;54 rh_t rh;55 } ohci_t;56 57 static inline ohci_t * dev_to_ohci(ddf_dev_t *dev)58 {59 assert(dev);60 assert(dev->driver_data);61 return dev->driver_data;62 }63 46 64 47 /** IRQ handling callback, identifies device … … 70 53 static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call) 71 54 { 72 hc_t *hc = &dev_to_ohci(dev)->hc; 55 assert(dev); 56 assert(dev->driver_data); 57 hc_t *hc = &((ohci_t*)dev->driver_data)->hc; 58 uint16_t status = IPC_GET_ARG1(*call); 73 59 assert(hc); 74 const uint16_t status = IPC_GET_ARG1(*call);75 60 hc_interrupt(hc, status); 76 61 } … … 86 71 { 87 72 assert(fun); 88 usb_device_keeper_t *manager = & dev_to_ohci(fun->dev)->hc.manager;73 usb_device_keeper_t *manager = &((ohci_t*)fun->dev->driver_data)->hc.manager; 89 74 90 75 usb_address_t addr = usb_device_keeper_find(manager, handle); … … 109 94 ddf_fun_t *fun, devman_handle_t *handle) 110 95 { 111 assert(fun); 112 ddf_fun_t *hc_fun = dev_to_ohci(fun->dev)->hc_fun; 113 assert(hc_fun); 114 115 if (handle != NULL) 116 *handle = hc_fun->handle; 96 assert(handle); 97 ddf_fun_t *hc_fun = ((ohci_t*)fun->dev->driver_data)->hc_fun; 98 assert(hc_fun != NULL); 99 100 *handle = hc_fun->handle; 117 101 return EOK; 118 102 } 119 103 /*----------------------------------------------------------------------------*/ 120 /** Root hub USB interface*/104 /** This iface is generic for both RH and HC. */ 121 105 static usb_iface_t usb_iface = { 122 106 .get_hc_handle = usb_iface_get_hc_handle, … … 124 108 }; 125 109 /*----------------------------------------------------------------------------*/ 126 /** Standard USB HC options (HC interface) */127 110 static ddf_dev_ops_t hc_ops = { 128 111 .interfaces[USBHC_DEV_IFACE] = &hc_iface, /* see iface.h/c */ 129 112 }; 130 113 /*----------------------------------------------------------------------------*/ 131 /** Standard USB RH options (RH interface) */132 114 static ddf_dev_ops_t rh_ops = { 133 115 .interfaces[USB_DEV_IFACE] = &usb_iface, … … 136 118 /** Initialize hc and rh ddf structures and their respective drivers. 137 119 * 120 * @param[in] instance OHCI structure to use. 138 121 * @param[in] device DDF instance of the device to use. 139 * @param[in] instance OHCI structure to use.140 122 * 141 123 * This function does all the preparatory work for hc and rh drivers: … … 145 127 * - registers interrupt handler 146 128 */ 147 int device_setup_ohci(ddf_dev_t *device) 148 { 149 ohci_t *instance = malloc(sizeof(ohci_t)); 150 if (instance == NULL) { 151 usb_log_error("Failed to allocate OHCI driver.\n"); 152 return ENOMEM; 153 } 154 155 #define CHECK_RET_DEST_FREE_RETURN(ret, message...) \ 129 int ohci_init(ohci_t *instance, ddf_dev_t *device) 130 { 131 assert(instance); 132 instance->hc_fun = NULL; 133 instance->rh_fun = NULL; 134 #define CHECK_RET_DEST_FUN_RETURN(ret, message...) \ 156 135 if (ret != EOK) { \ 157 if (instance->hc_fun) { \ 158 instance->hc_fun->ops = NULL; \ 159 instance->hc_fun->driver_data = NULL; \ 136 usb_log_error(message); \ 137 if (instance->hc_fun) \ 160 138 ddf_fun_destroy(instance->hc_fun); \ 161 } \ 162 if (instance->rh_fun) { \ 163 instance->rh_fun->ops = NULL; \ 164 instance->rh_fun->driver_data = NULL; \ 139 if (instance->rh_fun) \ 165 140 ddf_fun_destroy(instance->rh_fun); \ 166 } \167 free(instance); \168 usb_log_error(message); \169 141 return ret; \ 170 } else (void)0 171 172 instance->rh_fun = NULL; 173 instance->hc_fun = ddf_fun_create(device, fun_exposed, "ohci-hc"); 174 int ret = instance->hc_fun ? EOK : ENOMEM; 175 CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create OHCI HC function.\n"); 176 instance->hc_fun->ops = &hc_ops; 177 instance->hc_fun->driver_data = &instance->hc; 178 179 instance->rh_fun = ddf_fun_create(device, fun_inner, "ohci-rh"); 180 ret = instance->rh_fun ? EOK : ENOMEM; 181 CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create OHCI RH function.\n"); 182 instance->rh_fun->ops = &rh_ops; 183 184 uintptr_t reg_base = 0; 185 size_t reg_size = 0; 142 } 143 144 uintptr_t mem_reg_base = 0; 145 size_t mem_reg_size = 0; 186 146 int irq = 0; 187 147 188 ret = pci_get_my_registers(device, ®_base, ®_size, &irq); 189 CHECK_RET_DEST_FREE_RETURN(ret, 148 int ret = 149 pci_get_my_registers(device, &mem_reg_base, &mem_reg_size, &irq); 150 CHECK_RET_DEST_FUN_RETURN(ret, 190 151 "Failed to get memory addresses for %" PRIun ": %s.\n", 191 152 device->handle, str_error(ret)); 192 153 usb_log_debug("Memory mapped regs at %p (size %zu), IRQ %d.\n", 193 (void *) reg_base,reg_size, irq);154 (void *) mem_reg_base, mem_reg_size, irq); 194 155 195 156 bool interrupts = false; 196 157 #ifdef CONFIG_USBHC_NO_INTERRUPTS 197 usb_log_warning("Interrupts disabled in OS config, " 158 usb_log_warning("Interrupts disabled in OS config, " \ 198 159 "falling back to polling.\n"); 199 160 #else … … 202 163 usb_log_warning("Failed to enable interrupts: %s.\n", 203 164 str_error(ret)); 204 usb_log_info("HW interrupts not available, " 165 usb_log_info("HW interrupts not available, " \ 205 166 "falling back to polling.\n"); 206 167 } else { … … 210 171 #endif 211 172 212 ret = hc_init(&instance->hc, reg_base, reg_size, interrupts); 213 CHECK_RET_DEST_FREE_RETURN(ret, "Failed(%d) to init ohci-hcd.\n", ret); 173 instance->hc_fun = ddf_fun_create(device, fun_exposed, "ohci-hc"); 174 ret = (instance->hc_fun == NULL) ? ENOMEM : EOK; 175 CHECK_RET_DEST_FUN_RETURN(ret, 176 "Failed(%d) to create HC function.\n", ret); 177 178 ret = hc_init(&instance->hc, instance->hc_fun, device, 179 mem_reg_base, mem_reg_size, interrupts); 180 CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to init ohci-hcd.\n", ret); 181 instance->hc_fun->ops = &hc_ops; 182 instance->hc_fun->driver_data = &instance->hc; 183 ret = ddf_fun_bind(instance->hc_fun); 184 CHECK_RET_DEST_FUN_RETURN(ret, 185 "Failed(%d) to bind OHCI device function: %s.\n", 186 ret, str_error(ret)); 187 ret = ddf_fun_add_to_class(instance->hc_fun, USB_HC_DDF_CLASS_NAME); 188 CHECK_RET_DEST_FUN_RETURN(ret, 189 "Failed to add OHCI to HC class: %s.\n", str_error(ret)); 190 191 #undef CHECK_RET_HC_RETURN 214 192 215 193 #define CHECK_RET_FINI_RETURN(ret, message...) \ 216 194 if (ret != EOK) { \ 195 usb_log_error(message); \ 196 if (instance->hc_fun) \ 197 ddf_fun_destroy(instance->hc_fun); \ 198 if (instance->rh_fun) \ 199 ddf_fun_destroy(instance->rh_fun); \ 217 200 hc_fini(&instance->hc); \ 218 CHECK_RET_DEST_FREE_RETURN(ret, message); \219 } else (void)0201 return ret; \ 202 } 220 203 221 204 /* It does no harm if we register this on polling */ … … 225 208 "Failed(%d) to register interrupt handler.\n", ret); 226 209 227 ret = ddf_fun_bind(instance->hc_fun); 210 instance->rh_fun = ddf_fun_create(device, fun_inner, "ohci-rh"); 211 ret = (instance->rh_fun == NULL) ? ENOMEM : EOK; 228 212 CHECK_RET_FINI_RETURN(ret, 229 "Failed(%d) to bind OHCI device function: %s.\n", 230 ret, str_error(ret)); 231 232 ret = ddf_fun_add_to_class(instance->hc_fun, USB_HC_DDF_CLASS_NAME); 233 CHECK_RET_FINI_RETURN(ret, 234 "Failed to add OHCI to HC class: %s.\n", str_error(ret)); 235 213 "Failed(%d) to create root hub function.\n", ret); 214 215 216 instance->rh_fun->ops = &rh_ops; 217 instance->rh_fun->driver_data = NULL; 218 236 219 device->driver_data = instance; 237 220 238 221 hc_start_hw(&instance->hc); 239 hc_register_hub(&instance->hc, instance->rh_fun);240 222 return EOK; 241 242 #undef CHECK_RET_DEST_FUN_RETURN243 223 #undef CHECK_RET_FINI_RETURN 244 224 } -
uspace/drv/ohci/ohci.h
rf50f722 r68b614e 38 38 #include <ddf/driver.h> 39 39 40 int device_setup_ohci(ddf_dev_t *device); 40 #include "hc.h" 41 #include "root_hub.h" 42 43 typedef struct ohci { 44 ddf_fun_t *hc_fun; 45 ddf_fun_t *rh_fun; 46 47 hc_t hc; 48 rh_t rh; 49 } ohci_t; 50 51 int ohci_init(ohci_t *instance, ddf_dev_t *device); 41 52 42 53 #endif -
uspace/drv/ohci/pci.c
rf50f722 r68b614e 58 58 uintptr_t *mem_reg_address, size_t *mem_reg_size, int *irq_no) 59 59 { 60 assert(dev); 61 assert(mem_reg_address); 62 assert(mem_reg_size); 63 assert(irq_no); 60 assert(dev != NULL); 64 61 65 62 int parent_phone = devman_parent_device_connect(dev->handle, -
uspace/drv/ohci/root_hub.c
rf50f722 r68b614e 237 237 return ENOMEM; 238 238 239 usb_log_info("OHCI root hub with % zuports initialized.\n",239 usb_log_info("OHCI root hub with %d ports initialized.\n", 240 240 instance->port_count); 241 241 -
uspace/drv/uhci-hcd/hc.c
rf50f722 r68b614e 60 60 * 61 61 * @param[in] instance Memory place to initialize. 62 * @param[in] fun DDF function. 62 63 * @param[in] regs Address of I/O control registers. 63 64 * @param[in] size Size of I/O control registers. … … 68 69 * interrupt fibrils. 69 70 */ 70 int hc_init(hc_t *instance, void *regs, size_t reg_size, bool interrupts) 71 int hc_init(hc_t *instance, ddf_fun_t *fun, 72 void *regs, size_t reg_size, bool interrupts) 71 73 { 72 74 assert(reg_size >= sizeof(regs_t)); -
uspace/drv/uhci-hcd/hc.h
rf50f722 r68b614e 136 136 } hc_t; 137 137 138 int hc_init(hc_t *instance, void *regs, size_t reg_size, bool interupts); 138 int hc_init(hc_t *instance, ddf_fun_t *fun, 139 void *regs, size_t reg_size, bool interupts); 139 140 140 141 int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch); -
uspace/drv/uhci-hcd/iface.c
rf50f722 r68b614e 122 122 return EOK; 123 123 } 124 125 /** Find device handle by address interface function.126 *127 * @param[in] fun DDF function that was called.128 * @param[in] address Address in question.129 * @param[out] handle Where to store device handle if found.130 * @return Error code.131 */132 static int find_by_address(ddf_fun_t *fun, usb_address_t address,133 devman_handle_t *handle)134 {135 assert(fun);136 hc_t *hc = fun_to_hc(fun);137 assert(hc);138 bool found =139 usb_device_keeper_find_by_address(&hc->manager, address, handle);140 return found ? EOK : ENOENT;141 }142 143 124 /*----------------------------------------------------------------------------*/ 144 125 /** Release address interface function … … 371 352 .request_address = request_address, 372 353 .bind_address = bind_address, 373 .find_by_address = find_by_address,374 354 .release_address = release_address, 375 355 -
uspace/drv/uhci-hcd/main.c
rf50f722 r68b614e 64 64 assert(device); 65 65 66 int ret = device_setup_uhci(device); 66 uhci_t *uhci = malloc(sizeof(uhci_t)); 67 if (uhci == NULL) { 68 usb_log_error("Failed to allocate UHCI driver.\n"); 69 return ENOMEM; 70 } 71 72 int ret = uhci_init(uhci, device); 67 73 if (ret != EOK) { 68 74 usb_log_error("Failed to initialize UHCI driver: %s.\n", … … 70 76 return ret; 71 77 } 78 device->driver_data = uhci; 79 72 80 usb_log_info("Controlling new UHCI device '%s'.\n", device->name); 73 81 -
uspace/drv/uhci-hcd/uhci.c
rf50f722 r68b614e 44 44 #include "pci.h" 45 45 46 #include "hc.h"47 #include "root_hub.h"48 49 /** Structure representing both functions of UHCI hc, USB host controller50 * and USB root hub */51 typedef struct uhci {52 /** Pointer to DDF represenation of UHCI host controller */53 ddf_fun_t *hc_fun;54 /** Pointer to DDF represenation of UHCI root hub */55 ddf_fun_t *rh_fun;56 57 /** Internal driver's represenation of UHCI host controller */58 hc_t hc;59 /** Internal driver's represenation of UHCI root hub */60 rh_t rh;61 } uhci_t;62 63 static inline uhci_t * dev_to_uhci(ddf_dev_t *dev)64 {65 assert(dev);66 assert(dev->driver_data);67 return dev->driver_data;68 }69 /*----------------------------------------------------------------------------*/70 46 /** IRQ handling callback, forward status from call to diver structure. 71 47 * … … 93 69 { 94 70 assert(fun); 95 usb_device_keeper_t *manager = &dev_to_uhci(fun->dev)->hc.manager; 71 usb_device_keeper_t *manager = 72 &((uhci_t*)fun->dev->driver_data)->hc.manager; 73 96 74 usb_address_t addr = usb_device_keeper_find(manager, handle); 97 98 75 if (addr < 0) { 99 76 return addr; … … 116 93 ddf_fun_t *fun, devman_handle_t *handle) 117 94 { 118 assert(fun); 119 ddf_fun_t *hc_fun = dev_to_uhci(fun->dev)->hc_fun; 120 assert(hc_fun); 121 122 if (handle != NULL) 123 *handle = hc_fun->handle; 95 assert(handle); 96 ddf_fun_t *hc_fun = ((uhci_t*)fun->dev->driver_data)->hc_fun; 97 assert(hc_fun != NULL); 98 99 *handle = hc_fun->handle; 124 100 return EOK; 125 101 } … … 150 126 static hw_res_ops_t hw_res_iface = { 151 127 .get_resource_list = get_resource_list, 152 .enable_interrupt = NULL ,128 .enable_interrupt = NULL 153 129 }; 154 130 /*----------------------------------------------------------------------------*/ … … 170 146 * - registers interrupt handler 171 147 */ 172 int device_setup_uhci(ddf_dev_t *device) 173 { 174 assert(device); 175 uhci_t *instance = malloc(sizeof(uhci_t)); 176 if (instance == NULL) { 177 usb_log_error("Failed to allocate OHCI driver.\n"); 178 return ENOMEM; 179 } 180 181 #define CHECK_RET_DEST_FREE_RETURN(ret, message...) \ 148 int uhci_init(uhci_t *instance, ddf_dev_t *device) 149 { 150 assert(instance); 151 instance->hc_fun = NULL; 152 instance->rh_fun = NULL; 153 #define CHECK_RET_DEST_FUN_RETURN(ret, message...) \ 182 154 if (ret != EOK) { \ 155 usb_log_error(message); \ 183 156 if (instance->hc_fun) \ 184 instance->hc_fun->ops = NULL; \185 instance->hc_fun->driver_data = NULL; \186 157 ddf_fun_destroy(instance->hc_fun); \ 187 if (instance->rh_fun) {\ 188 instance->rh_fun->ops = NULL; \ 189 instance->rh_fun->driver_data = NULL; \ 158 if (instance->rh_fun) \ 190 159 ddf_fun_destroy(instance->rh_fun); \ 191 } \192 free(instance); \193 usb_log_error(message); \194 160 return ret; \ 195 } else (void)0 196 197 instance->rh_fun = NULL; 198 instance->hc_fun = ddf_fun_create(device, fun_exposed, "uhci-hc"); 199 int ret = (instance->hc_fun == NULL) ? ENOMEM : EOK; 200 CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create UHCI HC function.\n"); 201 instance->hc_fun->ops = &hc_ops; 202 instance->hc_fun->driver_data = &instance->hc; 203 204 instance->rh_fun = ddf_fun_create(device, fun_inner, "uhci-rh"); 205 ret = (instance->rh_fun == NULL) ? ENOMEM : EOK; 206 CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create UHCI RH function.\n"); 207 instance->rh_fun->ops = &rh_ops; 208 instance->rh_fun->driver_data = &instance->rh; 209 210 uintptr_t reg_base = 0; 211 size_t reg_size = 0; 161 } 162 163 uintptr_t io_reg_base = 0; 164 size_t io_reg_size = 0; 212 165 int irq = 0; 213 166 214 ret = pci_get_my_registers(device, ®_base, ®_size, &irq); 215 CHECK_RET_DEST_FREE_RETURN(ret, 167 int ret = 168 pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq); 169 CHECK_RET_DEST_FUN_RETURN(ret, 216 170 "Failed to get I/O addresses for %" PRIun ": %s.\n", 217 171 device->handle, str_error(ret)); 218 172 usb_log_debug("I/O regs at 0x%p (size %zu), IRQ %d.\n", 219 (void *) reg_base,reg_size, irq);173 (void *) io_reg_base, io_reg_size, irq); 220 174 221 175 ret = pci_disable_legacy(device); 222 CHECK_RET_DEST_F REE_RETURN(ret,176 CHECK_RET_DEST_FUN_RETURN(ret, 223 177 "Failed(%d) to disable legacy USB: %s.\n", ret, str_error(ret)); 224 178 … … 240 194 #endif 241 195 242 243 ret = hc_init(&instance->hc, (void*)reg_base, reg_size, interrupts); 244 CHECK_RET_DEST_FREE_RETURN(ret, 196 instance->hc_fun = ddf_fun_create(device, fun_exposed, "uhci-hc"); 197 ret = (instance->hc_fun == NULL) ? ENOMEM : EOK; 198 CHECK_RET_DEST_FUN_RETURN(ret, 199 "Failed(%d) to create HC function: %s.\n", ret, str_error(ret)); 200 201 ret = hc_init(&instance->hc, instance->hc_fun, 202 (void*)io_reg_base, io_reg_size, interrupts); 203 CHECK_RET_DEST_FUN_RETURN(ret, 245 204 "Failed(%d) to init uhci-hcd: %s.\n", ret, str_error(ret)); 205 206 instance->hc_fun->ops = &hc_ops; 207 instance->hc_fun->driver_data = &instance->hc; 208 ret = ddf_fun_bind(instance->hc_fun); 209 CHECK_RET_DEST_FUN_RETURN(ret, 210 "Failed(%d) to bind UHCI device function: %s.\n", 211 ret, str_error(ret)); 212 ret = ddf_fun_add_to_class(instance->hc_fun, USB_HC_DDF_CLASS_NAME); 213 CHECK_RET_DEST_FUN_RETURN(ret, 214 "Failed to add UHCI to HC class: %s.\n", str_error(ret)); 215 216 #undef CHECK_RET_HC_RETURN 246 217 247 218 #define CHECK_RET_FINI_RETURN(ret, message...) \ 248 219 if (ret != EOK) { \ 220 usb_log_error(message); \ 221 if (instance->hc_fun) \ 222 ddf_fun_destroy(instance->hc_fun); \ 223 if (instance->rh_fun) \ 224 ddf_fun_destroy(instance->rh_fun); \ 249 225 hc_fini(&instance->hc); \ 250 CHECK_RET_DEST_FREE_RETURN(ret, message); \251 226 return ret; \ 252 } else (void)0227 } 253 228 254 229 /* It does no harm if we register this on polling */ … … 259 234 ret, str_error(ret)); 260 235 261 ret = ddf_fun_bind(instance->hc_fun); 262 CHECK_RET_FINI_RETURN(ret, 263 "Failed(%d) to bind UHCI device function: %s.\n", 236 instance->rh_fun = ddf_fun_create(device, fun_inner, "uhci-rh"); 237 ret = (instance->rh_fun == NULL) ? ENOMEM : EOK; 238 CHECK_RET_FINI_RETURN(ret, 239 "Failed(%d) to create root hub function: %s.\n", 264 240 ret, str_error(ret)); 265 266 ret = ddf_fun_add_to_class(instance->hc_fun, USB_HC_DDF_CLASS_NAME);267 CHECK_RET_FINI_RETURN(ret,268 "Failed to add UHCI to HC class: %s.\n", str_error(ret));269 241 270 242 ret = rh_init(&instance->rh, instance->rh_fun, … … 273 245 "Failed(%d) to setup UHCI root hub: %s.\n", ret, str_error(ret)); 274 246 247 instance->rh_fun->ops = &rh_ops; 248 instance->rh_fun->driver_data = &instance->rh; 275 249 ret = ddf_fun_bind(instance->rh_fun); 276 250 CHECK_RET_FINI_RETURN(ret, 277 251 "Failed(%d) to register UHCI root hub: %s.\n", ret, str_error(ret)); 278 252 279 device->driver_data = instance;280 253 return EOK; 281 254 #undef CHECK_RET_FINI_RETURN -
uspace/drv/uhci-hcd/uhci.h
rf50f722 r68b614e 38 38 #include <ddf/driver.h> 39 39 40 int device_setup_uhci(ddf_dev_t *device); 40 #include "hc.h" 41 #include "root_hub.h" 42 43 /** Structure representing both functions of UHCI hc, USB host controller 44 * and USB root hub */ 45 typedef struct uhci { 46 /** Pointer to DDF represenation of UHCI host controller */ 47 ddf_fun_t *hc_fun; 48 /** Pointer to DDF represenation of UHCI root hub */ 49 ddf_fun_t *rh_fun; 50 51 /** Internal driver's represenation of UHCI host controller */ 52 hc_t hc; 53 /** Internal driver's represenation of UHCI root hub */ 54 rh_t rh; 55 } uhci_t; 56 57 int uhci_init(uhci_t *instance, ddf_dev_t *device); 41 58 #endif 42 59 /** -
uspace/drv/vhc/connhost.c
rf50f722 r68b614e 94 94 } 95 95 96 /** Find device handle by address interface function.97 *98 * @param[in] fun DDF function that was called.99 * @param[in] address Address in question.100 * @param[out] handle Where to store device handle if found.101 * @return Error code.102 */103 static int find_by_address(ddf_fun_t *fun, usb_address_t address,104 devman_handle_t *handle)105 {106 VHC_DATA(vhc, fun);107 bool found =108 usb_device_keeper_find_by_address(&vhc->dev_keeper, address, handle);109 return found ? EOK : ENOENT;110 }111 112 96 /** Release previously requested address. 113 97 * … … 460 444 .request_address = request_address, 461 445 .bind_address = bind_address, 462 .find_by_address = find_by_address,463 446 .release_address = release_address, 464 447 -
uspace/lib/drv/generic/remote_usbhc.c
rf50f722 r68b614e 52 52 static void remote_usbhc_request_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 53 53 static void remote_usbhc_bind_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 54 static void remote_usbhc_find_by_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);55 54 static void remote_usbhc_release_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 56 55 static void remote_usbhc_register_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); … … 62 61 remote_usbhc_request_address, 63 62 remote_usbhc_bind_address, 64 remote_usbhc_find_by_address,65 63 remote_usbhc_release_address, 66 64 … … 165 163 } 166 164 167 void remote_usbhc_find_by_address(ddf_fun_t *fun, void *iface,168 ipc_callid_t callid, ipc_call_t *call)169 {170 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;171 172 if (!usb_iface->find_by_address) {173 async_answer_0(callid, ENOTSUP);174 return;175 }176 177 usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);178 devman_handle_t handle;179 int rc = usb_iface->find_by_address(fun, address, &handle);180 181 if (rc == EOK) {182 async_answer_1(callid, EOK, handle);183 } else {184 async_answer_0(callid, rc);185 }186 }187 188 165 void remote_usbhc_release_address(ddf_fun_t *fun, void *iface, 189 166 ipc_callid_t callid, ipc_call_t *call) … … 325 302 async_transaction_t *trans = async_transaction_create(callid); 326 303 if (trans == NULL) { 327 async_answer_0(data_callid, ENOMEM);328 304 async_answer_0(callid, ENOMEM); 329 305 return; … … 338 314 339 315 if (rc != EOK) { 340 async_answer_0(data_callid, rc);341 316 async_answer_0(callid, rc); 342 317 async_transaction_destroy(trans); … … 485 460 async_transaction_t *trans = async_transaction_create(callid); 486 461 if (trans == NULL) { 487 async_answer_0(data_callid, ENOMEM);488 462 async_answer_0(callid, ENOMEM); 489 463 free(setup_packet); … … 495 469 trans->buffer = malloc(data_len); 496 470 if (trans->buffer == NULL) { 497 async_answer_0(data_callid, ENOMEM);498 471 async_answer_0(callid, ENOMEM); 499 472 async_transaction_destroy(trans); … … 507 480 508 481 if (rc != EOK) { 509 async_answer_0(data_callid, rc);510 482 async_answer_0(callid, rc); 511 483 async_transaction_destroy(trans); -
uspace/lib/drv/include/usb_iface.h
rf50f722 r68b614e 49 49 * - arbitrary error code if returned by remote implementation 50 50 * - EOK - handle found, first parameter contains the USB address 51 *52 * The handle must be the one used for binding USB address with53 * it (IPC_M_USBHC_BIND_ADDRESS), otherwise the host controller54 * (that this request would eventually reach) would not be able55 * to find it.56 * The problem is that this handle is actually assigned to the57 * function inside driver of the parent device (usually hub driver).58 * To bypass this problem, the initial caller specify handle as59 * zero and the first parent assigns the actual value.60 * See usb_iface_get_address_hub_child_impl() implementation61 * that could be assigned to device ops of a child device of in a62 * hub driver.63 * For example, the USB multi interface device driver (MID)64 * passes this initial zero without any modification because the65 * handle must be resolved by its parent.66 51 */ 67 52 IPC_M_USB_GET_ADDRESS, -
uspace/lib/drv/include/usbhc_iface.h
rf50f722 r68b614e 105 105 IPC_M_USBHC_BIND_ADDRESS, 106 106 107 /** Get handle binded with given USB address.108 * Parameters109 * - USB address110 * Answer:111 * - EOK - address binded, first parameter is the devman handle112 * - ENOENT - address is not in use at the moment113 */114 IPC_M_USBHC_GET_HANDLE_BY_ADDRESS,115 116 107 /** Release address in use. 117 108 * Arguments: … … 216 207 int (*request_address)(ddf_fun_t *, usb_speed_t, usb_address_t *); 217 208 int (*bind_address)(ddf_fun_t *, usb_address_t, devman_handle_t); 218 int (*find_by_address)(ddf_fun_t *, usb_address_t, devman_handle_t *);219 209 int (*release_address)(ddf_fun_t *, usb_address_t); 220 210 -
uspace/lib/usb/include/usb/host/device_keeper.h
rf50f722 r68b614e 80 80 devman_handle_t handle); 81 81 82 bool usb_device_keeper_find_by_address(usb_device_keeper_t *instance,83 usb_address_t address, devman_handle_t *handle);84 85 82 usb_speed_t usb_device_keeper_get_speed(usb_device_keeper_t *instance, 86 83 usb_address_t address); -
uspace/lib/usb/include/usb/hub.h
rf50f722 r68b614e 63 63 const usb_hc_attached_device_t *); 64 64 int usb_hc_unregister_device(usb_hc_connection_t *, usb_address_t); 65 int usb_hc_get_handle_by_address(usb_hc_connection_t *, usb_address_t,66 devman_handle_t *);67 65 68 66 #endif -
uspace/lib/usb/src/host/device_keeper.c
rf50f722 r68b614e 157 157 return ENOENT; 158 158 } 159 160 /** Find devman handled assigned to USB address.161 *162 * @param[in] instance Device keeper structure to use.163 * @param[in] address Address the caller wants to find.164 * @param[out] handle Where to store found handle.165 * @return Whether such address is currently occupied.166 */167 bool usb_device_keeper_find_by_address(usb_device_keeper_t *instance,168 usb_address_t address, devman_handle_t *handle)169 {170 assert(instance);171 fibril_mutex_lock(&instance->guard);172 if ((address < 0) || (address >= USB_ADDRESS_COUNT)) {173 fibril_mutex_unlock(&instance->guard);174 return false;175 }176 if (!instance->devices[address].occupied) {177 fibril_mutex_unlock(&instance->guard);178 return false;179 }180 181 if (handle != NULL) {182 *handle = instance->devices[address].handle;183 }184 185 fibril_mutex_unlock(&instance->guard);186 return true;187 }188 189 159 /*----------------------------------------------------------------------------*/ 190 160 /** Get speed associated with the address -
uspace/lib/usb/src/hub.c
rf50f722 r68b614e 117 117 DEV_IFACE_ID(USBHC_DEV_IFACE), 118 118 IPC_M_USBHC_RELEASE_ADDRESS, address); 119 }120 121 /** Get handle of USB device with given address.122 *123 * @param[in] connection Opened connection to host controller.124 * @param[in] address Address of device in question.125 * @param[out] handle Where to write the device handle.126 * @return Error code.127 */128 int usb_hc_get_handle_by_address(usb_hc_connection_t *connection,129 usb_address_t address, devman_handle_t *handle)130 {131 CHECK_CONNECTION(connection);132 133 sysarg_t tmp;134 int rc = async_req_2_1(connection->hc_phone,135 DEV_IFACE_ID(USBHC_DEV_IFACE),136 IPC_M_USBHC_GET_HANDLE_BY_ADDRESS,137 address, &tmp);138 if ((rc == EOK) && (handle != NULL)) {139 *handle = tmp;140 }141 142 return rc;143 119 } 144 120
Note:
See TracChangeset
for help on using the changeset viewer.