source: mainline/uspace/drv/bus/usb/uhci/hc.c@ a6c4597

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a6c4597 was c913f71e, checked in by Petr Manek <petr.manek@…>, 8 years ago

uhci: implement onlining device functions

  • Property mode set to 100644
File size: 17.6 KB
RevLine 
[9351353]1/*
2 * Copyright (c) 2011 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
[58563585]28
[17ceb72]29/** @addtogroup drvusbuhcihc
[9351353]30 * @{
31 */
32/** @file
[17ceb72]33 * @brief UHCI Host controller driver routines
[9351353]34 */
[8064c2f6]35
[9351353]36#include <adt/list.h>
[8064c2f6]37#include <assert.h>
38#include <async.h>
[1ae74c6]39#include <ddi.h>
[8064c2f6]40#include <device/hw_res_parsed.h>
41#include <fibril.h>
42#include <errno.h>
43#include <macros.h>
44#include <mem.h>
45#include <stdlib.h>
[8d2dd7f2]46#include <stdint.h>
[8064c2f6]47#include <str_error.h>
[9351353]48
49#include <usb/debug.h>
50#include <usb/usb.h>
[8fc61c8]51#include <usb/host/utils/malloc32.h>
[e6b9182]52#include <usb/host/bandwidth.h>
[9351353]53
[07f49ae]54#include "uhci_batch.h"
[8064c2f6]55#include "hc.h"
[9351353]56
[8986412]57#define UHCI_INTR_ALLOW_INTERRUPTS \
[af81980]58 (UHCI_INTR_CRC | UHCI_INTR_COMPLETE | UHCI_INTR_SHORT_PACKET)
[8986412]59#define UHCI_STATUS_USED_INTERRUPTS \
60 (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)
[af81980]61
[d57122c]62static const irq_pio_range_t uhci_irq_pio_ranges[] = {
63 {
[8486c07]64 .base = 0,
[d57122c]65 .size = sizeof(uhci_regs_t)
66 }
67};
[5fe0a697]68
[d57122c]69static const irq_cmd_t uhci_irq_commands[] = {
[8486c07]70 {
71 .cmd = CMD_PIO_READ_16,
72 .dstarg = 1,
73 .addr = NULL
74 },
75 {
76 .cmd = CMD_AND,
77 .srcarg = 1,
78 .dstarg = 2,
79 .value = UHCI_STATUS_USED_INTERRUPTS | UHCI_STATUS_NM_INTERRUPTS
80 },
81 {
82 .cmd = CMD_PREDICATE,
83 .srcarg = 2,
84 .value = 2
85 },
86 {
87 .cmd = CMD_PIO_WRITE_A_16,
88 .srcarg = 1,
89 .addr = NULL
90 },
91 {
92 .cmd = CMD_ACCEPT
93 }
[dfe4955]94};
[302a4b6]95
[3afb758]96static void hc_init_hw(const hc_t *instance);
[32fb6bce]97static int hc_init_mem_structures(hc_t *instance, hc_device_t *);
[3afb758]98static int hc_init_transfer_lists(hc_t *instance);
[9351353]99
[c01cd32]100static int hc_debug_checker(void *arg);
[dfe4955]101
[76fbd9a]102
[d57122c]103/** Generate IRQ code.
[6210a333]104 * @param[out] code IRQ code structure.
[ba4a03a5]105 * @param[in] hw_res Device's resources.
[dfe4955]106 *
107 * @return Error code.
108 */
[32fb6bce]109int hc_gen_irq_code(irq_code_t *code, hc_device_t *hcd, const hw_res_list_parsed_t *hw_res)
[dfe4955]110{
[6210a333]111 assert(code);
[ba4a03a5]112 assert(hw_res);
[6210a333]113
[ba4a03a5]114 if (hw_res->irqs.count != 1 || hw_res->io_ranges.count != 1)
115 return EINVAL;
116 const addr_range_t regs = hw_res->io_ranges.ranges[0];
117
118 if (RNGSZ(regs) < sizeof(uhci_regs_t))
[dfe4955]119 return EOVERFLOW;
120
[6210a333]121 code->ranges = malloc(sizeof(uhci_irq_pio_ranges));
122 if (code->ranges == NULL)
123 return ENOMEM;
124
125 code->cmds = malloc(sizeof(uhci_irq_commands));
126 if (code->cmds == NULL) {
127 free(code->ranges);
128 return ENOMEM;
129 }
130
131 code->rangecount = ARRAY_SIZE(uhci_irq_pio_ranges);
132 code->cmdcount = ARRAY_SIZE(uhci_irq_commands);
[dfe4955]133
[6210a333]134 memcpy(code->ranges, uhci_irq_pio_ranges, sizeof(uhci_irq_pio_ranges));
[ba4a03a5]135 code->ranges[0].base = RNGABS(regs);
[6210a333]136
137 memcpy(code->cmds, uhci_irq_commands, sizeof(uhci_irq_commands));
[ba4a03a5]138 uhci_regs_t *registers = (uhci_regs_t *) RNGABSPTR(regs);
[6210a333]139 code->cmds[0].addr = (void*)&registers->usbsts;
140 code->cmds[3].addr = (void*)&registers->usbsts;
[dfe4955]141
[ba4a03a5]142 usb_log_debug("I/O regs at %p (size %zu), IRQ %d.\n",
143 RNGABSPTR(regs), RNGSZ(regs), hw_res->irqs.irqs[0]);
144
145 return hw_res->irqs.irqs[0];
[dfe4955]146}
[76fbd9a]147
[3afb758]148/** Take action based on the interrupt cause.
149 *
[4bfcf22]150 * @param[in] hcd HCD structure to use.
[3afb758]151 * @param[in] status Value of the status register at the time of interrupt.
152 *
153 * Interrupt might indicate:
154 * - transaction completed, either by triggering IOC, SPD, or an error
155 * - some kind of device error
156 * - resume from suspend state (not implemented)
157 */
[32fb6bce]158static void hc_interrupt(bus_t *bus, uint32_t status)
[3afb758]159{
[32fb6bce]160 hc_t *instance = bus_to_hc(bus);
161
[3afb758]162 /* Lower 2 bits are transaction error and transaction complete */
163 if (status & (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)) {
164 LIST_INITIALIZE(done);
165 transfer_list_remove_finished(
166 &instance->transfers_interrupt, &done);
167 transfer_list_remove_finished(
168 &instance->transfers_control_slow, &done);
169 transfer_list_remove_finished(
170 &instance->transfers_control_full, &done);
171 transfer_list_remove_finished(
172 &instance->transfers_bulk_full, &done);
173
[ad5f149]174 list_foreach_safe(done, current, next) {
175 list_remove(current);
[b991d37]176 uhci_transfer_batch_t *batch =
[ad5f149]177 uhci_transfer_batch_from_link(current);
[17873ac7]178 usb_transfer_batch_finish(&batch->base);
[3afb758]179 }
180 }
181 /* Resume interrupts are not supported */
182 if (status & UHCI_STATUS_RESUME) {
183 usb_log_error("Resume interrupt!\n");
184 }
185
186 /* Bits 4 and 5 indicate hc error */
187 if (status & (UHCI_STATUS_PROCESS_ERROR | UHCI_STATUS_SYSTEM_ERROR)) {
188 usb_log_error("UHCI hardware failure!.\n");
189 ++instance->hw_failures;
190 transfer_list_abort_all(&instance->transfers_interrupt);
191 transfer_list_abort_all(&instance->transfers_control_slow);
192 transfer_list_abort_all(&instance->transfers_control_full);
193 transfer_list_abort_all(&instance->transfers_bulk_full);
194
195 if (instance->hw_failures < UHCI_ALLOWED_HW_FAIL) {
196 /* reinitialize hw, this triggers virtual disconnect*/
197 hc_init_hw(instance);
198 } else {
199 usb_log_fatal("Too many UHCI hardware failures!.\n");
[32fb6bce]200 hc_gone(&instance->base);
[3afb758]201 }
202 }
203}
[76fbd9a]204
[02cacce]205/** Initialize UHCI hc driver structure
[9351353]206 *
207 * @param[in] instance Memory place to initialize.
[7de1988c]208 * @param[in] regs Range of device's I/O control registers.
[23f40280]209 * @param[in] interrupts True if hw interrupts should be used.
[9351353]210 * @return Error code.
211 * @note Should be called only once on any structure.
[17ceb72]212 *
213 * Initializes memory structures, starts up hw, and launches debugger and
214 * interrupt fibrils.
[9351353]215 */
[32fb6bce]216int hc_add(hc_device_t *hcd, const hw_res_list_parsed_t *hw_res)
[9351353]217{
[32fb6bce]218 hc_t *instance = hcd_to_hc(hcd);
[7813516]219 assert(hw_res);
220 if (hw_res->io_ranges.count != 1 ||
221 hw_res->io_ranges.ranges[0].size < sizeof(uhci_regs_t))
222 return EINVAL;
[9351353]223
[fcc525d]224 instance->hw_failures = 0;
225
[9351353]226 /* allow access to hc control registers */
[7813516]227 int ret = pio_enable_range(&hw_res->io_ranges.ranges[0],
228 (void **) &instance->registers);
[e0d8b740]229 if (ret != EOK) {
[7813516]230 usb_log_error("Failed to gain access to registers: %s.\n",
231 str_error(ret));
[e0d8b740]232 return ret;
233 }
234
[7813516]235 usb_log_debug("Device registers at %" PRIx64 " (%zuB) accessible.\n",
236 hw_res->io_ranges.ranges[0].address.absolute,
237 hw_res->io_ranges.ranges[0].size);
[3afb758]238
[6832245]239 ret = hc_init_mem_structures(instance, hcd);
[e0d8b740]240 if (ret != EOK) {
241 usb_log_error("Failed to init UHCI memory structures: %s.\n",
242 str_error(ret));
243 // TODO: we should disable pio here
244 return ret;
245 }
[7265558]246
[e4d7363]247 return EOK;
248}
249
[32fb6bce]250int hc_start(hc_device_t *hcd)
[e4d7363]251{
[32fb6bce]252 hc_t *instance = hcd_to_hc(hcd);
[c01cd32]253 hc_init_hw(instance);
[ea993d18]254 (void)hc_debug_checker;
[9351353]255
[32fb6bce]256 return uhci_rh_init(&instance->rh, instance->registers->ports, "uhci");
[9351353]257}
[76fbd9a]258
[7813516]259/** Safely dispose host controller internal structures
260 *
261 * @param[in] instance Host controller structure to use.
262 */
[32fb6bce]263int hc_gone(hc_device_t *instance)
[7813516]264{
265 assert(instance);
266 //TODO Implement
[32fb6bce]267 return ENOTSUP;
[7813516]268}
269
[17ceb72]270/** Initialize UHCI hc hw resources.
[9351353]271 *
272 * @param[in] instance UHCI structure to use.
[17ceb72]273 * For magic values see UHCI Design Guide
[9351353]274 */
[3afb758]275void hc_init_hw(const hc_t *instance)
[9351353]276{
277 assert(instance);
[dfe4955]278 uhci_regs_t *registers = instance->registers;
[9351353]279
280 /* Reset everything, who knows what touched it before us */
281 pio_write_16(&registers->usbcmd, UHCI_CMD_GLOBAL_RESET);
[26858040]282 async_usleep(50000); /* 50ms according to USB spec(root hub reset) */
[9351353]283 pio_write_16(&registers->usbcmd, 0);
284
[26858040]285 /* Reset hc, all states and counters. Hope that hw is not broken */
[9351353]286 pio_write_16(&registers->usbcmd, UHCI_CMD_HCRESET);
287 do { async_usleep(10); }
288 while ((pio_read_16(&registers->usbcmd) & UHCI_CMD_HCRESET) != 0);
289
[eb2a48a]290 /* Set frame to exactly 1ms */
291 pio_write_8(&registers->sofmod, 64);
292
293 /* Set frame list pointer */
[9351353]294 const uint32_t pa = addr_to_phys(instance->frame_list);
295 pio_write_32(&registers->flbaseadd, pa);
296
[32fb6bce]297 if (instance->base.irq_cap >= 0) {
[ff34e5a]298 /* Enable all interrupts, but resume interrupt */
299 pio_write_16(&instance->registers->usbintr,
[8986412]300 UHCI_INTR_ALLOW_INTERRUPTS);
[ff34e5a]301 }
[9351353]302
[26858040]303 const uint16_t cmd = pio_read_16(&registers->usbcmd);
304 if (cmd != 0)
305 usb_log_warning("Previous command value: %x.\n", cmd);
[9351353]306
307 /* Start the hc with large(64B) packet FSBR */
308 pio_write_16(&registers->usbcmd,
309 UHCI_CMD_RUN_STOP | UHCI_CMD_MAX_PACKET | UHCI_CMD_CONFIGURE);
310}
[76fbd9a]311
[6832245]312static usb_transfer_batch_t *create_transfer_batch(endpoint_t *ep)
[5fd9c30]313{
314 uhci_transfer_batch_t *batch = uhci_transfer_batch_create(ep);
315 return &batch->base;
316}
317
318static void destroy_transfer_batch(usb_transfer_batch_t *batch)
319{
320 uhci_transfer_batch_destroy(uhci_transfer_batch_get(batch));
321}
322
[5dfb70c9]323static int device_online(device_t *device)
324{
[c913f71e]325 int err;
326 hc_t *instance = bus_to_hc(device->bus);
327 assert(instance);
[5dfb70c9]328
[c913f71e]329 /* Allow creation of new endpoints and transfers. */
330 usb_log_info("Device(%d): Going online.", device->address);
331 fibril_mutex_lock(&device->guard);
332 device->online = true;
333 fibril_mutex_unlock(&device->guard);
334
335 if ((err = ddf_fun_online(device->fun))) {
336 return err;
337 }
338
339 return EOK;
[5dfb70c9]340}
341
342static int device_offline(device_t *device)
343{
[c913f71e]344 int err;
[5dfb70c9]345 hc_t *instance = bus_to_hc(device->bus);
346 assert(instance);
347
348 /* Tear down all drivers working with the device. */
349 if ((err = ddf_fun_offline(device->fun))) {
350 return err;
351 }
352
353 /* At this point, all drivers are assumed to have already terminated
354 * in a consistent way. The following code just cleans up hanging
355 * transfers if there are any. */
356
357 /* Block creation of new endpoints and transfers. */
358 usb_log_info("Device(%d): Going offline.", device->address);
359 fibril_mutex_lock(&device->guard);
360 device->online = false;
361 fibril_mutex_unlock(&device->guard);
362
363 /* Abort all transfers to all endpoints. */
364 transfer_list_abort_device(&instance->transfers_interrupt, device->address);
365 transfer_list_abort_device(&instance->transfers_control_slow, device->address);
366 transfer_list_abort_device(&instance->transfers_control_full, device->address);
367 transfer_list_abort_device(&instance->transfers_bulk_full, device->address);
368
369 return EOK;
370}
371
[32fb6bce]372static int hc_status(bus_t *, uint32_t *);
373static int hc_schedule(usb_transfer_batch_t *);
374
[6832245]375static const bus_ops_t uhci_bus_ops = {
376 .parent = &usb2_bus_ops,
377
[32fb6bce]378 .interrupt = hc_interrupt,
379 .status = hc_status,
380
[6832245]381 .endpoint_count_bw = bandwidth_count_usb11,
382 .batch_create = create_transfer_batch,
[32fb6bce]383 .batch_schedule = hc_schedule,
[6832245]384 .batch_destroy = destroy_transfer_batch,
[5dfb70c9]385
386 .device_online = device_online,
387 .device_offline = device_offline,
[6832245]388};
389
[17ceb72]390/** Initialize UHCI hc memory structures.
[9351353]391 *
392 * @param[in] instance UHCI structure to use.
393 * @return Error code
394 * @note Should be called only once on any structure.
[17ceb72]395 *
396 * Structures:
397 * - transfer lists (queue heads need to be accessible by the hw)
398 * - frame list page (needs to be one UHCI hw accessible 4K page)
[9351353]399 */
[32fb6bce]400int hc_init_mem_structures(hc_t *instance, hc_device_t *hcd)
[9351353]401{
402 assert(instance);
403
[5e2b1ae6]404 usb2_bus_init(&instance->bus, BANDWIDTH_AVAILABLE_USB11);
[e6b9182]405
[6832245]406 bus_t *bus = (bus_t *) &instance->bus;
407 bus->ops = &uhci_bus_ops;
[5fd9c30]408
[32fb6bce]409 hc_device_setup(&instance->base, bus);
410
[3afb758]411 /* Init USB frame list page */
[9351353]412 instance->frame_list = get_page();
[26858040]413 if (!instance->frame_list) {
414 return ENOMEM;
415 }
[001b152]416 usb_log_debug("Initialized frame list at %p.\n", instance->frame_list);
[9351353]417
[3afb758]418 /* Init transfer lists */
419 int ret = hc_init_transfer_lists(instance);
420 if (ret != EOK) {
421 usb_log_error("Failed to initialize transfer lists.\n");
422 return_page(instance->frame_list);
423 return ENOMEM;
424 }
425 usb_log_debug("Initialized transfer lists.\n");
426
427
[9351353]428 /* Set all frames to point to the first queue head */
[302a4b6]429 const uint32_t queue = LINK_POINTER_QH(
430 addr_to_phys(instance->transfers_interrupt.queue_head));
[75f9dcd]431
432 for (unsigned i = 0; i < UHCI_FRAME_LIST_COUNT; ++i) {
[9351353]433 instance->frame_list[i] = queue;
434 }
435
436 return EOK;
437}
[76fbd9a]438
[17ceb72]439/** Initialize UHCI hc transfer lists.
[9351353]440 *
441 * @param[in] instance UHCI structure to use.
442 * @return Error code
443 * @note Should be called only once on any structure.
[17ceb72]444 *
445 * Initializes transfer lists and sets them in one chain to support proper
446 * USB scheduling. Sets pointer table for quick access.
[9351353]447 */
[c01cd32]448int hc_init_transfer_lists(hc_t *instance)
[9351353]449{
450 assert(instance);
[27205841]451#define SETUP_TRANSFER_LIST(type, name) \
452do { \
453 int ret = transfer_list_init(&instance->transfers_##type, name); \
[9351353]454 if (ret != EOK) { \
[26858040]455 usb_log_error("Failed to setup %s transfer list: %s.\n", \
456 name, str_error(ret)); \
[9351353]457 transfer_list_fini(&instance->transfers_bulk_full); \
458 transfer_list_fini(&instance->transfers_control_full); \
459 transfer_list_fini(&instance->transfers_control_slow); \
460 transfer_list_fini(&instance->transfers_interrupt); \
461 return ret; \
[27205841]462 } \
463} while (0)
464
465 SETUP_TRANSFER_LIST(bulk_full, "BULK FULL");
466 SETUP_TRANSFER_LIST(control_full, "CONTROL FULL");
467 SETUP_TRANSFER_LIST(control_slow, "CONTROL LOW");
468 SETUP_TRANSFER_LIST(interrupt, "INTERRUPT");
469#undef SETUP_TRANSFER_LIST
470 /* Connect lists into one schedule */
[9351353]471 transfer_list_set_next(&instance->transfers_control_full,
472 &instance->transfers_bulk_full);
473 transfer_list_set_next(&instance->transfers_control_slow,
474 &instance->transfers_control_full);
475 transfer_list_set_next(&instance->transfers_interrupt,
476 &instance->transfers_control_slow);
477
[e247d83]478 /*FSBR, This feature is not needed (adds no benefit) and is supposedly
479 * buggy on certain hw, enable at your own risk. */
[9351353]480#ifdef FSBR
481 transfer_list_set_next(&instance->transfers_bulk_full,
[302a4b6]482 &instance->transfers_control_full);
[9351353]483#endif
484
485 /* Assign pointers to be used during scheduling */
486 instance->transfers[USB_SPEED_FULL][USB_TRANSFER_INTERRUPT] =
487 &instance->transfers_interrupt;
488 instance->transfers[USB_SPEED_LOW][USB_TRANSFER_INTERRUPT] =
489 &instance->transfers_interrupt;
490 instance->transfers[USB_SPEED_FULL][USB_TRANSFER_CONTROL] =
491 &instance->transfers_control_full;
492 instance->transfers[USB_SPEED_LOW][USB_TRANSFER_CONTROL] =
493 &instance->transfers_control_slow;
494 instance->transfers[USB_SPEED_FULL][USB_TRANSFER_BULK] =
495 &instance->transfers_bulk_full;
496
497 return EOK;
498}
[76fbd9a]499
[32fb6bce]500static int hc_status(bus_t *bus, uint32_t *status)
[e26a9d95]501{
[32fb6bce]502 hc_t *instance = bus_to_hc(bus);
[e26a9d95]503 assert(status);
504
505 *status = 0;
506 if (instance->registers) {
507 uint16_t s = pio_read_16(&instance->registers->usbsts);
508 pio_write_16(&instance->registers->usbsts, s);
509 *status = s;
510 }
511 return EOK;
512}
513
[17ceb72]514/** Schedule batch for execution.
[9351353]515 *
516 * @param[in] instance UHCI structure to use.
517 * @param[in] batch Transfer batch to schedule.
518 * @return Error code
[17ceb72]519 *
520 * Checks for bandwidth availability and appends the batch to the proper queue.
[9351353]521 */
[32fb6bce]522static int hc_schedule(usb_transfer_batch_t *batch)
[9351353]523{
[32fb6bce]524 hc_t *instance = bus_to_hc(endpoint_get_bus(batch->ep));
[9351353]525 assert(batch);
[c95c00e]526
[a5b3de6]527 if (batch->target.address == uhci_rh_get_address(&instance->rh))
[3848fec]528 return uhci_rh_schedule(&instance->rh, batch);
[c95c00e]529
[5fd9c30]530 uhci_transfer_batch_t *uhci_batch = (uhci_transfer_batch_t *) batch;
[b991d37]531 if (!uhci_batch) {
532 usb_log_error("Failed to create UHCI transfer structures.\n");
533 return ENOMEM;
[23b0fe8]534 }
[9351353]535
[5fd9c30]536 const int err = uhci_transfer_batch_prepare(uhci_batch);
537 if (err)
538 return err;
539
[9351353]540 transfer_list_t *list =
[888238e9]541 instance->transfers[batch->ep->device->speed][batch->ep->transfer_type];
[9351353]542 assert(list);
[b991d37]543 transfer_list_add_batch(list, uhci_batch);
[9351353]544
545 return EOK;
546}
[76fbd9a]547
[9351353]548/** Debug function, checks consistency of memory structures.
549 *
550 * @param[in] arg UHCI structure to use.
[17ceb72]551 * @return EOK (should never return)
[9351353]552 */
[c01cd32]553int hc_debug_checker(void *arg)
[9351353]554{
[6f122df]555 hc_t *instance = arg;
[9351353]556 assert(instance);
557
558#define QH(queue) \
559 instance->transfers_##queue.queue_head
560
561 while (1) {
562 const uint16_t cmd = pio_read_16(&instance->registers->usbcmd);
563 const uint16_t sts = pio_read_16(&instance->registers->usbsts);
564 const uint16_t intr =
565 pio_read_16(&instance->registers->usbintr);
566
567 if (((cmd & UHCI_CMD_RUN_STOP) != 1) || (sts != 0)) {
568 usb_log_debug2("Command: %X Status: %X Intr: %x\n",
569 cmd, sts, intr);
570 }
571
[e247d83]572 const uintptr_t frame_list =
[9351353]573 pio_read_32(&instance->registers->flbaseadd) & ~0xfff;
574 if (frame_list != addr_to_phys(instance->frame_list)) {
575 usb_log_debug("Framelist address: %p vs. %p.\n",
[4125b7d]576 (void *) frame_list,
577 (void *) addr_to_phys(instance->frame_list));
[9351353]578 }
579
580 int frnum = pio_read_16(&instance->registers->frnum) & 0x3ff;
581
582 uintptr_t expected_pa = instance->frame_list[frnum]
583 & LINK_POINTER_ADDRESS_MASK;
584 uintptr_t real_pa = addr_to_phys(QH(interrupt));
585 if (expected_pa != real_pa) {
[4125b7d]586 usb_log_debug("Interrupt QH: %p (frame %d) vs. %p.\n",
587 (void *) expected_pa, frnum, (void *) real_pa);
[9351353]588 }
589
590 expected_pa = QH(interrupt)->next & LINK_POINTER_ADDRESS_MASK;
591 real_pa = addr_to_phys(QH(control_slow));
592 if (expected_pa != real_pa) {
593 usb_log_debug("Control Slow QH: %p vs. %p.\n",
[4125b7d]594 (void *) expected_pa, (void *) real_pa);
[9351353]595 }
596
597 expected_pa = QH(control_slow)->next & LINK_POINTER_ADDRESS_MASK;
598 real_pa = addr_to_phys(QH(control_full));
599 if (expected_pa != real_pa) {
600 usb_log_debug("Control Full QH: %p vs. %p.\n",
[4125b7d]601 (void *) expected_pa, (void *) real_pa);
[9351353]602 }
603
604 expected_pa = QH(control_full)->next & LINK_POINTER_ADDRESS_MASK;
605 real_pa = addr_to_phys(QH(bulk_full));
606 if (expected_pa != real_pa ) {
607 usb_log_debug("Bulk QH: %p vs. %p.\n",
[4125b7d]608 (void *) expected_pa, (void *) real_pa);
[9351353]609 }
610 async_usleep(UHCI_DEBUGER_TIMEOUT);
611 }
612 return EOK;
613#undef QH
614}
615/**
616 * @}
617 */
Note: See TracBrowser for help on using the repository browser.