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

Last change on this file since 99013b84 was 3bacee1, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Make ccheck-fix again and commit more good files.

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