Changeset 5944244 in mainline
- Timestamp:
- 2011-02-01T23:25:48Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1f5c1e61
- Parents:
- c56dbe0
- Location:
- uspace/drv
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/iface.c
rc56dbe0 r5944244 44 44 { 45 45 assert(dev); 46 uhci_t *hc = (uhci_t *)dev->driver_data;46 uhci_t *hc = dev_to_uhci(dev); 47 47 assert(hc); 48 48 *address = usb_address_keeping_find(&hc->address_manager, handle); … … 55 55 { 56 56 assert(dev); 57 uhci_t *hc = (uhci_t *)dev->driver_data;57 uhci_t *hc = dev_to_uhci(dev); 58 58 assert(hc); 59 59 usb_address_keeping_reserve_default(&hc->address_manager); … … 64 64 { 65 65 assert(dev); 66 uhci_t *hc = (uhci_t *)dev->driver_data;66 uhci_t *hc = dev_to_uhci(dev); 67 67 assert(hc); 68 68 usb_address_keeping_release_default(&hc->address_manager); … … 73 73 { 74 74 assert(dev); 75 uhci_t *hc = (uhci_t *)dev->driver_data;75 uhci_t *hc = dev_to_uhci(dev); 76 76 assert(hc); 77 77 *address = usb_address_keeping_request(&hc->address_manager); … … 85 85 { 86 86 assert(dev); 87 uhci_t *hc = (uhci_t *)dev->driver_data;87 uhci_t *hc = dev_to_uhci(dev); 88 88 assert(hc); 89 89 usb_address_keeping_devman_bind(&hc->address_manager, address, handle); … … 94 94 { 95 95 assert(dev); 96 uhci_t *hc = (uhci_t *)dev->driver_data;96 uhci_t *hc = dev_to_uhci(dev); 97 97 assert(hc); 98 98 usb_address_keeping_release_default(&hc->address_manager); … … 104 104 usbhc_iface_transfer_out_callback_t callback, void *arg) 105 105 { 106 return uhci_transfer(dev, target, USB_TRANSFER_INTERRUPT, 0, USB_PID_OUT, 106 assert(dev); 107 uhci_t *hc = dev_to_uhci(dev); 108 assert(hc); 109 return uhci_transfer(hc, dev, target, USB_TRANSFER_INTERRUPT, 0, USB_PID_OUT, 107 110 data, size, callback, NULL, arg); 108 111 } … … 112 115 usbhc_iface_transfer_in_callback_t callback, void *arg) 113 116 { 114 return uhci_transfer(dev, target, USB_TRANSFER_INTERRUPT, 0, USB_PID_IN, 117 assert(dev); 118 uhci_t *hc = dev_to_uhci(dev); 119 assert(hc); 120 return uhci_transfer(hc, dev, target, USB_TRANSFER_INTERRUPT, 0, USB_PID_IN, 115 121 data, size, NULL, callback, arg); 116 122 } … … 120 126 usbhc_iface_transfer_out_callback_t callback, void *arg) 121 127 { 122 return uhci_transfer(dev, target, USB_TRANSFER_CONTROL, 0, USB_PID_SETUP, 128 assert(dev); 129 uhci_t *hc = dev_to_uhci(dev); 130 assert(hc); 131 return uhci_transfer(hc, dev, target, USB_TRANSFER_CONTROL, 0, USB_PID_SETUP, 123 132 data, size, callback, NULL, arg); 124 133 } … … 128 137 usbhc_iface_transfer_out_callback_t callback, void *arg) 129 138 { 130 return uhci_transfer(dev, target, USB_TRANSFER_CONTROL, 1, USB_PID_OUT, 139 assert(dev); 140 uhci_t *hc = dev_to_uhci(dev); 141 assert(hc); 142 return uhci_transfer(hc, dev, target, USB_TRANSFER_CONTROL, 1, USB_PID_OUT, 131 143 data, size, callback, NULL, arg); 132 144 } … … 135 147 usbhc_iface_transfer_in_callback_t callback, void *arg) 136 148 { 137 return uhci_transfer(dev, target, USB_TRANSFER_CONTROL, 0, USB_PID_IN, 149 assert(dev); 150 uhci_t *hc = dev_to_uhci(dev); 151 assert(hc); 152 return uhci_transfer(hc, dev, target, USB_TRANSFER_CONTROL, 0, USB_PID_IN, 138 153 NULL, 0, NULL, callback, arg); 139 154 } … … 143 158 usbhc_iface_transfer_out_callback_t callback, void *arg) 144 159 { 145 return uhci_transfer(dev, target, USB_TRANSFER_CONTROL, 0, USB_PID_SETUP, 160 assert(dev); 161 uhci_t *hc = dev_to_uhci(dev); 162 assert(hc); 163 return uhci_transfer(hc, dev, target, USB_TRANSFER_CONTROL, 0, USB_PID_SETUP, 146 164 data, size, callback, NULL, arg); 147 165 } … … 151 169 usbhc_iface_transfer_in_callback_t callback, void *arg) 152 170 { 153 return uhci_transfer(dev, target, USB_TRANSFER_CONTROL, 1, USB_PID_IN, 171 assert(dev); 172 uhci_t *hc = dev_to_uhci(dev); 173 assert(hc); 174 return uhci_transfer(hc, dev, target, USB_TRANSFER_CONTROL, 1, USB_PID_IN, 154 175 data, size, NULL, callback, arg); 155 176 } … … 158 179 usbhc_iface_transfer_out_callback_t callback, void *arg) 159 180 { 160 return uhci_transfer(dev, target, USB_TRANSFER_CONTROL, 0, USB_PID_OUT, 181 assert(dev); 182 uhci_t *hc = dev_to_uhci(dev); 183 assert(hc); 184 return uhci_transfer(hc, dev, target, USB_TRANSFER_CONTROL, 0, USB_PID_OUT, 161 185 NULL, 0, callback, NULL, arg); 162 186 } -
uspace/drv/uhci-hcd/main.c
rc56dbe0 r5944244 87 87 io_reg_base, io_reg_size, irq); 88 88 89 int ret = uhci_init(device, (void*)io_reg_base, io_reg_size); 89 uhci_t *uhci_hc = malloc(sizeof(uhci_t)); 90 if (!uhci_hc) { 91 usb_log_error("Failed to allocaete memory for uhci hcd driver.\n"); 92 return ENOMEM; 93 } 90 94 95 int ret = uhci_init(uhci_hc, (void*)io_reg_base, io_reg_size); 91 96 if (ret != EOK) { 92 97 usb_log_error("Failed to init uhci-hcd.\n"); … … 108 113 return ret; 109 114 } 115 116 device->driver_data = uhci_hc; 110 117 111 118 return EOK; -
uspace/drv/uhci-hcd/transfer_list.c
rc56dbe0 r5944244 43 43 instance->first = NULL; 44 44 instance->last = NULL; 45 instance->queue_head = malloc32(sizeof(queue_head_t));45 instance->queue_head = queue_head_get(); 46 46 if (!instance->queue_head) { 47 47 usb_log_error("Failed to allocate queue head.\n"); -
uspace/drv/uhci-hcd/transfer_list.h
rc56dbe0 r5944244 37 37 #include "uhci_struct/queue_head.h" 38 38 #include "uhci_struct/transfer_descriptor.h" 39 #include "utils/malloc32.h"40 39 41 40 typedef struct transfer_list … … 52 51 { 53 52 assert(instance); 54 if (instance->queue_head) 55 free32(instance->queue_head); 53 queue_head_dispose(instance->queue_head); 56 54 } 57 55 -
uspace/drv/uhci-hcd/uhci.c
rc56dbe0 r5944244 37 37 #include <usb/usb.h> 38 38 39 #include "utils/malloc32.h"40 39 #include "uhci.h" 41 40 … … 44 43 static int uhci_debug_checker(void *arg); 45 44 46 int uhci_init(device_t *device, void *regs, size_t reg_size) 47 { 48 assert(device); 49 usb_log_info("Initializing device at address %p.\n", device); 50 51 #define CHECK_RET_FREE_INSTANCE(message...) \ 45 int uhci_init(uhci_t *instance, void *regs, size_t reg_size) 46 { 47 #define CHECK_RET_RETURN(message...) \ 52 48 if (ret != EOK) { \ 53 49 usb_log_error(message); \ 54 if (instance) { \55 free(instance); \56 } \57 50 return ret; \ 58 51 } else (void) 0 59 60 /* create instance */61 uhci_t *instance = malloc(sizeof(uhci_t));62 int ret = instance ? EOK : ENOMEM;63 CHECK_RET_FREE_INSTANCE("Failed to allocate uhci driver instance.\n");64 65 bzero(instance, sizeof(uhci_t));66 52 67 53 /* init address keeper(libusb) */ … … 72 58 regs_t *io; 73 59 assert(reg_size >= sizeof(regs_t)); 74 ret = pio_enable(regs, reg_size, (void**)&io);75 CHECK_RET_ FREE_INSTANCE("Failed to gain access to registers at %p.\n", io);60 int ret = pio_enable(regs, reg_size, (void**)&io); 61 CHECK_RET_RETURN("Failed to gain access to registers at %p.\n", io); 76 62 instance->registers = io; 77 63 usb_log_debug("Device registers accessible.\n"); … … 79 65 /* init transfer lists */ 80 66 ret = uhci_init_transfer_lists(instance->transfers); 81 CHECK_RET_ FREE_INSTANCE("Failed to initialize transfer lists.\n");67 CHECK_RET_RETURN("Failed to initialize transfer lists.\n"); 82 68 usb_log_debug("Transfer lists initialized.\n"); 83 69 … … 86 72 instance->frame_list = get_page(); 87 73 ret = instance ? EOK : ENOMEM; 88 CHECK_RET_ FREE_INSTANCE("Failed to get frame list page.\n");74 CHECK_RET_RETURN("Failed to get frame list page.\n"); 89 75 90 76 /* initialize all frames to point to the first queue head */ 91 unsigned i = 0;92 77 const uint32_t queue = 93 78 instance->transfers[USB_TRANSFER_INTERRUPT].queue_head_pa 94 79 | LINK_POINTER_QUEUE_HEAD_FLAG; 80 unsigned i = 0; 95 81 for(; i < UHCI_FRAME_LIST_COUNT; ++i) { 96 82 instance->frame_list[i] = queue; … … 107 93 fibril_add_ready(instance->debug_checker); 108 94 109 usb_log_debug("Starting UHCI HC.\n"); 110 pio_write_16(&instance->registers->usbcmd, UHCI_CMD_RUN_STOP); 95 /* Start the hc with large(64b) packet FSBR */ 96 pio_write_16(&instance->registers->usbcmd, 97 UHCI_CMD_RUN_STOP | UHCI_CMD_MAX_PACKET); 98 usb_log_debug("Started UHCI HC.\n"); 111 99 /* 112 100 uint16_t cmd = pio_read_16(&instance->registers->usbcmd); … … 114 102 pio_write_16(&instance->registers->usbcmd, cmd); 115 103 */ 116 device->driver_data = instance;117 104 return EOK; 118 105 } … … 152 139 /*----------------------------------------------------------------------------*/ 153 140 int uhci_transfer( 141 uhci_t *instance, 154 142 device_t *dev, 155 143 usb_target_t target, … … 172 160 callback_t *job = NULL; 173 161 int ret = EOK; 162 assert(dev); 174 163 175 164 #define CHECK_RET_TRANS_FREE_JOB_TD(message) \ … … 183 172 } else (void) 0 184 173 185 186 174 job = callback_get(dev, buffer, size, callback_in, callback_out, arg); 187 175 ret = job ? EOK : ENOMEM; … … 193 181 194 182 td->callback = job; 195 196 assert(dev);197 uhci_t *instance = (uhci_t*)dev->driver_data;198 assert(instance);199 183 200 184 usb_log_debug("Appending a new transfer to queue.\n"); -
uspace/drv/uhci-hcd/uhci.h
rc56dbe0 r5944244 85 85 86 86 /* init uhci specifics in device.driver_data */ 87 int uhci_init( device_t *device, void *regs, size_t reg_size);87 int uhci_init(uhci_t *instance, void *regs, size_t reg_size); 88 88 89 int uhci_ destroy(device_t *device);89 int uhci_fini(uhci_t *device); 90 90 91 91 int uhci_transfer( 92 uhci_t *instance, 92 93 device_t *dev, 93 94 usb_target_t target, … … 100 101 void *arg ); 101 102 103 static inline uhci_t * dev_to_uhci(device_t *dev) 104 { return (uhci_t*)dev->driver_data; } 105 102 106 #endif 103 107 /** -
uspace/drv/uhci-hcd/uhci_struct/queue_head.h
rc56dbe0 r5944244 36 36 #define DRV_UHCI_QH_H 37 37 38 /* libc */ 38 39 #include <assert.h> 39 40 40 41 #include "link_pointer.h" 42 #include "utils/malloc32.h" 41 43 42 44 typedef struct queue_head { … … 59 61 } 60 62 63 static inline queue_head_t * queue_head_get() 64 { return malloc32(sizeof(queue_head_t)); } 65 66 static inline void queue_head_dispose(queue_head_t *head) 67 { free32(head); } 68 69 61 70 #endif 62 71 /** -
uspace/drv/uhci-hcd/utils/malloc32.h
rc56dbe0 r5944244 74 74 { return memalign(alignment, size); } 75 75 76 static inline void free32(void * 77 { free(addr); }76 static inline void free32(void *addr) 77 { if (addr) free(addr); } 78 78 79 79 #endif -
uspace/drv/uhci-rhd/main.c
rc56dbe0 r5944244 86 86 87 87 device->driver_data = rh; 88 usb_log_info("Sucessfully initialized driver i sntance for device:%d.\n",88 usb_log_info("Sucessfully initialized driver instance for device:%d.\n", 89 89 device->handle); 90 90 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.