1 // Copyright 2019 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 use super::xhci_transfer::XhciTransfer;
6 use crate::usb::host_backend::error::Result;
7 
8 /// Address of this usb device, as in Set Address standard usb device request.
9 pub type UsbDeviceAddress = u32;
10 
11 /// The type USB device provided by the backend device.
12 #[derive(PartialEq, Eq)]
13 pub enum BackendType {
14     Usb2,
15     Usb3,
16 }
17 
18 /// Xhci backend device is a virtual device connected to xHCI controller. It handles xhci transfers.
19 pub trait XhciBackendDevice: Send {
20     /// Returns the type of USB device provided by this device.
get_backend_type(&self) -> BackendType21     fn get_backend_type(&self) -> BackendType;
22     /// Get vendor id of this device.
get_vid(&self) -> u1623     fn get_vid(&self) -> u16;
24     /// Get product id of this device.
get_pid(&self) -> u1625     fn get_pid(&self) -> u16;
26     /// Submit a xhci transfer to backend.
submit_transfer(&mut self, transfer: XhciTransfer) -> Result<()>27     fn submit_transfer(&mut self, transfer: XhciTransfer) -> Result<()>;
28     /// Set address of this backend.
set_address(&mut self, address: UsbDeviceAddress)29     fn set_address(&mut self, address: UsbDeviceAddress);
30     /// Reset the backend device.
reset(&mut self) -> Result<()>31     fn reset(&mut self) -> Result<()>;
32 }
33