Changeset 6210a333 in mainline
- Timestamp:
- 2013-09-21T05:09:46Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 19d21728
- Parents:
- 30e8ab4
- Location:
- uspace/drv/bus/usb
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ohci/hc.c
r30e8ab4 r6210a333 42 42 #include <usb/usb.h> 43 43 44 #include "macros.h" 44 45 #include "hc.h" 45 46 #include "ohci_endpoint.h" … … 87 88 static int hc_init_memory(hc_t *instance); 88 89 static int interrupt_emulator(hc_t *instance); 89 90 /** Get number of PIO ranges used in IRQ code.91 * @return Number of ranges.92 */93 size_t hc_irq_pio_range_count(void)94 {95 return sizeof(ohci_pio_ranges) / sizeof(irq_pio_range_t);96 }97 98 /** Get number of commands used in IRQ code.99 * @return Number of commands.100 */101 size_t hc_irq_cmd_count(void)102 {103 return sizeof(ohci_irq_commands) / sizeof(irq_cmd_t);104 }105 90 106 91 /** Generate IRQ code. … … 113 98 * @return Error code. 114 99 */ 115 int 116 hc_get_irq_code(irq_pio_range_t ranges[], size_t ranges_size, irq_cmd_t cmds[], 117 size_t cmds_size, addr_range_t *regs) 118 { 119 if ((ranges_size < sizeof(ohci_pio_ranges)) || 120 (cmds_size < sizeof(ohci_irq_commands)) || 121 (RNGSZ(*regs) < sizeof(ohci_regs_t))) 100 int hc_gen_irq_code(irq_code_t *code, addr_range_t *regs) 101 { 102 assert(code); 103 if (RNGSZ(*regs) < sizeof(ohci_regs_t)) 122 104 return EOVERFLOW; 123 105 124 memcpy(ranges, ohci_pio_ranges, sizeof(ohci_pio_ranges)); 125 ranges[0].base = RNGABS(*regs); 126 127 memcpy(cmds, ohci_irq_commands, sizeof(ohci_irq_commands)); 106 code->ranges = malloc(sizeof(ohci_pio_ranges)); 107 if (code->ranges == NULL) 108 return ENOMEM; 109 110 code->cmds = malloc(sizeof(ohci_irq_commands)); 111 if (code->cmds == NULL) { 112 free(code->ranges); 113 return ENOMEM; 114 } 115 116 code->rangecount = ARRAY_SIZE(ohci_pio_ranges); 117 code->cmdcount = ARRAY_SIZE(ohci_irq_commands); 118 119 memcpy(code->ranges, ohci_pio_ranges, sizeof(ohci_pio_ranges)); 120 code->ranges[0].base = RNGABS(*regs); 121 122 memcpy(code->cmds, ohci_irq_commands, sizeof(ohci_irq_commands)); 128 123 ohci_regs_t *registers = (ohci_regs_t *) RNGABSPTR(*regs); 129 c mds[0].addr = (void *) ®isters->interrupt_status;130 c mds[3].addr = (void *) ®isters->interrupt_status;131 OHCI_WR(c mds[1].value, OHCI_USED_INTERRUPTS);124 code->cmds[0].addr = (void *) ®isters->interrupt_status; 125 code->cmds[3].addr = (void *) ®isters->interrupt_status; 126 OHCI_WR(code->cmds[1].value, OHCI_USED_INTERRUPTS); 132 127 133 128 return EOK; … … 146 141 interrupt_handler_t handler) 147 142 { 148 int rc; 149 150 irq_pio_range_t irq_ranges[hc_irq_pio_range_count()]; 151 irq_cmd_t irq_cmds[hc_irq_cmd_count()]; 152 153 irq_code_t irq_code = { 154 .rangecount = hc_irq_pio_range_count(), 155 .ranges = irq_ranges, 156 .cmdcount = hc_irq_cmd_count(), 157 .cmds = irq_cmds 158 }; 159 160 rc = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds, 161 sizeof(irq_cmds), regs); 162 if (rc != EOK) { 143 irq_code_t irq_code = { 0 }; 144 145 int ret = hc_gen_irq_code(&irq_code, regs); 146 if (ret != EOK) { 163 147 usb_log_error("Failed to generate IRQ code: %s.\n", 164 str_error(rc)); 165 return rc; 166 } 148 str_error(ret)); 149 return ret; 150 } 151 152 //TODO we leak memory here 167 153 168 154 /* Register handler to avoid interrupt lockup */ 169 r c= register_interrupt_handler(device, irq, handler, &irq_code);170 if (r c!= EOK) {155 ret = register_interrupt_handler(device, irq, handler, &irq_code); 156 if (ret != EOK) { 171 157 usb_log_error("Failed to register interrupt handler: %s.\n", 172 str_error(r c));173 return r c;158 str_error(ret)); 159 return ret; 174 160 } 175 161 -
uspace/drv/bus/usb/ohci/hc.h
r30e8ab4 r6210a333 72 72 } hc_t; 73 73 74 size_t hc_irq_pio_range_count(void); 75 size_t hc_irq_cmd_count(void); 76 int hc_get_irq_code(irq_pio_range_t [], size_t, irq_cmd_t [], size_t, 77 addr_range_t *); 74 int hc_gen_irq_code(irq_code_t *code, addr_range_t *regs); 78 75 int hc_register_irq_handler(ddf_dev_t *, addr_range_t *, int, 79 76 interrupt_handler_t); -
uspace/drv/bus/usb/uhci/hc.c
r30e8ab4 r6210a333 90 90 91 91 92 /** Get number of PIO ranges used in IRQ code.93 * @return Number of ranges.94 */95 size_t hc_irq_pio_range_count(void)96 {97 return sizeof(uhci_irq_pio_ranges) / sizeof(irq_pio_range_t);98 }99 100 /** Get number of commands used in IRQ code.101 * @return Number of commands.102 */103 size_t hc_irq_cmd_count(void)104 {105 return sizeof(uhci_irq_commands) / sizeof(irq_cmd_t);106 }107 108 92 /** Generate IRQ code. 109 * @param[out] ranges PIO ranges buffer. 110 * @param[in] ranges_size Size of the ranges buffer (bytes). 111 * @param[out] cmds Commands buffer. 112 * @param[in] cmds_size Size of the commands buffer (bytes). 93 * @param[out] code IRQ code structure. 113 94 * @param[in] regs Device's register range. 114 95 * 115 96 * @return Error code. 116 97 */ 117 int 118 hc_get_irq_code(irq_pio_range_t ranges[], size_t ranges_size, irq_cmd_t cmds[], 119 size_t cmds_size, addr_range_t *regs) 120 { 121 if ((ranges_size < sizeof(uhci_irq_pio_ranges)) || 122 (cmds_size < sizeof(uhci_irq_commands)) || 123 (RNGSZ(*regs) < sizeof(uhci_regs_t))) 98 int hc_gen_irq_code(irq_code_t *code, addr_range_t *regs) 99 { 100 assert(code); 101 102 if (RNGSZ(*regs) < sizeof(uhci_regs_t)) 124 103 return EOVERFLOW; 125 104 126 memcpy(ranges, uhci_irq_pio_ranges, sizeof(uhci_irq_pio_ranges)); 127 ranges[0].base = RNGABS(*regs); 128 129 memcpy(cmds, uhci_irq_commands, sizeof(uhci_irq_commands)); 105 code->ranges = malloc(sizeof(uhci_irq_pio_ranges)); 106 if (code->ranges == NULL) 107 return ENOMEM; 108 109 code->cmds = malloc(sizeof(uhci_irq_commands)); 110 if (code->cmds == NULL) { 111 free(code->ranges); 112 return ENOMEM; 113 } 114 115 code->rangecount = ARRAY_SIZE(uhci_irq_pio_ranges); 116 code->cmdcount = ARRAY_SIZE(uhci_irq_commands); 117 118 memcpy(code->ranges, uhci_irq_pio_ranges, sizeof(uhci_irq_pio_ranges)); 119 code->ranges[0].base = RNGABS(*regs); 120 121 memcpy(code->cmds, uhci_irq_commands, sizeof(uhci_irq_commands)); 130 122 uhci_regs_t *registers = (uhci_regs_t *) RNGABSPTR(*regs); 131 c mds[0].addr = (void*)®isters->usbsts;132 c mds[3].addr = (void*)®isters->usbsts;123 code->cmds[0].addr = (void*)®isters->usbsts; 124 code->cmds[3].addr = (void*)®isters->usbsts; 133 125 134 126 return EOK; … … 148 140 { 149 141 assert(device); 150 irq_pio_range_t irq_ranges[hc_irq_pio_range_count()]; 151 irq_cmd_t irq_cmds[hc_irq_cmd_count()]; 152 153 int ret = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds, 154 sizeof(irq_cmds), regs); 142 143 irq_code_t irq_code = { 0 }; 144 145 int ret = hc_gen_irq_code(&irq_code, regs); 155 146 if (ret != EOK) { 156 147 usb_log_error("Failed to generate IRQ commands: %s.\n", … … 158 149 return ret; 159 150 } 160 161 irq_code_t irq_code = { 162 .rangecount = hc_irq_pio_range_count(), 163 .ranges = irq_ranges, 164 .cmdcount = hc_irq_cmd_count(), 165 .cmds = irq_cmds 166 }; 151 //TODO we leak memory here 167 152 168 153 /* Register handler to avoid interrupt lockup */ -
uspace/drv/bus/usb/uhci/hc.h
r30e8ab4 r6210a333 124 124 } hc_t; 125 125 126 size_t hc_irq_pio_range_count(void);127 size_t hc_irq_cmd_count(void);128 126 int hc_register_irq_handler(ddf_dev_t *, addr_range_t *, int, 129 127 interrupt_handler_t); 130 int hc_get_irq_code(irq_pio_range_t [], size_t, irq_cmd_t [], size_t, 131 addr_range_t *); 128 int hc_gen_irq_code(irq_code_t *code, addr_range_t *regs); 132 129 void hc_interrupt(hc_t *instance, uint16_t status); 133 130 int hc_init(hc_t *instance, addr_range_t *regs, bool interupts);
Note:
See TracChangeset
for help on using the changeset viewer.