source: mainline/uspace/drv/bus/usb/ehci/ehci_rh.c@ b2aaaa0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b2aaaa0 was 5f97ef44, checked in by Jiří Zárevúcky <jiri.zarevucky@…>, 7 years ago

Sleep is more natural as part of the fibril API.
(the implementation will move later)

  • Property mode set to 100644
File size: 20.3 KB
Line 
1/*
2 * Copyright (c) 2013 Jan Vesely
3 * Copyright (c) 2018 Ondrej Hlavaty
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29/** @addtogroup drvusbehci
30 * @{
31 */
32/** @file
33 * @brief EHCI driver
34 */
35
36#include <assert.h>
37#include <errno.h>
38#include <mem.h>
39#include <str_error.h>
40#include <stdint.h>
41#include <stddef.h>
42
43#include <usb/classes/hub.h>
44#include <usb/debug.h>
45#include <usb/descriptor.h>
46#include <usb/request.h>
47#include <usb/usb.h>
48
49#include <usb/host/endpoint.h>
50#include <usbvirt/device.h>
51
52#include "ehci_rh.h"
53
54enum {
55 HUB_STATUS_CHANGE_PIPE = 1,
56};
57
58static usbvirt_device_ops_t ops;
59
60/** Initialize internal USB HUB class descriptor.
61 * @param instance EHCI root hub.
62 * Use register based info to create accurate descriptor.
63 */
64static void ehci_rh_hub_desc_init(ehci_rh_t *instance, unsigned hcs)
65{
66 assert(instance);
67 const unsigned dsize = sizeof(usb_hub_descriptor_header_t) +
68 STATUS_BYTES(instance->port_count) * 2;
69 assert(dsize <= sizeof(instance->hub_descriptor));
70
71 instance->hub_descriptor.header.length = dsize;
72 instance->hub_descriptor.header.descriptor_type = USB_DESCTYPE_HUB;
73 instance->hub_descriptor.header.port_count = instance->port_count;
74 /*
75 * Bits 0,1 indicate power switching mode
76 * Bit 2 indicates device type (compound device)
77 * Bits 3,4 indicate over-current protection mode
78 */
79 instance->hub_descriptor.header.characteristics = 0 |
80 ((hcs & EHCI_CAPS_HCS_PPC_FLAG) ? 0x09 : 0x12) |
81 ((hcs & EHCI_CAPS_HCS_INDICATORS_FLAG) ? 0x80 : 0) |
82 (0x3 << 5); /* Need 32 FS bit times */ // TODO Implement
83 instance->hub_descriptor.header.characteristics_reserved = 0;
84 instance->hub_descriptor.header.power_good_time = 50;
85 /* bHubContrCurrent, root hubs don't need no power. */
86 instance->hub_descriptor.header.max_current = 0;
87
88 /* Device removable and some legacy 1.0 stuff*/
89 instance->hub_descriptor.rempow[0] = 0xff;
90 instance->hub_descriptor.rempow[1] = 0xff;
91 instance->hub_descriptor.rempow[2] = 0xff;
92 instance->hub_descriptor.rempow[3] = 0xff;
93
94}
95/** Initialize EHCI root hub.
96 * @param instance Place to initialize.
97 * @param regs EHCI device registers.
98 * @param name Device name.
99 * return Error code, EOK on success.
100 *
101 * Selects preconfigured port powering mode, sets up descriptor, and
102 * initializes internal virtual hub.
103 */
104errno_t ehci_rh_init(ehci_rh_t *instance, ehci_caps_regs_t *caps, ehci_regs_t *regs,
105 fibril_mutex_t *guard, const char *name)
106{
107 assert(instance);
108 instance->registers = regs;
109 instance->port_count =
110 (EHCI_RD(caps->hcsparams) >> EHCI_CAPS_HCS_N_PORTS_SHIFT) &
111 EHCI_CAPS_HCS_N_PORTS_MASK;
112 usb_log_debug2("RH(%p): hcsparams: %x.", instance,
113 EHCI_RD(caps->hcsparams));
114 usb_log_info("RH(%p): Found %u ports.", instance,
115 instance->port_count);
116
117 if (EHCI_RD(caps->hcsparams) & EHCI_CAPS_HCS_PPC_FLAG) {
118 usb_log_info("RH(%p): Per-port power switching.", instance);
119 } else {
120 usb_log_info("RH(%p): No power switching.", instance);
121 }
122 for (unsigned i = 0; i < instance->port_count; ++i)
123 usb_log_debug2("RH(%p-%u): status: %" PRIx32, instance, i,
124 EHCI_RD(regs->portsc[i]));
125
126 for (unsigned i = 0; i < EHCI_MAX_PORTS; ++i) {
127 instance->reset_flag[i] = false;
128 instance->resume_flag[i] = false;
129 }
130
131 ehci_rh_hub_desc_init(instance, EHCI_RD(caps->hcsparams));
132 instance->guard = guard;
133 instance->status_change_endpoint = NULL;
134
135 return virthub_base_init(&instance->base, name, &ops, instance,
136 NULL, &instance->hub_descriptor.header, HUB_STATUS_CHANGE_PIPE);
137}
138
139/** Schedule USB request.
140 * @param instance OCHI root hub instance.
141 * @param batch USB requst batch to schedule.
142 * @return Always EOK.
143 * Most requests complete even before this function returns,
144 * status change requests might be postponed until there is something to report.
145 */
146errno_t ehci_rh_schedule(ehci_rh_t *instance, usb_transfer_batch_t *batch)
147{
148 assert(instance);
149 assert(batch);
150 batch->error = virthub_base_request(&instance->base, batch->target,
151 batch->dir, (void *) batch->setup.buffer,
152 batch->dma_buffer.virt, batch->size,
153 &batch->transferred_size);
154 if (batch->error == ENAK) {
155 usb_log_debug("RH(%p): BATCH(%p) adding as unfinished",
156 instance, batch);
157
158 /* Lock the HC guard */
159 fibril_mutex_lock(instance->guard);
160 const int err = endpoint_activate_locked(batch->ep, batch);
161 if (err) {
162 fibril_mutex_unlock(batch->ep->guard);
163 return err;
164 }
165
166 /*
167 * Asserting that the HC do not run two instances of the status
168 * change endpoint - shall be true.
169 */
170 assert(!instance->status_change_endpoint);
171
172 endpoint_add_ref(batch->ep);
173 instance->status_change_endpoint = batch->ep;
174 fibril_mutex_unlock(instance->guard);
175 } else {
176 usb_log_debug("RH(%p): BATCH(%p) virtual request complete: %s",
177 instance, batch, str_error(batch->error));
178 usb_transfer_batch_finish(batch);
179 }
180 return EOK;
181}
182
183/** Handle EHCI RHSC interrupt.
184 * @param instance EHCI root hub isntance.
185 * @return Always EOK.
186 *
187 * Interrupt means there is a change of status to report. It may trigger
188 * processing of a postponed request.
189 */
190errno_t ehci_rh_interrupt(ehci_rh_t *instance)
191{
192 fibril_mutex_lock(instance->guard);
193 endpoint_t *ep = instance->status_change_endpoint;
194 if (!ep) {
195 fibril_mutex_unlock(instance->guard);
196 return EOK;
197 }
198
199 usb_transfer_batch_t *const batch = ep->active_batch;
200 endpoint_deactivate_locked(ep);
201 instance->status_change_endpoint = NULL;
202 fibril_mutex_unlock(instance->guard);
203
204 endpoint_del_ref(ep);
205
206 if (batch) {
207 usb_log_debug2("RH(%p): Interrupt. Processing batch: %p",
208 instance, batch);
209 batch->error = virthub_base_request(&instance->base, batch->target,
210 batch->dir, (void *) batch->setup.buffer,
211 batch->dma_buffer.virt, batch->size,
212 &batch->transferred_size);
213 usb_transfer_batch_finish(batch);
214 }
215 return EOK;
216}
217
218/* HUB ROUTINES IMPLEMENTATION */
219#define TEST_SIZE_INIT(size, port, hub) \
220do { \
221 hub = virthub_get_data(device); \
222 assert(hub);\
223 if (uint16_usb2host(setup_packet->length) != size) \
224 return ESTALL; \
225 port = uint16_usb2host(setup_packet->index) - 1; \
226 if (port > hub->port_count) \
227 return EINVAL; \
228} while (0)
229
230/** Hub status request handler.
231 * @param device Virtual hub device
232 * @param setup_packet USB setup stage data.
233 * @param[out] data destination data buffer, size must be at least
234 * setup_packet->length bytes
235 * @param[out] act_size Sized of the valid response part of the buffer.
236 * @return Error code.
237 */
238static errno_t req_get_status(usbvirt_device_t *device,
239 const usb_device_request_setup_packet_t *setup_packet,
240 uint8_t *data, size_t *act_size)
241{
242 ehci_rh_t *hub = virthub_get_data(device);
243 assert(hub);
244 if (uint16_usb2host(setup_packet->length) != 4)
245 return ESTALL;
246 /* ECHI RH does not report global OC, and local power is always good */
247 const uint32_t val = 0;
248 memcpy(data, &val, sizeof(val));
249 *act_size = sizeof(val);
250 return EOK;
251}
252
253/** Hub set feature request handler.
254 * @param device Virtual hub device
255 * @param setup_packet USB setup stage data.
256 * @param[out] data destination data buffer, size must be at least
257 * setup_packet->length bytes
258 * @param[out] act_size Sized of the valid response part of the buffer.
259 * @return Error code.
260 */
261static errno_t req_clear_hub_feature(usbvirt_device_t *device,
262 const usb_device_request_setup_packet_t *setup_packet,
263 uint8_t *data, size_t *act_size)
264{
265 ehci_rh_t *hub = virthub_get_data(device);
266 assert(hub);
267
268 /*
269 * Chapter 11.16.2 specifies that only C_HUB_LOCAL_POWER and
270 * C_HUB_OVER_CURRENT are supported.
271 * C_HUB_LOCAL_POWER is not supported because root hubs do not support
272 * local power status feature.
273 * EHCI RH does not report global OC condition either
274 */
275 return ESTALL;
276}
277
278#define BIT_VAL(val, bit) ((val & bit) ? 1 : 0)
279#define EHCI2USB(val, bit, mask) (BIT_VAL(val, bit) ? mask : 0)
280
281/** Port status request handler.
282 * @param device Virtual hub device
283 * @param setup_packet USB setup stage data.
284 * @param[out] data destination data buffer, size must be at least
285 * setup_packet->length bytes
286 * @param[out] act_size Sized of the valid response part of the buffer.
287 * @return Error code.
288 */
289static errno_t req_get_port_status(usbvirt_device_t *device,
290 const usb_device_request_setup_packet_t *setup_packet,
291 uint8_t *data, size_t *act_size)
292{
293 ehci_rh_t *hub;
294 unsigned port;
295 TEST_SIZE_INIT(4, port, hub);
296 if (setup_packet->value != 0)
297 return EINVAL;
298
299 const uint32_t reg = EHCI_RD(hub->registers->portsc[port]);
300 const uint32_t status = uint32_host2usb(
301 EHCI2USB(reg, USB_PORTSC_CONNECT_FLAG, USB_HUB_PORT_STATUS_CONNECTION) |
302 EHCI2USB(reg, USB_PORTSC_ENABLED_FLAG, USB_HUB_PORT_STATUS_ENABLE) |
303 EHCI2USB(reg, USB_PORTSC_SUSPEND_FLAG, USB2_HUB_PORT_STATUS_SUSPEND) |
304 EHCI2USB(reg, USB_PORTSC_OC_ACTIVE_FLAG, USB_HUB_PORT_STATUS_OC) |
305 EHCI2USB(reg, USB_PORTSC_PORT_RESET_FLAG, USB_HUB_PORT_STATUS_RESET) |
306 EHCI2USB(reg, USB_PORTSC_PORT_POWER_FLAG, USB2_HUB_PORT_STATUS_POWER) |
307 (((reg & USB_PORTSC_LINE_STATUS_MASK) == USB_PORTSC_LINE_STATUS_K) ?
308 (USB2_HUB_PORT_STATUS_LOW_SPEED) : 0) |
309 ((reg & USB_PORTSC_PORT_OWNER_FLAG) ? 0 : USB2_HUB_PORT_STATUS_HIGH_SPEED) |
310 EHCI2USB(reg, USB_PORTSC_PORT_TEST_MASK, USB2_HUB_PORT_STATUS_TEST) |
311 EHCI2USB(reg, USB_PORTSC_INDICATOR_MASK, USB2_HUB_PORT_STATUS_INDICATOR) |
312 EHCI2USB(reg, USB_PORTSC_CONNECT_CH_FLAG, USB_HUB_PORT_STATUS_C_CONNECTION) |
313 EHCI2USB(reg, USB_PORTSC_EN_CHANGE_FLAG, USB2_HUB_PORT_STATUS_C_ENABLE) |
314 (hub->resume_flag[port] ? USB2_HUB_PORT_STATUS_C_SUSPEND : 0) |
315 EHCI2USB(reg, USB_PORTSC_OC_CHANGE_FLAG, USB_HUB_PORT_STATUS_C_OC) |
316 (hub->reset_flag[port] ? USB_HUB_PORT_STATUS_C_RESET : 0));
317 /*
318 * Note feature numbers for test and indicator feature do not
319 * correspond to the port status bit locations
320 */
321 usb_log_debug2("RH(%p-%u) port status: %" PRIx32 "(%" PRIx32 ")", hub, port,
322 status, reg);
323 memcpy(data, &status, sizeof(status));
324 *act_size = sizeof(status);
325 return EOK;
326}
327
328typedef struct {
329 ehci_rh_t *hub;
330 unsigned port;
331} ehci_rh_job_t;
332
333static errno_t stop_reset(void *arg)
334{
335 ehci_rh_job_t *job = arg;
336 fibril_usleep(50000);
337 usb_log_debug("RH(%p-%u): Clearing reset", job->hub, job->port);
338 EHCI_CLR(job->hub->registers->portsc[job->port],
339 USB_PORTSC_PORT_RESET_FLAG);
340 /* wait for reset to complete */
341 while (EHCI_RD(job->hub->registers->portsc[job->port]) &
342 USB_PORTSC_PORT_RESET_FLAG) {
343 fibril_usleep(1);
344 }
345 usb_log_debug("RH(%p-%u): Reset complete", job->hub, job->port);
346 /*
347 * Handle port ownership, if the port is not enabled
348 * after reset it's a full speed device
349 */
350 if (!(EHCI_RD(job->hub->registers->portsc[job->port]) &
351 USB_PORTSC_ENABLED_FLAG)) {
352 usb_log_info("RH(%p-%u): Port not enabled after reset (%" PRIX32
353 "), giving up ownership", job->hub, job->port,
354 EHCI_RD(job->hub->registers->portsc[job->port]));
355 EHCI_SET(job->hub->registers->portsc[job->port],
356 USB_PORTSC_PORT_OWNER_FLAG);
357 }
358 job->hub->reset_flag[job->port] = true;
359 ehci_rh_interrupt(job->hub);
360 free(job);
361 return 0;
362}
363
364static errno_t stop_resume(void *arg)
365{
366 ehci_rh_job_t *job = arg;
367 fibril_usleep(20000);
368 usb_log_debug("RH(%p-%u): Stopping resume", job->hub, job->port);
369 EHCI_CLR(job->hub->registers->portsc[job->port],
370 USB_PORTSC_RESUME_FLAG);
371 job->hub->resume_flag[job->port] = true;
372 ehci_rh_interrupt(job->hub);
373 free(job);
374 return 0;
375}
376
377static errno_t delayed_job(errno_t (*func)(void *), ehci_rh_t *rh, unsigned port)
378{
379 ehci_rh_job_t *job = malloc(sizeof(*job));
380 if (!job)
381 return ENOMEM;
382 job->hub = rh;
383 job->port = port;
384 fid_t fib = fibril_create(func, job);
385 if (!fib) {
386 free(job);
387 return ENOMEM;
388 }
389 fibril_add_ready(fib);
390 usb_log_debug2("RH(%p-%u): Scheduled delayed stop job.", rh, port);
391 return EOK;
392}
393
394
395/** Port clear feature request handler.
396 * @param device Virtual hub device
397 * @param setup_packet USB setup stage data.
398 * @param[out] data destination data buffer, size must be at least
399 * setup_packet->length bytes
400 * @param[out] act_size Sized of the valid response part of the buffer.
401 * @return Error code.
402 */
403static errno_t req_clear_port_feature(usbvirt_device_t *device,
404 const usb_device_request_setup_packet_t *setup_packet,
405 uint8_t *data, size_t *act_size)
406{
407 ehci_rh_t *hub;
408 unsigned port;
409 TEST_SIZE_INIT(0, port, hub);
410 const unsigned feature = uint16_usb2host(setup_packet->value);
411 /* Enabled features to clear: see page 269 of USB specs */
412 switch (feature) {
413 case USB_HUB_FEATURE_PORT_POWER: /*8*/
414 usb_log_debug2("RH(%p-%u): Clear port power.", hub, port);
415 EHCI_CLR(hub->registers->portsc[port],
416 USB_PORTSC_PORT_POWER_FLAG);
417 return EOK;
418
419 case USB2_HUB_FEATURE_PORT_ENABLE: /*1*/
420 usb_log_debug2("RH(%p-%u): Clear port enable.", hub, port);
421 EHCI_CLR(hub->registers->portsc[port],
422 USB_PORTSC_ENABLED_FLAG);
423 return EOK;
424
425 case USB2_HUB_FEATURE_PORT_SUSPEND: /*2*/
426 usb_log_debug2("RH(%p-%u): Clear port suspend.", hub, port);
427 /* If not in suspend it's noop */
428 if ((EHCI_RD(hub->registers->portsc[port]) &
429 USB_PORTSC_SUSPEND_FLAG) == 0)
430 return EOK;
431 /* Host driven resume */
432 EHCI_SET(hub->registers->portsc[port],
433 USB_PORTSC_RESUME_FLAG);
434 //TODO: What if creating the delayed job fails?
435 return delayed_job(stop_resume, hub, port);
436
437 case USB_HUB_FEATURE_C_PORT_CONNECTION: /*16*/
438 usb_log_debug2("RH(%p-%u): Clear port connection change.",
439 hub, port);
440 EHCI_SET(hub->registers->portsc[port],
441 USB_PORTSC_CONNECT_CH_FLAG);
442 return EOK;
443 case USB2_HUB_FEATURE_C_PORT_ENABLE: /*17*/
444 usb_log_debug2("RH(%p-%u): Clear port enable change.",
445 hub, port);
446 EHCI_SET(hub->registers->portsc[port],
447 USB_PORTSC_CONNECT_CH_FLAG);
448 return EOK;
449 case USB_HUB_FEATURE_C_PORT_OVER_CURRENT: /*19*/
450 usb_log_debug2("RH(%p-%u): Clear port OC change.",
451 hub, port);
452 EHCI_SET(hub->registers->portsc[port],
453 USB_PORTSC_OC_CHANGE_FLAG);
454 return EOK;
455 case USB2_HUB_FEATURE_C_PORT_SUSPEND: /*18*/
456 usb_log_debug2("RH(%p-%u): Clear port suspend change.",
457 hub, port);
458 hub->resume_flag[port] = false;
459 return EOK;
460 case USB_HUB_FEATURE_C_PORT_RESET: /*20*/
461 usb_log_debug2("RH(%p-%u): Clear port reset change.",
462 hub, port);
463 hub->reset_flag[port] = false;
464 return EOK;
465
466 default:
467 usb_log_warning("RH(%p-%u): Clear unknown feature: %u",
468 hub, port, feature);
469 return ENOTSUP;
470 }
471}
472
473/** Port set feature request handler.
474 * @param device Virtual hub device
475 * @param setup_packet USB setup stage data.
476 * @param[out] data destination data buffer, size must be at least
477 * setup_packet->length bytes
478 * @param[out] act_size Sized of the valid response part of the buffer.
479 * @return Error code.
480 */
481static errno_t req_set_port_feature(usbvirt_device_t *device,
482 const usb_device_request_setup_packet_t *setup_packet,
483 uint8_t *data, size_t *act_size)
484{
485 ehci_rh_t *hub;
486 unsigned port;
487 TEST_SIZE_INIT(0, port, hub);
488 const unsigned feature = uint16_usb2host(setup_packet->value);
489 switch (feature) {
490 case USB2_HUB_FEATURE_PORT_ENABLE: /*1*/
491 usb_log_debug2("RH(%p-%u): Set port enable.", hub, port);
492 EHCI_SET(hub->registers->portsc[port],
493 USB_PORTSC_ENABLED_FLAG);
494 return EOK;
495 case USB2_HUB_FEATURE_PORT_SUSPEND: /*2*/
496 usb_log_debug2("RH(%p-%u): Set port suspend.", hub, port);
497 EHCI_SET(hub->registers->portsc[port],
498 USB_PORTSC_SUSPEND_FLAG);
499 return EOK;
500 case USB_HUB_FEATURE_PORT_RESET: /*4*/
501 usb_log_debug2("RH(%p-%u): Set port reset.", hub, port);
502 EHCI_SET(hub->registers->portsc[port],
503 USB_PORTSC_PORT_RESET_FLAG);
504 //TODO: What if creating the delayed job fails?
505 return delayed_job(stop_reset, hub, port);
506 case USB_HUB_FEATURE_PORT_POWER: /*8*/
507 usb_log_debug2("RH(%p-%u): Set port power.", hub, port);
508 EHCI_SET(hub->registers->portsc[port],
509 USB_PORTSC_PORT_POWER_FLAG);
510 return EOK;
511 default:
512 usb_log_warning("RH(%p-%u): Set unknown feature: %u",
513 hub, port, feature);
514 return ENOTSUP;
515 }
516}
517
518/** Status change handler.
519 * @param device Virtual hub device
520 * @param endpoint Endpoint number
521 * @param tr_type Transfer type
522 * @param buffer Response destination
523 * @param buffer_size Bytes available in buffer
524 * @param actual_size Size us the used part of the dest buffer.
525 *
526 * Produces status mask. Bit 0 indicates hub status change the other bits
527 * represent port status change. Endian does not matter as UHCI root hubs
528 * only need 1 byte.
529 */
530static errno_t req_status_change_handler(usbvirt_device_t *device,
531 usb_endpoint_t endpoint, usb_transfer_type_t tr_type,
532 void *buffer, size_t buffer_size, size_t *actual_size)
533{
534 ehci_rh_t *hub = virthub_get_data(device);
535 assert(hub);
536
537 if (buffer_size < STATUS_BYTES(hub->port_count))
538 return ESTALL;
539
540 uint16_t mask = 0;
541 for (unsigned port = 0; port < hub->port_count; ++port) {
542 /* Write-clean bits are those that indicate change */
543 uint32_t status = EHCI_RD(hub->registers->portsc[port]);
544 if ((status & USB_PORTSC_WC_MASK) || hub->reset_flag[port]) {
545 /* Ignore new LS device */
546 if ((status & USB_PORTSC_CONNECT_CH_FLAG) &&
547 (status & USB_PORTSC_LINE_STATUS_MASK) ==
548 USB_PORTSC_LINE_STATUS_K)
549 EHCI_SET(hub->registers->portsc[port],
550 USB_PORTSC_PORT_OWNER_FLAG);
551 else
552 mask |= (2 << port);
553 }
554 }
555
556 usb_log_debug2("RH(%p): root hub interrupt mask: %" PRIx16, hub, mask);
557
558 if (mask == 0)
559 return ENAK;
560 mask = uint16_host2usb(mask);
561 memcpy(buffer, &mask, STATUS_BYTES(hub->port_count));
562 *actual_size = STATUS_BYTES(hub->port_count);
563 return EOK;
564}
565
566/** EHCI root hub request handlers */
567static const usbvirt_control_request_handler_t control_transfer_handlers[] = {
568 {
569 STD_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
570 .name = "GetDescriptor",
571 .callback = virthub_base_get_hub_descriptor,
572 },
573 {
574 CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
575 .name = "GetDescriptor",
576 .callback = virthub_base_get_hub_descriptor,
577 },
578 {
579 CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_GET_DESCRIPTOR),
580 .name = "GetHubDescriptor",
581 .callback = virthub_base_get_hub_descriptor,
582 },
583 {
584 CLASS_REQ_IN(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_GET_STATUS),
585 .name = "GetPortStatus",
586 .callback = req_get_port_status,
587 },
588 {
589 CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_CLEAR_FEATURE),
590 .name = "ClearHubFeature",
591 .callback = req_clear_hub_feature,
592 },
593 {
594 CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_CLEAR_FEATURE),
595 .name = "ClearPortFeature",
596 .callback = req_clear_port_feature,
597 },
598 {
599 CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_GET_STATUS),
600 .name = "GetHubStatus",
601 .callback = req_get_status,
602 },
603 {
604 CLASS_REQ_IN(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_GET_STATUS),
605 .name = "GetPortStatus",
606 .callback = req_get_port_status,
607 },
608 {
609 CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_SET_FEATURE),
610 .name = "SetHubFeature",
611 .callback = req_nop,
612 },
613 {
614 CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_SET_FEATURE),
615 .name = "SetPortFeature",
616 .callback = req_set_port_feature,
617 },
618 {
619 .callback = NULL
620 }
621};
622
623/** Virtual EHCI root hub ops */
624static usbvirt_device_ops_t ops = {
625 .control = control_transfer_handlers,
626 .data_in[HUB_STATUS_CHANGE_PIPE] = req_status_change_handler,
627};
Note: See TracBrowser for help on using the repository browser.