1 // Copyright 2019 The ChromiumOS Authors 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 usb_util::DeviceSpeed; 6 7 use crate::usb::backend::error::Result; 8 9 /// Address of this usb device, as in Set Address standard usb device request. 10 pub type UsbDeviceAddress = u32; 11 12 /// The type USB device provided by the backend device. 13 #[derive(PartialEq, Eq)] 14 pub enum BackendType { 15 Usb2, 16 Usb3, 17 } 18 19 /// Xhci backend device is a virtual device connected to xHCI controller. It handles xhci transfers. 20 pub trait XhciBackendDevice: Send + Sync { 21 /// Returns the type of USB device provided by this device. get_backend_type(&self) -> BackendType22 fn get_backend_type(&self) -> BackendType; 23 /// Get vendor id of this device. get_vid(&self) -> u1624 fn get_vid(&self) -> u16; 25 /// Get product id of this device. get_pid(&self) -> u1626 fn get_pid(&self) -> u16; 27 /// Set address of this backend. set_address(&mut self, address: UsbDeviceAddress)28 fn set_address(&mut self, address: UsbDeviceAddress); 29 /// Reset the backend device. reset(&mut self) -> Result<()>30 fn reset(&mut self) -> Result<()>; 31 /// Get speed of this device. get_speed(&self) -> Option<DeviceSpeed>32 fn get_speed(&self) -> Option<DeviceSpeed>; 33 /// Allocate streams for the endpoint alloc_streams(&self, ep: u8, num_streams: u16) -> Result<()>34 fn alloc_streams(&self, ep: u8, num_streams: u16) -> Result<()>; 35 /// Free streams for the endpoint free_streams(&self, ep: u8) -> Result<()>36 fn free_streams(&self, ep: u8) -> Result<()>; 37 /// Stop the backend device, allowing it to execute cleanup routines. stop(&mut self)38 fn stop(&mut self); 39 } 40