Changeset 233e68d in mainline for uspace/drv/uhci-hcd
- Timestamp:
- 2011-02-23T18:28:41Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e9e58ea3
- Parents:
- deece2f (diff), a9c674e0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/drv/uhci-hcd
- Files:
-
- 11 edited
-
batch.c (modified) (5 diffs)
-
batch.h (modified) (2 diffs)
-
iface.c (modified) (14 diffs)
-
iface.h (modified) (1 diff)
-
main.c (modified) (10 diffs)
-
pci.c (modified) (2 diffs)
-
pci.h (modified) (1 diff)
-
root_hub.c (modified) (2 diffs)
-
root_hub.h (modified) (1 diff)
-
uhci.c (modified) (3 diffs)
-
uhci.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/batch.c
rdeece2f r233e68d 51 51 52 52 53 batch_t * batch_get(d evice_t *dev, usb_target_t target,53 batch_t * batch_get(ddf_fun_t *fun, usb_target_t target, 54 54 usb_transfer_type_t transfer_type, size_t max_packet_size, 55 55 dev_speed_t speed, char *buffer, size_t size, … … 128 128 instance->buffer_size = size; 129 129 instance->setup_size = setup_size; 130 instance-> dev = dev;130 instance->fun = fun; 131 131 instance->arg = arg; 132 132 instance->speed = speed; … … 291 291 err, instance->transfered_size); 292 292 293 instance->callback_in(instance-> dev,293 instance->callback_in(instance->fun, 294 294 err, instance->transfered_size, 295 295 instance->arg); … … 303 303 int err = instance->error; 304 304 usb_log_info("Callback OUT(%d): %d.\n", instance->transfer_type, err); 305 instance->callback_out(instance-> dev,305 instance->callback_out(instance->fun, 306 306 err, instance->arg); 307 307 } … … 334 334 { 335 335 assert(instance); 336 uhci_t *hc = dev_to_uhci(instance->dev);336 uhci_t *hc = fun_to_uhci(instance->fun); 337 337 assert(hc); 338 338 return uhci_schedule(hc, instance); -
uspace/drv/uhci-hcd/batch.h
rdeece2f r233e68d 68 68 size_t transfered_size; 69 69 int error; 70 d evice_t *dev;70 ddf_fun_t *fun; 71 71 queue_head_t *qh; 72 72 transfer_descriptor_t *tds; … … 74 74 } batch_t; 75 75 76 batch_t * batch_get(d evice_t *dev, usb_target_t target,76 batch_t * batch_get(ddf_fun_t *fun, usb_target_t target, 77 77 usb_transfer_type_t transfer_type, size_t max_packet_size, 78 78 dev_speed_t speed, char *buffer, size_t size, -
uspace/drv/uhci-hcd/iface.c
rdeece2f r233e68d 32 32 * @brief UHCI driver 33 33 */ 34 #include <d river.h>34 #include <ddf/driver.h> 35 35 #include <remote_usbhc.h> 36 36 … … 43 43 44 44 /*----------------------------------------------------------------------------*/ 45 static int reserve_default_address(d evice_t *dev, usb_speed_t speed)45 static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed) 46 46 { 47 assert( dev);48 uhci_t *hc = dev_to_uhci(dev);47 assert(fun); 48 uhci_t *hc = fun_to_uhci(fun); 49 49 assert(hc); 50 50 usb_address_keeping_reserve_default(&hc->address_manager); … … 52 52 } 53 53 /*----------------------------------------------------------------------------*/ 54 static int release_default_address(d evice_t *dev)54 static int release_default_address(ddf_fun_t *fun) 55 55 { 56 assert( dev);57 uhci_t *hc = dev_to_uhci(dev);56 assert(fun); 57 uhci_t *hc = fun_to_uhci(fun); 58 58 assert(hc); 59 59 usb_address_keeping_release_default(&hc->address_manager); … … 61 61 } 62 62 /*----------------------------------------------------------------------------*/ 63 static int request_address(d evice_t *dev, usb_speed_t speed,63 static int request_address(ddf_fun_t *fun, usb_speed_t speed, 64 64 usb_address_t *address) 65 65 { 66 assert( dev);67 uhci_t *hc = dev_to_uhci(dev);66 assert(fun); 67 uhci_t *hc = fun_to_uhci(fun); 68 68 assert(hc); 69 69 *address = usb_address_keeping_request(&hc->address_manager); … … 74 74 /*----------------------------------------------------------------------------*/ 75 75 static int bind_address( 76 d evice_t *dev, usb_address_t address, devman_handle_t handle)76 ddf_fun_t *fun, usb_address_t address, devman_handle_t handle) 77 77 { 78 assert( dev);79 uhci_t *hc = dev_to_uhci(dev);78 assert(fun); 79 uhci_t *hc = fun_to_uhci(fun); 80 80 assert(hc); 81 81 usb_address_keeping_devman_bind(&hc->address_manager, address, handle); … … 83 83 } 84 84 /*----------------------------------------------------------------------------*/ 85 static int release_address(d evice_t *dev, usb_address_t address)85 static int release_address(ddf_fun_t *fun, usb_address_t address) 86 86 { 87 assert( dev);88 uhci_t *hc = dev_to_uhci(dev);87 assert(fun); 88 uhci_t *hc = fun_to_uhci(fun); 89 89 assert(hc); 90 90 usb_address_keeping_release_default(&hc->address_manager); … … 92 92 } 93 93 /*----------------------------------------------------------------------------*/ 94 static int interrupt_out(d evice_t *dev, usb_target_t target,94 static int interrupt_out(ddf_fun_t *fun, usb_target_t target, 95 95 size_t max_packet_size, 96 96 void *data, size_t size, … … 99 99 dev_speed_t speed = FULL_SPEED; 100 100 101 batch_t *batch = batch_get( dev, target, USB_TRANSFER_INTERRUPT,101 batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT, 102 102 max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg); 103 103 if (!batch) … … 107 107 } 108 108 /*----------------------------------------------------------------------------*/ 109 static int interrupt_in(d evice_t *dev, usb_target_t target,109 static int interrupt_in(ddf_fun_t *fun, usb_target_t target, 110 110 size_t max_packet_size, 111 111 void *data, size_t size, … … 114 114 dev_speed_t speed = FULL_SPEED; 115 115 116 batch_t *batch = batch_get( dev, target, USB_TRANSFER_INTERRUPT,116 batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT, 117 117 max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg); 118 118 if (!batch) … … 122 122 } 123 123 /*----------------------------------------------------------------------------*/ 124 static int control_write(d evice_t *dev, usb_target_t target,124 static int control_write(ddf_fun_t *fun, usb_target_t target, 125 125 size_t max_packet_size, 126 126 void *setup_data, size_t setup_size, void *data, size_t size, … … 129 129 dev_speed_t speed = FULL_SPEED; 130 130 131 batch_t *batch = batch_get( dev, target, USB_TRANSFER_CONTROL,131 batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL, 132 132 max_packet_size, speed, data, size, setup_data, setup_size, 133 133 NULL, callback, arg); … … 138 138 } 139 139 /*----------------------------------------------------------------------------*/ 140 static int control_read(d evice_t *dev, usb_target_t target,140 static int control_read(ddf_fun_t *fun, usb_target_t target, 141 141 size_t max_packet_size, 142 142 void *setup_data, size_t setup_size, void *data, size_t size, … … 145 145 dev_speed_t speed = FULL_SPEED; 146 146 147 batch_t *batch = batch_get( dev, target, USB_TRANSFER_CONTROL,147 batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL, 148 148 max_packet_size, speed, data, size, setup_data, setup_size, callback, 149 149 NULL, arg); -
uspace/drv/uhci-hcd/iface.h
rdeece2f r233e68d 38 38 #include <usbhc_iface.h> 39 39 40 usbhc_iface_t uhci_iface;40 extern usbhc_iface_t uhci_iface; 41 41 42 42 #endif -
uspace/drv/uhci-hcd/main.c
rdeece2f r233e68d 32 32 * @brief UHCI driver 33 33 */ 34 #include <driver.h> 34 #include <ddf/driver.h> 35 #include <ddf/interrupt.h> 35 36 #include <usb_iface.h> 36 37 #include <usb/ddfiface.h> … … 48 49 #define NAME "uhci-hcd" 49 50 50 static int uhci_add_device(d evice_t *device);51 static int uhci_add_device(ddf_dev_t *device); 51 52 52 static int usb_iface_get_address(device_t *dev, devman_handle_t handle,53 usb_address_t *address)54 {55 assert(dev);56 uhci_t *hc = dev_to_uhci(dev);57 assert(hc);58 59 usb_address_t addr = usb_address_keeping_find(&hc->address_manager,60 handle);61 if (addr < 0) {62 return addr;63 }64 65 if (address != NULL) {66 *address = addr;67 }68 69 return EOK;70 }71 72 73 static usb_iface_t hc_usb_iface = {74 .get_hc_handle = usb_iface_get_hc_handle_hc_impl,75 .get_address = usb_iface_get_address76 };77 /*----------------------------------------------------------------------------*/78 static device_ops_t uhci_ops = {79 .interfaces[USB_DEV_IFACE] = &hc_usb_iface,80 .interfaces[USBHC_DEV_IFACE] = &uhci_iface81 };82 53 /*----------------------------------------------------------------------------*/ 83 54 static driver_ops_t uhci_driver_ops = { … … 90 61 }; 91 62 /*----------------------------------------------------------------------------*/ 92 static void irq_handler(d evice_t *device, ipc_callid_t iid, ipc_call_t *call)63 static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call) 93 64 { 94 assert(dev ice);95 uhci_t *hc = dev_to_uhci(dev ice);65 assert(dev); 66 uhci_t *hc = dev_to_uhci(dev); 96 67 uint16_t status = IPC_GET_ARG1(*call); 97 68 assert(hc); … … 105 76 } 106 77 107 static int uhci_add_device(d evice_t *device)78 static int uhci_add_device(ddf_dev_t *device) 108 79 { 109 80 assert(device); 110 81 111 82 usb_log_info("uhci_add_device() called\n"); 112 device->ops = &uhci_ops; 83 113 84 114 85 uintptr_t io_reg_base; … … 131 102 CHECK_RET_RETURN(ret, "Failed to allocate memory for uhci hcd driver.\n"); 132 103 133 ret = uhci_init(uhci_hc, (void*)io_reg_base, io_reg_size);104 ret = uhci_init(uhci_hc, device, (void*)io_reg_base, io_reg_size); 134 105 if (ret != EOK) { 135 106 usb_log_error("Failed to init uhci-hcd.\n"); … … 137 108 return ret; 138 109 } 110 111 /* 112 * We might free uhci_hc, but that does not matter since no one 113 * else would access driver_data anyway. 114 */ 115 device->driver_data = uhci_hc; 139 116 140 117 ret = register_interrupt_handler(device, irq, irq_handler, … … 147 124 } 148 125 149 d evice_t *rh;126 ddf_fun_t *rh; 150 127 ret = setup_root_hub(&rh, device); 151 128 if (ret != EOK) { … … 155 132 return ret; 156 133 } 134 rh->driver_data = uhci_hc->ddf_instance; 157 135 158 ret = child_device_register(rh, device);136 ret = ddf_fun_bind(rh); 159 137 if (ret != EOK) { 160 138 usb_log_error("Failed to register root hub.\n"); … … 165 143 } 166 144 167 device->driver_data = uhci_hc;168 145 return EOK; 169 146 } … … 172 149 { 173 150 sleep(3); 174 usb_log_enable(USB_LOG_LEVEL_ DEBUG, NAME);151 usb_log_enable(USB_LOG_LEVEL_INFO, NAME); 175 152 176 return d river_main(&uhci_driver);153 return ddf_driver_main(&uhci_driver); 177 154 } 178 155 /** -
uspace/drv/uhci-hcd/pci.c
rdeece2f r233e68d 49 49 * @return Error code. 50 50 */ 51 int pci_get_my_registers(d evice_t *dev,51 int pci_get_my_registers(ddf_dev_t *dev, 52 52 uintptr_t *io_reg_address, size_t *io_reg_size, 53 53 int *irq_no) … … 122 122 } 123 123 /*----------------------------------------------------------------------------*/ 124 int pci_enable_interrupts(d evice_t *device)124 int pci_enable_interrupts(ddf_dev_t *device) 125 125 { 126 126 int parent_phone = devman_parent_device_connect(device->handle, -
uspace/drv/uhci-hcd/pci.h
rdeece2f r233e68d 36 36 #define DRV_UHCI_PCI_H 37 37 38 #include <d river.h>38 #include <ddf/driver.h> 39 39 40 int pci_get_my_registers(d evice_t *, uintptr_t *, size_t *, int *);41 int pci_enable_interrupts(d evice_t *device);40 int pci_get_my_registers(ddf_dev_t *, uintptr_t *, size_t *, int *); 41 int pci_enable_interrupts(ddf_dev_t *); 42 42 43 43 #endif -
uspace/drv/uhci-hcd/root_hub.c
rdeece2f r233e68d 39 39 40 40 #include "root_hub.h" 41 #include "uhci.h" 41 42 42 extern device_ops_t child_ops; 43 static int usb_iface_get_hc_handle_rh_impl(ddf_fun_t *root_hub_fun, 44 devman_handle_t *handle) 45 { 46 ddf_fun_t *hc_fun = root_hub_fun->driver_data; 47 assert(hc_fun != NULL); 48 49 *handle = hc_fun->handle; 50 51 return EOK; 52 } 53 54 static int usb_iface_get_address_rh_impl(ddf_fun_t *fun, devman_handle_t handle, 55 usb_address_t *address) 56 { 57 assert(fun); 58 ddf_fun_t *hc_fun = fun->driver_data; 59 assert(hc_fun); 60 uhci_t *hc = fun_to_uhci(hc_fun); 61 assert(hc); 62 63 usb_address_t addr = usb_address_keeping_find(&hc->address_manager, 64 handle); 65 if (addr < 0) { 66 return addr; 67 } 68 69 if (address != NULL) { 70 *address = addr; 71 } 72 73 return EOK; 74 } 75 76 usb_iface_t usb_iface_root_hub_fun_impl = { 77 .get_hc_handle = usb_iface_get_hc_handle_rh_impl, 78 .get_address = usb_iface_get_address_rh_impl 79 }; 80 81 static ddf_dev_ops_t root_hub_ops = { 82 .interfaces[USB_DEV_IFACE] = &usb_iface_root_hub_fun_impl 83 }; 84 43 85 /*----------------------------------------------------------------------------*/ 44 int setup_root_hub(d evice_t **device, device_t *hc)86 int setup_root_hub(ddf_fun_t **fun, ddf_dev_t *hc) 45 87 { 46 assert(device); 47 device_t *hub = create_device(); 88 assert(fun); 89 int ret; 90 91 ddf_fun_t *hub = ddf_fun_create(hc, fun_inner, "root-hub"); 48 92 if (!hub) { 49 93 usb_log_error("Failed to create root hub device structure.\n"); 50 return ENOMEM;51 }52 char *name;53 int ret = asprintf(&name, "UHCI Root Hub");54 if (ret < 0) {55 usb_log_error("Failed to create root hub name.\n");56 free(hub);57 94 return ENOMEM; 58 95 } … … 62 99 if (ret < 0) { 63 100 usb_log_error("Failed to create root hub match string.\n"); 64 free(hub); 65 free(name); 101 ddf_fun_destroy(hub); 66 102 return ENOMEM; 67 103 } 68 104 69 match_id_t *match_id = create_match_id(); 70 if (!match_id) { 71 usb_log_error("Failed to create root hub match id.\n"); 72 free(hub); 73 free(match_str); 105 ret = ddf_fun_add_match_id(hub, match_str, 100); 106 if (ret != EOK) { 107 usb_log_error("Failed to add root hub match id.\n"); 108 ddf_fun_destroy(hub); 74 109 return ENOMEM; 75 110 } 76 match_id->id = match_str;77 match_id->score = 90;78 111 79 add_match_id(&hub->match_ids, match_id); 80 hub->name = name; 81 hub->parent = hc; 82 hub->ops = &child_ops; 112 hub->ops = &root_hub_ops; 83 113 84 * device= hub;114 *fun = hub; 85 115 return EOK; 86 116 } -
uspace/drv/uhci-hcd/root_hub.h
rdeece2f r233e68d 36 36 #define DRV_UHCI_ROOT_HUB_H 37 37 38 #include <d river.h>38 #include <ddf/driver.h> 39 39 40 int setup_root_hub(d evice_t **device, device_t *hc);40 int setup_root_hub(ddf_fun_t **device, ddf_dev_t *hc); 41 41 42 42 #endif -
uspace/drv/uhci-hcd/uhci.c
rdeece2f r233e68d 33 33 */ 34 34 #include <errno.h> 35 #include <str_error.h> 35 36 #include <adt/list.h> 37 #include <libarch/ddi.h> 36 38 37 39 #include <usb/debug.h> 38 40 #include <usb/usb.h> 41 #include <usb/ddfiface.h> 42 #include <usb_iface.h> 39 43 40 44 #include "uhci.h" 45 #include "iface.h" 46 41 47 static irq_cmd_t uhci_cmds[] = { 42 48 { … … 55 61 }; 56 62 63 static int usb_iface_get_address(ddf_fun_t *fun, devman_handle_t handle, 64 usb_address_t *address) 65 { 66 assert(fun); 67 uhci_t *hc = fun_to_uhci(fun); 68 assert(hc); 69 70 usb_address_t addr = usb_address_keeping_find(&hc->address_manager, 71 handle); 72 if (addr < 0) { 73 return addr; 74 } 75 76 if (address != NULL) { 77 *address = addr; 78 } 79 80 return EOK; 81 } 82 83 84 static usb_iface_t hc_usb_iface = { 85 .get_hc_handle = usb_iface_get_hc_handle_hc_impl, 86 .get_address = usb_iface_get_address 87 }; 88 /*----------------------------------------------------------------------------*/ 89 static ddf_dev_ops_t uhci_ops = { 90 .interfaces[USB_DEV_IFACE] = &hc_usb_iface, 91 .interfaces[USBHC_DEV_IFACE] = &uhci_iface 92 }; 93 57 94 static int uhci_init_transfer_lists(uhci_t *instance); 58 95 static int uhci_init_mem_structures(uhci_t *instance); … … 71 108 } else (void) 0 72 109 73 int uhci_init(uhci_t *instance, void *regs, size_t reg_size)110 int uhci_init(uhci_t *instance, ddf_dev_t *dev, void *regs, size_t reg_size) 74 111 { 75 112 assert(reg_size >= sizeof(regs_t)); 113 int ret; 114 115 /* 116 * Create UHCI function. 117 */ 118 instance->ddf_instance = ddf_fun_create(dev, fun_exposed, "uhci"); 119 if (instance->ddf_instance == NULL) { 120 usb_log_error("Failed to create UHCI device function.\n"); 121 return ENOMEM; 122 } 123 instance->ddf_instance->ops = &uhci_ops; 124 instance->ddf_instance->driver_data = instance; 125 126 ret = ddf_fun_bind(instance->ddf_instance); 127 CHECK_RET_RETURN(ret, "Failed to bind UHCI device function: %s.\n", 128 str_error(ret)); 76 129 77 130 /* allow access to hc control registers */ 78 131 regs_t *io; 79 intret = pio_enable(regs, reg_size, (void**)&io);132 ret = pio_enable(regs, reg_size, (void**)&io); 80 133 CHECK_RET_RETURN(ret, "Failed to gain access to registers at %p.\n", io); 81 134 instance->registers = io; -
uspace/drv/uhci-hcd/uhci.h
rdeece2f r233e68d 39 39 #include <fibril_synch.h> 40 40 #include <adt/list.h> 41 #include <ddi.h> 41 42 42 43 #include <usb/addrkeep.h> … … 97 98 fid_t cleaner; 98 99 fid_t debug_checker; 100 101 ddf_fun_t *ddf_instance; 99 102 } uhci_t; 100 103 101 104 /* init uhci specifics in device.driver_data */ 102 int uhci_init(uhci_t *instance, void *regs, size_t reg_size);105 int uhci_init(uhci_t *instance, ddf_dev_t *dev, void *regs, size_t reg_size); 103 106 104 107 static inline void uhci_fini(uhci_t *instance) {}; … … 108 111 void uhci_interrupt(uhci_t *instance, uint16_t status); 109 112 110 static inline uhci_t * dev_to_uhci(d evice_t *dev)113 static inline uhci_t * dev_to_uhci(ddf_dev_t *dev) 111 114 { return (uhci_t*)dev->driver_data; } 115 116 static inline uhci_t * fun_to_uhci(ddf_fun_t *fun) 117 { return (uhci_t*)fun->driver_data; } 112 118 113 119
Note:
See TracChangeset
for help on using the changeset viewer.
