Changeset 698cb1cc in mainline
- Timestamp:
- 2012-03-15T14:15:42Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9155bb2
- Parents:
- 89e54124
- Location:
- uspace/drv/bus/usb/ehci
- Files:
-
- 2 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ehci/Makefile
r89e54124 r698cb1cc 43 43 SOURCES = \ 44 44 main.c \ 45 pci.c45 res.c 46 46 47 47 include $(USPACE_PREFIX)/Makefile.common -
uspace/drv/bus/usb/ehci/main.c
r89e54124 r698cb1cc 44 44 #include <usb/host/hcd.h> 45 45 46 #include " pci.h"46 #include "res.h" 47 47 48 48 #define NAME "ehci" … … 81 81 int irq = 0; 82 82 83 int ret = pci_get_my_registers(device, ®_base, ®_size, &irq);83 int ret = get_my_registers(device, ®_base, ®_size, &irq); 84 84 CHECK_RET_RETURN(ret, 85 85 "Failed to get memory addresses for %" PRIun ": %s.\n", … … 88 88 reg_base, reg_size, irq); 89 89 90 ret = pci_disable_legacy(device, reg_base, reg_size, irq);90 ret = disable_legacy(device, reg_base, reg_size); 91 91 CHECK_RET_RETURN(ret, 92 92 "Failed to disable legacy USB: %s.\n", str_error(ret)); -
uspace/drv/bus/usb/ehci/res.c
r89e54124 r698cb1cc 39 39 #include <str_error.h> 40 40 #include <assert.h> 41 #include <as.h>42 41 #include <devman.h> 43 42 #include <ddi.h> 44 #include <libarch/ddi.h>45 #include <device/hw_res.h>46 47 43 #include <usb/debug.h> 48 #include <pci_dev_iface.h> 49 50 #include "pci.h" 44 #include <device/hw_res_parsed.h> 45 #include <device/pci.h> 46 47 #include "res.h" 51 48 52 49 #define PAGE_SIZE_MASK 0xfffff000 … … 72 69 #define WAIT_STEP 10 73 70 74 #define PCI_READ(size) \75 do { \76 async_sess_t *parent_sess = \77 devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle, \78 IPC_FLAG_BLOCKING); \79 if (!parent_sess) \80 return ENOMEM; \81 \82 sysarg_t add = (sysarg_t) address; \83 sysarg_t val; \84 \85 async_exch_t *exch = async_exchange_begin(parent_sess); \86 \87 const int ret = \88 async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE), \89 IPC_M_CONFIG_SPACE_READ_##size, add, &val); \90 \91 async_exchange_end(exch); \92 async_hangup(parent_sess); \93 \94 assert(value); \95 \96 *value = val; \97 return ret; \98 } while (0)99 100 static int pci_read32(const ddf_dev_t *dev, int address, uint32_t *value)101 {102 PCI_READ(32);103 }104 105 static int pci_read16(const ddf_dev_t *dev, int address, uint16_t *value)106 {107 PCI_READ(16);108 }109 110 static int pci_read8(const ddf_dev_t *dev, int address, uint8_t *value)111 {112 PCI_READ(8);113 }114 115 #define PCI_WRITE(size) \116 do { \117 async_sess_t *parent_sess = \118 devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle, \119 IPC_FLAG_BLOCKING); \120 if (!parent_sess) \121 return ENOMEM; \122 \123 sysarg_t add = (sysarg_t) address; \124 sysarg_t val = value; \125 \126 async_exch_t *exch = async_exchange_begin(parent_sess); \127 \128 const int ret = \129 async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE), \130 IPC_M_CONFIG_SPACE_WRITE_##size, add, val); \131 \132 async_exchange_end(exch); \133 async_hangup(parent_sess); \134 \135 return ret; \136 } while(0)137 138 static int pci_write32(const ddf_dev_t *dev, int address, uint32_t value)139 {140 PCI_WRITE(32);141 }142 143 static int pci_write16(const ddf_dev_t *dev, int address, uint16_t value)144 {145 PCI_WRITE(16);146 }147 148 static int pci_write8(const ddf_dev_t *dev, int address, uint8_t value)149 {150 PCI_WRITE(8);151 }152 71 153 72 /** Get address of registers and IRQ for given device. … … 159 78 * @return Error code. 160 79 */ 161 int pci_get_my_registers(const ddf_dev_t *dev,80 int get_my_registers(const ddf_dev_t *dev, 162 81 uintptr_t *mem_reg_address, size_t *mem_reg_size, int *irq_no) 163 82 { 164 assert(dev != NULL); 165 166 async_sess_t *parent_sess = 167 devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle, 168 IPC_FLAG_BLOCKING); 83 assert(dev); 84 85 async_sess_t *parent_sess = devman_parent_device_connect( 86 EXCHANGE_SERIALIZE, dev->handle, IPC_FLAG_BLOCKING); 169 87 if (!parent_sess) 170 88 return ENOMEM; 171 89 172 hw_resource_list_t hw_resources; 173 int rc = hw_res_get_resource_list(parent_sess, &hw_resources); 174 if (rc != EOK) { 175 async_hangup(parent_sess); 176 return rc; 177 } 178 179 uintptr_t mem_address = 0; 180 size_t mem_size = 0; 181 bool mem_found = false; 182 183 int irq = 0; 184 bool irq_found = false; 185 186 size_t i; 187 for (i = 0; i < hw_resources.count; i++) { 188 hw_resource_t *res = &hw_resources.resources[i]; 189 switch (res->type) { 190 case INTERRUPT: 191 irq = res->res.interrupt.irq; 192 irq_found = true; 193 usb_log_debug2("Found interrupt: %d.\n", irq); 194 break; 195 case MEM_RANGE: 196 if (res->res.mem_range.address != 0 197 && res->res.mem_range.size != 0 ) { 198 mem_address = res->res.mem_range.address; 199 mem_size = res->res.mem_range.size; 200 usb_log_debug2("Found mem: %" PRIxn" %zu.\n", 201 mem_address, mem_size); 202 mem_found = true; 203 } 204 default: 205 break; 206 } 207 } 208 209 if (mem_found && irq_found) { 210 *mem_reg_address = mem_address; 211 *mem_reg_size = mem_size; 212 *irq_no = irq; 213 rc = EOK; 214 } else { 215 rc = ENOENT; 216 } 217 90 hw_res_list_parsed_t hw_res; 91 hw_res_list_parsed_init(&hw_res); 92 const int ret = hw_res_get_list_parsed(parent_sess, &hw_res, 0); 218 93 async_hangup(parent_sess); 219 return rc; 94 if (ret != EOK) { 95 return ret; 96 } 97 98 if (hw_res.irqs.count != 1 || hw_res.mem_ranges.count != 1) { 99 hw_res_list_parsed_clean(&hw_res); 100 return ENOENT; 101 } 102 103 if (mem_reg_address) 104 *mem_reg_address = hw_res.mem_ranges.ranges[0].address; 105 if (mem_reg_size) 106 *mem_reg_size = hw_res.mem_ranges.ranges[0].size; 107 if (irq_no) 108 *irq_no = hw_res.irqs.irqs[0]; 109 110 hw_res_list_parsed_clean(&hw_res); 111 return EOK; 220 112 } 221 113 /*----------------------------------------------------------------------------*/ … … 225 117 * @return Error code. 226 118 */ 227 int pci_enable_interrupts(const ddf_dev_t *device)119 int enable_interrupts(const ddf_dev_t *device) 228 120 { 229 async_sess_t *parent_sess = 230 devman_parent_device_connect(EXCHANGE_SERIALIZE, device->handle, 231 IPC_FLAG_BLOCKING); 121 async_sess_t *parent_sess = devman_parent_device_connect( 122 EXCHANGE_SERIALIZE, device->handle, IPC_FLAG_BLOCKING); 232 123 if (!parent_sess) 233 124 return ENOMEM; … … 244 135 * @return Error code. 245 136 */ 246 int pci_disable_legacy( 247 const ddf_dev_t *device, uintptr_t reg_base, size_t reg_size, int irq) 137 int disable_legacy(const ddf_dev_t *device, uintptr_t reg_base, size_t reg_size) 248 138 { 249 139 assert(device); 250 (void) pci_read16; 251 (void) pci_read8; 252 (void) pci_write16; 140 async_sess_t *parent_sess = devman_parent_device_connect( 141 EXCHANGE_SERIALIZE, device->handle, IPC_FLAG_BLOCKING); 142 if (!parent_sess) 143 return ENOMEM; 253 144 254 145 #define CHECK_RET_RETURN(ret, message...) \ 255 146 if (ret != EOK) { \ 256 147 usb_log_error(message); \ 148 async_hangup(parent_sess); \ 257 149 return ret; \ 258 150 } else (void)0 … … 276 168 /* Read the first EEC. i.e. Legacy Support register */ 277 169 uint32_t usblegsup; 278 ret = pci_read32(device, eecp + USBLEGSUP_OFFSET, &usblegsup); 170 ret = pci_config_space_read_32(parent_sess, 171 eecp + USBLEGSUP_OFFSET, &usblegsup); 279 172 CHECK_RET_RETURN(ret, "Failed to read USBLEGSUP: %s.\n", str_error(ret)); 280 173 usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup); … … 283 176 * (OS Control semaphore)*/ 284 177 usb_log_debug("Requesting OS control.\n"); 285 ret = pci_write8(device, eecp + USBLEGSUP_OFFSET + 3, 1); 178 ret = pci_config_space_write_8(parent_sess, 179 eecp + USBLEGSUP_OFFSET + 3, 1); 286 180 CHECK_RET_RETURN(ret, "Failed to request OS EHCI control: %s.\n", 287 181 str_error(ret)); … … 289 183 size_t wait = 0; 290 184 /* Wait for BIOS to release control. */ 291 ret = pci_read32(device, eecp + USBLEGSUP_OFFSET, &usblegsup); 185 ret = pci_config_space_read_32(parent_sess, 186 eecp + USBLEGSUP_OFFSET, &usblegsup); 292 187 while ((wait < DEFAULT_WAIT) && (usblegsup & USBLEGSUP_BIOS_CONTROL)) { 293 188 async_usleep(WAIT_STEP); 294 ret = pci_read32(device, eecp + USBLEGSUP_OFFSET, &usblegsup); 189 ret = pci_config_space_read_32(parent_sess, 190 eecp + USBLEGSUP_OFFSET, &usblegsup); 295 191 wait += WAIT_STEP; 296 192 } … … 303 199 usb_log_warning( "BIOS failed to release control after " 304 200 "%zu usecs, force it.\n", wait); 305 ret = pci_ write32(device, eecp + USBLEGSUP_OFFSET,306 USBLEGSUP_OS_CONTROL);201 ret = pci_config_space_write_32(parent_sess, 202 eecp + USBLEGSUP_OFFSET, USBLEGSUP_OS_CONTROL); 307 203 CHECK_RET_RETURN(ret, "Failed to force OS control: %s.\n", 308 204 str_error(ret)); … … 317 213 * Legacy Support and Control register */ 318 214 uint32_t usblegctlsts; 319 ret = pci_ read32(320 device,eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts);215 ret = pci_config_space_read_32(parent_sess, 216 eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts); 321 217 CHECK_RET_RETURN(ret, 322 218 "Failed to get USBLEGCTLSTS: %s.\n", str_error(ret)); … … 324 220 usblegctlsts); 325 221 /* Zero SMI enables in legacy control register. 326 * It should prevent pre-OS code from interfering. */ 327 ret = pci_write32(device, eecp + USBLEGCTLSTS_OFFSET, 328 0xe0000000); /* three upper bits are WC */ 222 * It should prevent pre-OS code from interfering. 223 * Three upper bits are WC */ 224 ret = pci_config_space_write_32(parent_sess, 225 eecp + USBLEGCTLSTS_OFFSET, 0xe0000000); 329 226 CHECK_RET_RETURN(ret, 330 227 "Failed(%d) zero USBLEGCTLSTS.\n", ret); 331 228 udelay(10); 332 ret = pci_ read32(333 device,eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts);229 ret = pci_config_space_read_32(parent_sess, 230 eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts); 334 231 CHECK_RET_RETURN(ret, 335 232 "Failed to get USBLEGCTLSTS 2: %s.\n", … … 342 239 343 240 /* Read again Legacy Support register */ 344 ret = pci_read32(device, eecp + USBLEGSUP_OFFSET, &usblegsup); 241 ret = pci_config_space_read_32(parent_sess, 242 eecp + USBLEGSUP_OFFSET, &usblegsup); 345 243 CHECK_RET_RETURN(ret, "Failed to read USBLEGSUP: %s.\n", str_error(ret)); 346 244 usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup); 347 245 246 async_hangup(parent_sess); 247 #undef CHECK_RET_RETURN 248 348 249 /* 349 * TURN OFF EHCI FOR NOW, DRIVER WILL REINITIALIZE IT 250 * TURN OFF EHCI FOR NOW, DRIVER WILL REINITIALIZE IT IF NEEDED 350 251 */ 351 252 … … 384 285 385 286 return ret; 386 #undef CHECK_RET_RETURN387 287 } 388 288 -
uspace/drv/bus/usb/ehci/res.h
r89e54124 r698cb1cc 38 38 #include <ddf/driver.h> 39 39 40 int pci_get_my_registers(const ddf_dev_t *, uintptr_t *, size_t *, int *);41 int pci_enable_interrupts(const ddf_dev_t *);42 int pci_disable_legacy(const ddf_dev_t *, uintptr_t, size_t, int);40 int get_my_registers(const ddf_dev_t *, uintptr_t *, size_t *, int *); 41 int enable_interrupts(const ddf_dev_t *); 42 int disable_legacy(const ddf_dev_t *, uintptr_t, size_t); 43 43 44 44 #endif
Note:
See TracChangeset
for help on using the changeset viewer.