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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5bccec3 was 2755a622, checked in by Ondřej Hlavatý <aearsis@…>, 8 years ago

uhci: fix transfer aborting

  • Property mode set to 100644
File size: 17.3 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"
[929599a8]55#include "transfer_list.h"
[8064c2f6]56#include "hc.h"
[9351353]57
[8986412]58#define UHCI_INTR_ALLOW_INTERRUPTS \
[af81980]59 (UHCI_INTR_CRC | UHCI_INTR_COMPLETE | UHCI_INTR_SHORT_PACKET)
[8986412]60#define UHCI_STATUS_USED_INTERRUPTS \
61 (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)
[af81980]62
[d57122c]63static const irq_pio_range_t uhci_irq_pio_ranges[] = {
64 {
[8486c07]65 .base = 0,
[d57122c]66 .size = sizeof(uhci_regs_t)
67 }
68};
[5fe0a697]69
[d57122c]70static const irq_cmd_t uhci_irq_commands[] = {
[8486c07]71 {
72 .cmd = CMD_PIO_READ_16,
73 .dstarg = 1,
74 .addr = NULL
75 },
76 {
77 .cmd = CMD_AND,
78 .srcarg = 1,
79 .dstarg = 2,
80 .value = UHCI_STATUS_USED_INTERRUPTS | UHCI_STATUS_NM_INTERRUPTS
81 },
82 {
83 .cmd = CMD_PREDICATE,
84 .srcarg = 2,
85 .value = 2
86 },
87 {
88 .cmd = CMD_PIO_WRITE_A_16,
89 .srcarg = 1,
90 .addr = NULL
91 },
92 {
93 .cmd = CMD_ACCEPT
94 }
[dfe4955]95};
[302a4b6]96
[3afb758]97static void hc_init_hw(const hc_t *instance);
[32fb6bce]98static int hc_init_mem_structures(hc_t *instance, hc_device_t *);
[3afb758]99static int hc_init_transfer_lists(hc_t *instance);
[9351353]100
[c01cd32]101static int hc_debug_checker(void *arg);
[dfe4955]102
[76fbd9a]103
[d57122c]104/** Generate IRQ code.
[6210a333]105 * @param[out] code IRQ code structure.
[ba4a03a5]106 * @param[in] hw_res Device's resources.
[dfe4955]107 *
108 * @return Error code.
109 */
[32fb6bce]110int hc_gen_irq_code(irq_code_t *code, hc_device_t *hcd, const hw_res_list_parsed_t *hw_res)
[dfe4955]111{
[6210a333]112 assert(code);
[ba4a03a5]113 assert(hw_res);
[6210a333]114
[ba4a03a5]115 if (hw_res->irqs.count != 1 || hw_res->io_ranges.count != 1)
116 return EINVAL;
117 const addr_range_t regs = hw_res->io_ranges.ranges[0];
118
119 if (RNGSZ(regs) < sizeof(uhci_regs_t))
[dfe4955]120 return EOVERFLOW;
121
[6210a333]122 code->ranges = malloc(sizeof(uhci_irq_pio_ranges));
123 if (code->ranges == NULL)
124 return ENOMEM;
125
126 code->cmds = malloc(sizeof(uhci_irq_commands));
127 if (code->cmds == NULL) {
128 free(code->ranges);
129 return ENOMEM;
130 }
131
132 code->rangecount = ARRAY_SIZE(uhci_irq_pio_ranges);
133 code->cmdcount = ARRAY_SIZE(uhci_irq_commands);
[dfe4955]134
[6210a333]135 memcpy(code->ranges, uhci_irq_pio_ranges, sizeof(uhci_irq_pio_ranges));
[ba4a03a5]136 code->ranges[0].base = RNGABS(regs);
[6210a333]137
138 memcpy(code->cmds, uhci_irq_commands, sizeof(uhci_irq_commands));
[ba4a03a5]139 uhci_regs_t *registers = (uhci_regs_t *) RNGABSPTR(regs);
[6210a333]140 code->cmds[0].addr = (void*)&registers->usbsts;
141 code->cmds[3].addr = (void*)&registers->usbsts;
[dfe4955]142
[a1732929]143 usb_log_debug("I/O regs at %p (size %zu), IRQ %d.",
[ba4a03a5]144 RNGABSPTR(regs), RNGSZ(regs), hw_res->irqs.irqs[0]);
145
146 return hw_res->irqs.irqs[0];
[dfe4955]147}
[76fbd9a]148
[3afb758]149/** Take action based on the interrupt cause.
150 *
[4bfcf22]151 * @param[in] hcd HCD structure to use.
[3afb758]152 * @param[in] status Value of the status register at the time of interrupt.
153 *
154 * Interrupt might indicate:
155 * - transaction completed, either by triggering IOC, SPD, or an error
156 * - some kind of device error
157 * - resume from suspend state (not implemented)
158 */
[32fb6bce]159static void hc_interrupt(bus_t *bus, uint32_t status)
[3afb758]160{
[32fb6bce]161 hc_t *instance = bus_to_hc(bus);
162
[3afb758]163 /* Lower 2 bits are transaction error and transaction complete */
164 if (status & (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)) {
165 LIST_INITIALIZE(done);
166 transfer_list_remove_finished(
167 &instance->transfers_interrupt, &done);
168 transfer_list_remove_finished(
169 &instance->transfers_control_slow, &done);
170 transfer_list_remove_finished(
171 &instance->transfers_control_full, &done);
172 transfer_list_remove_finished(
173 &instance->transfers_bulk_full, &done);
174
[ad5f149]175 list_foreach_safe(done, current, next) {
176 list_remove(current);
[b991d37]177 uhci_transfer_batch_t *batch =
[ad5f149]178 uhci_transfer_batch_from_link(current);
[17873ac7]179 usb_transfer_batch_finish(&batch->base);
[3afb758]180 }
181 }
182 /* Resume interrupts are not supported */
183 if (status & UHCI_STATUS_RESUME) {
[a1732929]184 usb_log_error("Resume interrupt!");
[3afb758]185 }
186
187 /* Bits 4 and 5 indicate hc error */
188 if (status & (UHCI_STATUS_PROCESS_ERROR | UHCI_STATUS_SYSTEM_ERROR)) {
[a1732929]189 usb_log_error("UHCI hardware failure!.");
[3afb758]190 ++instance->hw_failures;
191 transfer_list_abort_all(&instance->transfers_interrupt);
192 transfer_list_abort_all(&instance->transfers_control_slow);
193 transfer_list_abort_all(&instance->transfers_control_full);
194 transfer_list_abort_all(&instance->transfers_bulk_full);
195
196 if (instance->hw_failures < UHCI_ALLOWED_HW_FAIL) {
197 /* reinitialize hw, this triggers virtual disconnect*/
198 hc_init_hw(instance);
199 } else {
[a1732929]200 usb_log_fatal("Too many UHCI hardware failures!.");
[32fb6bce]201 hc_gone(&instance->base);
[3afb758]202 }
203 }
204}
[76fbd9a]205
[02cacce]206/** Initialize UHCI hc driver structure
[9351353]207 *
208 * @param[in] instance Memory place to initialize.
[7de1988c]209 * @param[in] regs Range of device's I/O control registers.
[23f40280]210 * @param[in] interrupts True if hw interrupts should be used.
[9351353]211 * @return Error code.
212 * @note Should be called only once on any structure.
[17ceb72]213 *
214 * Initializes memory structures, starts up hw, and launches debugger and
215 * interrupt fibrils.
[9351353]216 */
[32fb6bce]217int hc_add(hc_device_t *hcd, const hw_res_list_parsed_t *hw_res)
[9351353]218{
[32fb6bce]219 hc_t *instance = hcd_to_hc(hcd);
[7813516]220 assert(hw_res);
221 if (hw_res->io_ranges.count != 1 ||
222 hw_res->io_ranges.ranges[0].size < sizeof(uhci_regs_t))
223 return EINVAL;
[9351353]224
[fcc525d]225 instance->hw_failures = 0;
226
[9351353]227 /* allow access to hc control registers */
[7813516]228 int ret = pio_enable_range(&hw_res->io_ranges.ranges[0],
229 (void **) &instance->registers);
[e0d8b740]230 if (ret != EOK) {
[a1732929]231 usb_log_error("Failed to gain access to registers: %s.",
[7813516]232 str_error(ret));
[e0d8b740]233 return ret;
234 }
235
[a1732929]236 usb_log_debug("Device registers at %" PRIx64 " (%zuB) accessible.",
[7813516]237 hw_res->io_ranges.ranges[0].address.absolute,
238 hw_res->io_ranges.ranges[0].size);
[3afb758]239
[6832245]240 ret = hc_init_mem_structures(instance, hcd);
[e0d8b740]241 if (ret != EOK) {
[a1732929]242 usb_log_error("Failed to init UHCI memory structures: %s.",
[e0d8b740]243 str_error(ret));
244 // TODO: we should disable pio here
245 return ret;
246 }
[7265558]247
[e4d7363]248 return EOK;
249}
250
[32fb6bce]251int hc_start(hc_device_t *hcd)
[e4d7363]252{
[32fb6bce]253 hc_t *instance = hcd_to_hc(hcd);
[c01cd32]254 hc_init_hw(instance);
[ea993d18]255 (void)hc_debug_checker;
[9351353]256
[32fb6bce]257 return uhci_rh_init(&instance->rh, instance->registers->ports, "uhci");
[9351353]258}
[76fbd9a]259
[7813516]260/** Safely dispose host controller internal structures
261 *
262 * @param[in] instance Host controller structure to use.
263 */
[32fb6bce]264int hc_gone(hc_device_t *instance)
[7813516]265{
266 assert(instance);
267 //TODO Implement
[32fb6bce]268 return ENOTSUP;
[7813516]269}
270
[17ceb72]271/** Initialize UHCI hc hw resources.
[9351353]272 *
273 * @param[in] instance UHCI structure to use.
[17ceb72]274 * For magic values see UHCI Design Guide
[9351353]275 */
[3afb758]276void hc_init_hw(const hc_t *instance)
[9351353]277{
278 assert(instance);
[dfe4955]279 uhci_regs_t *registers = instance->registers;
[9351353]280
281 /* Reset everything, who knows what touched it before us */
282 pio_write_16(&registers->usbcmd, UHCI_CMD_GLOBAL_RESET);
[26858040]283 async_usleep(50000); /* 50ms according to USB spec(root hub reset) */
[9351353]284 pio_write_16(&registers->usbcmd, 0);
285
[26858040]286 /* Reset hc, all states and counters. Hope that hw is not broken */
[9351353]287 pio_write_16(&registers->usbcmd, UHCI_CMD_HCRESET);
288 do { async_usleep(10); }
289 while ((pio_read_16(&registers->usbcmd) & UHCI_CMD_HCRESET) != 0);
290
[eb2a48a]291 /* Set frame to exactly 1ms */
292 pio_write_8(&registers->sofmod, 64);
293
294 /* Set frame list pointer */
[9351353]295 const uint32_t pa = addr_to_phys(instance->frame_list);
296 pio_write_32(&registers->flbaseadd, pa);
297
[32fb6bce]298 if (instance->base.irq_cap >= 0) {
[ff34e5a]299 /* Enable all interrupts, but resume interrupt */
300 pio_write_16(&instance->registers->usbintr,
[8986412]301 UHCI_INTR_ALLOW_INTERRUPTS);
[ff34e5a]302 }
[9351353]303
[26858040]304 const uint16_t cmd = pio_read_16(&registers->usbcmd);
305 if (cmd != 0)
[a1732929]306 usb_log_warning("Previous command value: %x.", cmd);
[9351353]307
308 /* Start the hc with large(64B) packet FSBR */
309 pio_write_16(&registers->usbcmd,
310 UHCI_CMD_RUN_STOP | UHCI_CMD_MAX_PACKET | UHCI_CMD_CONFIGURE);
311}
[76fbd9a]312
[6832245]313static usb_transfer_batch_t *create_transfer_batch(endpoint_t *ep)
[5fd9c30]314{
315 uhci_transfer_batch_t *batch = uhci_transfer_batch_create(ep);
316 return &batch->base;
317}
318
319static void destroy_transfer_batch(usb_transfer_batch_t *batch)
320{
321 uhci_transfer_batch_destroy(uhci_transfer_batch_get(batch));
322}
323
[0892663a]324static void endpoint_unregister(endpoint_t *ep)
[5dfb70c9]325{
[929599a8]326 hc_t * const hc = bus_to_hc(endpoint_get_bus(ep));
[0892663a]327 usb2_bus_ops.endpoint_unregister(ep);
[c913f71e]328
[929599a8]329 uhci_transfer_batch_t *batch = NULL;
330
[2755a622]331 // Check for the roothub, as it does not schedule into lists
332 if (ep->device->speed == USB_SPEED_MAX) {
333 // FIXME: We shall check the roothub for active transfer. But
334 // as it is polling, there is no way to make it stop doing so.
335 // Return after rewriting uhci rh.
336 return;
337 }
338
339 transfer_list_t *list = hc->transfers[ep->device->speed][ep->transfer_type];
340 assert(list);
341
342 // To avoid ABBA deadlock, we need to take the list first
343 fibril_mutex_lock(&list->guard);
[0892663a]344 fibril_mutex_lock(&ep->guard);
345 if (ep->active_batch) {
[929599a8]346 batch = uhci_transfer_batch_get(ep->active_batch);
[2755a622]347 endpoint_deactivate_locked(ep);
[929599a8]348 transfer_list_remove_batch(list, batch);
[5dfb70c9]349 }
[0892663a]350 fibril_mutex_unlock(&ep->guard);
[2755a622]351 fibril_mutex_unlock(&list->guard);
[929599a8]352
353 if (batch) {
[2755a622]354 // The HW could have been looking at the batch.
355 // Better wait two frames before we release the buffers.
356 endpoint_wait_timeout_locked(ep, 2000);
[929599a8]357 batch->base.error = EINTR;
358 batch->base.transfered_size = 0;
359 usb_transfer_batch_finish(&batch->base);
360 }
[5dfb70c9]361}
362
[32fb6bce]363static int hc_status(bus_t *, uint32_t *);
364static int hc_schedule(usb_transfer_batch_t *);
365
[6832245]366static const bus_ops_t uhci_bus_ops = {
367 .parent = &usb2_bus_ops,
368
[32fb6bce]369 .interrupt = hc_interrupt,
370 .status = hc_status,
371
[0892663a]372 .endpoint_unregister = endpoint_unregister,
[6832245]373 .endpoint_count_bw = bandwidth_count_usb11,
[0892663a]374
[6832245]375 .batch_create = create_transfer_batch,
[32fb6bce]376 .batch_schedule = hc_schedule,
[6832245]377 .batch_destroy = destroy_transfer_batch,
378};
379
[17ceb72]380/** Initialize UHCI hc memory structures.
[9351353]381 *
382 * @param[in] instance UHCI structure to use.
383 * @return Error code
384 * @note Should be called only once on any structure.
[17ceb72]385 *
386 * Structures:
387 * - transfer lists (queue heads need to be accessible by the hw)
388 * - frame list page (needs to be one UHCI hw accessible 4K page)
[9351353]389 */
[32fb6bce]390int hc_init_mem_structures(hc_t *instance, hc_device_t *hcd)
[9351353]391{
392 assert(instance);
393
[5e2b1ae6]394 usb2_bus_init(&instance->bus, BANDWIDTH_AVAILABLE_USB11);
[e6b9182]395
[6832245]396 bus_t *bus = (bus_t *) &instance->bus;
397 bus->ops = &uhci_bus_ops;
[5fd9c30]398
[32fb6bce]399 hc_device_setup(&instance->base, bus);
400
[3afb758]401 /* Init USB frame list page */
[9351353]402 instance->frame_list = get_page();
[26858040]403 if (!instance->frame_list) {
404 return ENOMEM;
405 }
[a1732929]406 usb_log_debug("Initialized frame list at %p.", instance->frame_list);
[9351353]407
[3afb758]408 /* Init transfer lists */
409 int ret = hc_init_transfer_lists(instance);
410 if (ret != EOK) {
[a1732929]411 usb_log_error("Failed to initialize transfer lists.");
[3afb758]412 return_page(instance->frame_list);
413 return ENOMEM;
414 }
[a1732929]415 usb_log_debug("Initialized transfer lists.");
[3afb758]416
417
[9351353]418 /* Set all frames to point to the first queue head */
[302a4b6]419 const uint32_t queue = LINK_POINTER_QH(
420 addr_to_phys(instance->transfers_interrupt.queue_head));
[75f9dcd]421
422 for (unsigned i = 0; i < UHCI_FRAME_LIST_COUNT; ++i) {
[9351353]423 instance->frame_list[i] = queue;
424 }
425
426 return EOK;
427}
[76fbd9a]428
[17ceb72]429/** Initialize UHCI hc transfer lists.
[9351353]430 *
431 * @param[in] instance UHCI structure to use.
432 * @return Error code
433 * @note Should be called only once on any structure.
[17ceb72]434 *
435 * Initializes transfer lists and sets them in one chain to support proper
436 * USB scheduling. Sets pointer table for quick access.
[9351353]437 */
[c01cd32]438int hc_init_transfer_lists(hc_t *instance)
[9351353]439{
440 assert(instance);
[27205841]441#define SETUP_TRANSFER_LIST(type, name) \
442do { \
443 int ret = transfer_list_init(&instance->transfers_##type, name); \
[9351353]444 if (ret != EOK) { \
[a1732929]445 usb_log_error("Failed to setup %s transfer list: %s.", \
[26858040]446 name, str_error(ret)); \
[9351353]447 transfer_list_fini(&instance->transfers_bulk_full); \
448 transfer_list_fini(&instance->transfers_control_full); \
449 transfer_list_fini(&instance->transfers_control_slow); \
450 transfer_list_fini(&instance->transfers_interrupt); \
451 return ret; \
[27205841]452 } \
453} while (0)
454
455 SETUP_TRANSFER_LIST(bulk_full, "BULK FULL");
456 SETUP_TRANSFER_LIST(control_full, "CONTROL FULL");
457 SETUP_TRANSFER_LIST(control_slow, "CONTROL LOW");
458 SETUP_TRANSFER_LIST(interrupt, "INTERRUPT");
459#undef SETUP_TRANSFER_LIST
460 /* Connect lists into one schedule */
[9351353]461 transfer_list_set_next(&instance->transfers_control_full,
462 &instance->transfers_bulk_full);
463 transfer_list_set_next(&instance->transfers_control_slow,
464 &instance->transfers_control_full);
465 transfer_list_set_next(&instance->transfers_interrupt,
466 &instance->transfers_control_slow);
467
[e247d83]468 /*FSBR, This feature is not needed (adds no benefit) and is supposedly
469 * buggy on certain hw, enable at your own risk. */
[9351353]470#ifdef FSBR
471 transfer_list_set_next(&instance->transfers_bulk_full,
[302a4b6]472 &instance->transfers_control_full);
[9351353]473#endif
474
475 /* Assign pointers to be used during scheduling */
476 instance->transfers[USB_SPEED_FULL][USB_TRANSFER_INTERRUPT] =
477 &instance->transfers_interrupt;
478 instance->transfers[USB_SPEED_LOW][USB_TRANSFER_INTERRUPT] =
479 &instance->transfers_interrupt;
480 instance->transfers[USB_SPEED_FULL][USB_TRANSFER_CONTROL] =
481 &instance->transfers_control_full;
482 instance->transfers[USB_SPEED_LOW][USB_TRANSFER_CONTROL] =
483 &instance->transfers_control_slow;
484 instance->transfers[USB_SPEED_FULL][USB_TRANSFER_BULK] =
485 &instance->transfers_bulk_full;
486
487 return EOK;
488}
[76fbd9a]489
[32fb6bce]490static int hc_status(bus_t *bus, uint32_t *status)
[e26a9d95]491{
[32fb6bce]492 hc_t *instance = bus_to_hc(bus);
[e26a9d95]493 assert(status);
494
495 *status = 0;
496 if (instance->registers) {
497 uint16_t s = pio_read_16(&instance->registers->usbsts);
498 pio_write_16(&instance->registers->usbsts, s);
499 *status = s;
500 }
501 return EOK;
502}
503
[17ceb72]504/** Schedule batch for execution.
[9351353]505 *
506 * @param[in] instance UHCI structure to use.
507 * @param[in] batch Transfer batch to schedule.
508 * @return Error code
[17ceb72]509 *
510 * Checks for bandwidth availability and appends the batch to the proper queue.
[9351353]511 */
[32fb6bce]512static int hc_schedule(usb_transfer_batch_t *batch)
[9351353]513{
[929599a8]514 uhci_transfer_batch_t *uhci_batch = uhci_transfer_batch_get(batch);
515 endpoint_t *ep = batch->ep;
516 hc_t *hc = bus_to_hc(endpoint_get_bus(ep));
[c95c00e]517
[929599a8]518 if (batch->target.address == uhci_rh_get_address(&hc->rh))
519 return uhci_rh_schedule(&hc->rh, batch);
[c95c00e]520
[9351353]521
[5fd9c30]522 const int err = uhci_transfer_batch_prepare(uhci_batch);
523 if (err)
524 return err;
525
[929599a8]526 transfer_list_t *list = hc->transfers[ep->device->speed][ep->transfer_type];
[9351353]527 assert(list);
[b991d37]528 transfer_list_add_batch(list, uhci_batch);
[9351353]529
530 return EOK;
531}
[76fbd9a]532
[929599a8]533int hc_unschedule_batch(usb_transfer_batch_t *batch)
534{
535
536 return EOK;
537}
538
[9351353]539/** Debug function, checks consistency of memory structures.
540 *
541 * @param[in] arg UHCI structure to use.
[17ceb72]542 * @return EOK (should never return)
[9351353]543 */
[c01cd32]544int hc_debug_checker(void *arg)
[9351353]545{
[6f122df]546 hc_t *instance = arg;
[9351353]547 assert(instance);
548
549#define QH(queue) \
550 instance->transfers_##queue.queue_head
551
552 while (1) {
553 const uint16_t cmd = pio_read_16(&instance->registers->usbcmd);
554 const uint16_t sts = pio_read_16(&instance->registers->usbsts);
555 const uint16_t intr =
556 pio_read_16(&instance->registers->usbintr);
557
558 if (((cmd & UHCI_CMD_RUN_STOP) != 1) || (sts != 0)) {
[a1732929]559 usb_log_debug2("Command: %X Status: %X Intr: %x",
[9351353]560 cmd, sts, intr);
561 }
562
[e247d83]563 const uintptr_t frame_list =
[9351353]564 pio_read_32(&instance->registers->flbaseadd) & ~0xfff;
565 if (frame_list != addr_to_phys(instance->frame_list)) {
[a1732929]566 usb_log_debug("Framelist address: %p vs. %p.",
[4125b7d]567 (void *) frame_list,
568 (void *) addr_to_phys(instance->frame_list));
[9351353]569 }
570
571 int frnum = pio_read_16(&instance->registers->frnum) & 0x3ff;
572
573 uintptr_t expected_pa = instance->frame_list[frnum]
574 & LINK_POINTER_ADDRESS_MASK;
575 uintptr_t real_pa = addr_to_phys(QH(interrupt));
576 if (expected_pa != real_pa) {
[a1732929]577 usb_log_debug("Interrupt QH: %p (frame %d) vs. %p.",
[4125b7d]578 (void *) expected_pa, frnum, (void *) real_pa);
[9351353]579 }
580
581 expected_pa = QH(interrupt)->next & LINK_POINTER_ADDRESS_MASK;
582 real_pa = addr_to_phys(QH(control_slow));
583 if (expected_pa != real_pa) {
[a1732929]584 usb_log_debug("Control Slow QH: %p vs. %p.",
[4125b7d]585 (void *) expected_pa, (void *) real_pa);
[9351353]586 }
587
588 expected_pa = QH(control_slow)->next & LINK_POINTER_ADDRESS_MASK;
589 real_pa = addr_to_phys(QH(control_full));
590 if (expected_pa != real_pa) {
[a1732929]591 usb_log_debug("Control Full QH: %p vs. %p.",
[4125b7d]592 (void *) expected_pa, (void *) real_pa);
[9351353]593 }
594
595 expected_pa = QH(control_full)->next & LINK_POINTER_ADDRESS_MASK;
596 real_pa = addr_to_phys(QH(bulk_full));
597 if (expected_pa != real_pa ) {
[a1732929]598 usb_log_debug("Bulk QH: %p vs. %p.",
[4125b7d]599 (void *) expected_pa, (void *) real_pa);
[9351353]600 }
601 async_usleep(UHCI_DEBUGER_TIMEOUT);
602 }
603 return EOK;
604#undef QH
605}
606/**
607 * @}
608 */
Note: See TracBrowser for help on using the repository browser.