Changeset 6210a333 in mainline for uspace/drv/bus/usb/ohci/hc.c
- Timestamp:
- 2013-09-21T05:09:46Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 19d21728
- Parents:
- 30e8ab4
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.