Changeset 4ed80ce8 in mainline for uspace/drv/ehci-hcd/pci.c
- Timestamp:
- 2011-03-06T22:00:45Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4b4e163
- Parents:
- 8a20380
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ehci-hcd/pci.c
r8a20380 r4ed80ce8 87 87 rc = hw_res_get_resource_list(parent_phone, &hw_resources); 88 88 if (rc != EOK) { 89 goto leave; 89 async_hangup(parent_phone); 90 return rc; 90 91 } 91 92 … … 100 101 for (i = 0; i < hw_resources.count; i++) { 101 102 hw_resource_t *res = &hw_resources.resources[i]; 102 switch (res->type) { 103 case INTERRUPT: 104 irq = res->res.interrupt.irq; 105 irq_found = true; 106 usb_log_debug2("Found interrupt: %d.\n", irq); 107 break; 108 case MEM_RANGE: 109 if (res->res.mem_range.address != 0 110 && res->res.mem_range.size != 0 ) { 111 mem_address = res->res.mem_range.address; 112 mem_size = res->res.mem_range.size; 113 usb_log_debug2("Found mem: %llx %zu.\n", 114 res->res.mem_range.address, res->res.mem_range.size); 115 mem_found = true; 103 switch (res->type) 104 { 105 case INTERRUPT: 106 irq = res->res.interrupt.irq; 107 irq_found = true; 108 usb_log_debug2("Found interrupt: %d.\n", irq); 109 break; 110 111 case MEM_RANGE: 112 if (res->res.mem_range.address != 0 113 && res->res.mem_range.size != 0 ) { 114 mem_address = res->res.mem_range.address; 115 mem_size = res->res.mem_range.size; 116 usb_log_debug2("Found mem: %llx %zu.\n", 117 mem_address, mem_size); 118 mem_found = true; 116 119 } 117 break; 118 default: 119 break; 120 default: 121 break; 120 122 } 121 123 } 122 124 123 if (!mem_found) { 125 if (mem_found && irq_found) { 126 *mem_reg_address = mem_address; 127 *mem_reg_size = mem_size; 128 *irq_no = irq; 129 rc = EOK; 130 } else { 124 131 rc = ENOENT; 125 goto leave; 126 } 127 128 if (!irq_found) { 129 rc = ENOENT; 130 goto leave; 131 } 132 133 *mem_reg_address = mem_address; 134 *mem_reg_size = mem_size; 135 *irq_no = irq; 136 137 rc = EOK; 138 leave: 132 } 133 139 134 async_hangup(parent_phone); 140 141 135 return rc; 142 136 } … … 144 138 int pci_enable_interrupts(ddf_dev_t *device) 145 139 { 146 int parent_phone = devman_parent_device_connect(device->handle, 147 IPC_FLAG_BLOCKING); 140 int parent_phone = 141 devman_parent_device_connect(device->handle, IPC_FLAG_BLOCKING); 142 if (parent_phone < 0) { 143 return parent_phone; 144 } 148 145 bool enabled = hw_res_enable_interrupt(parent_phone); 149 146 async_hangup(parent_phone); … … 160 157 } 161 158 159 #define CHECK_RET_HANGUP_RETURN(ret, message...) \ 160 if (ret != EOK) { \ 161 usb_log_error(message); \ 162 async_hangup(parent_phone); \ 163 return ret; \ 164 } else (void)0 165 166 162 167 /* read register space BAR */ 163 168 sysarg_t address = 0x10; 164 169 sysarg_t value; 165 170 166 171 int ret = async_req_2_1(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE), 167 172 IPC_M_CONFIG_SPACE_READ_32, address, &value); 173 CHECK_RET_HANGUP_RETURN(ret, "Failed(%d) to read PCI config space.\n", 174 ret); 168 175 usb_log_info("Register space BAR at %p:%x.\n", address, value); 169 176 170 177 /* clear lower byte, it's not part of the address */ 171 178 uintptr_t registers = (value & 0xffffff00); 172 usb_log_info("Mem registeraddress:%p.\n", registers);179 usb_log_info("Memory registers address:%p.\n", registers); 173 180 174 181 /* if nothing setup the hc, the we don't need to to turn it off */ … … 176 183 return ENOTSUP; 177 184 178 /* EHCI registers need 20 bytes*/185 /* map EHCI registers */ 179 186 void *regs = as_get_mappable_page(4096); 180 187 ret = physmem_map((void*)(registers & PAGE_SIZE_MASK), regs, 1, 181 188 AS_AREA_READ | AS_AREA_WRITE); 182 if (ret != EOK) { 183 usb_log_error("Failed(%d) to map registers %p:%p.\n", 184 ret, regs, registers); 185 } 189 CHECK_RET_HANGUP_RETURN(ret, "Failed(%d) to map registers %p:%p.\n", 190 ret, regs, registers); 191 186 192 /* calculate value of BASE */ 187 193 registers = (registers & 0xf00) | (uintptr_t)regs; 188 194 189 uint32_t hcc_params = *(uint32_t*)(registers + HCC_PARAMS_OFFSET); 195 const uint32_t hcc_params = 196 *(uint32_t*)(registers + HCC_PARAMS_OFFSET); 190 197 191 198 usb_log_debug("Value of hcc params register: %x.\n", hcc_params); 192 uint32_t eecp = (hcc_params >> HCC_PARAMS_EECP_OFFSET) & HCC_PARAMS_EECP_MASK; 199 uint32_t eecp = 200 (hcc_params >> HCC_PARAMS_EECP_OFFSET) & HCC_PARAMS_EECP_MASK; 193 201 usb_log_debug("Value of EECP: %x.\n", eecp); 194 202 195 203 ret = async_req_2_1(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE), 196 204 IPC_M_CONFIG_SPACE_READ_32, eecp + USBLEGCTLSTS_OFFSET, &value); 197 if (ret != EOK) { 198 usb_log_error("Failed(%d) to read USBLEGCTLSTS.\n", ret); 199 return ret; 200 } 201 usb_log_debug2("USBLEGCTLSTS: %x.\n", value); 205 CHECK_RET_HANGUP_RETURN(ret, "Failed(%d) to read USBLEGCTLSTS.\n", ret); 206 usb_log_debug("USBLEGCTLSTS: %x.\n", value); 202 207 203 208 ret = async_req_2_1(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE), 204 209 IPC_M_CONFIG_SPACE_READ_32, eecp + USBLEGSUP_OFFSET, &value); 205 if (ret != EOK) { 206 usb_log_error("Failed(%d) to read USBLEGSUP.\n", ret); 207 return ret; 208 } 210 CHECK_RET_HANGUP_RETURN(ret, "Failed(%d) to read USBLEGSUP.\n", ret); 209 211 usb_log_debug2("USBLEGSUP: %x.\n", value); 210 212 … … 212 214 ret = async_req_3_0(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE), 213 215 IPC_M_CONFIG_SPACE_WRITE_8, eecp + USBLEGSUP_OFFSET + 3, 1); 214 if (ret != EOK) { 215 usb_log_error("Failed(%d) request OS EHCI control.\n", ret); 216 return ret; 217 } 218 219 size_t wait = 0; /* might be anything */ 216 CHECK_RET_HANGUP_RETURN(ret, "Failed(%d) request OS EHCI control.\n", 217 ret); 218 219 size_t wait = 0; 220 220 /* wait for BIOS to release control */ 221 221 while ((wait < DEFAULT_WAIT) && (value & USBLEGSUP_BIOS_CONTROL)) { 222 222 async_usleep(WAIT_STEP); 223 223 ret = async_req_2_1(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE), 224 224 IPC_M_CONFIG_SPACE_READ_32, eecp + USBLEGSUP_OFFSET, &value); 225 225 wait += WAIT_STEP; 226 226 } 227 227 228 228 if ((value & USBLEGSUP_BIOS_CONTROL) != 0) { 229 usb_log_warning( 230 "BIOS failed to release control after %d usecs, force it.\n", 231 wait); 229 usb_log_info("BIOS released control after %d usec.\n", wait); 230 } else { 231 usb_log_warning( "BIOS failed to release control after" 232 "%d usecs, force it.\n", wait); 232 233 ret = async_req_3_0(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE), 233 234 IPC_M_CONFIG_SPACE_WRITE_32, eecp + USBLEGSUP_OFFSET, 234 235 USBLEGSUP_OS_CONTROL); 235 if (ret != EOK) { 236 usb_log_error("Failed(%d) to force OS EHCI control.\n", ret); 237 return ret; 238 } 239 } else { 240 usb_log_info("BIOS released control after %d usec.\n", 241 wait); 236 CHECK_RET_HANGUP_RETURN(ret, 237 "Failed(%d) to force OS EHCI control.\n", ret); 242 238 } 243 239 … … 246 242 ret = async_req_3_0(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE), 247 243 IPC_M_CONFIG_SPACE_WRITE_32, eecp + USBLEGCTLSTS_OFFSET, 0); 248 if (ret != EOK) { 249 usb_log_error("Failed(%d) zero USBLEGCTLSTS.\n", ret); 250 return ret; 251 } 244 CHECK_RET_HANGUP_RETURN(ret, "Failed(%d) zero USBLEGCTLSTS.\n", ret); 252 245 usb_log_debug("Zeroed USBLEGCTLSTS register.\n"); 253 246 254 247 ret = async_req_2_1(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE), 255 248 IPC_M_CONFIG_SPACE_READ_32, eecp + USBLEGCTLSTS_OFFSET, &value); 256 if (ret != EOK) { 257 usb_log_error("Failed(%d) to read USBLEGCTLSTS.\n", ret); 258 return ret; 259 } 249 CHECK_RET_HANGUP_RETURN(ret, "Failed(%d) to read USBLEGCTLSTS.\n", ret); 260 250 usb_log_debug2("USBLEGCTLSTS: %x.\n", value); 261 251 262 252 ret = async_req_2_1(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE), 263 253 IPC_M_CONFIG_SPACE_READ_32, eecp + USBLEGSUP_OFFSET, &value); 264 if (ret != EOK) { 265 usb_log_error("Failed(%d) to read USBLEGSUP.\n", ret); 266 return ret; 267 } 254 CHECK_RET_HANGUP_RETURN(ret, "Failed(%d) to read USBLEGSUP.\n", ret); 268 255 usb_log_debug2("USBLEGSUP: %x.\n", value); 269 256 … … 288 275 289 276 async_hangup(parent_phone); 290 291 return ret; 277 return ret; 278 #undef CHECK_RET_HANGUP_RETURN 292 279 } 293 280 /*----------------------------------------------------------------------------*/
Note:
See TracChangeset
for help on using the changeset viewer.