2021-02-27 01:10:37 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
|
#include <AK/Types.h>
|
2022-04-11 07:18:31 -03:00
|
|
|
#include <AK/Vector.h>
|
|
|
|
|
#include <Kernel/Bus/USB/USBConfiguration.h>
|
2021-06-25 03:51:22 -03:00
|
|
|
#include <Kernel/Bus/USB/USBPipe.h>
|
2021-02-27 01:10:37 -03:00
|
|
|
|
2022-04-23 03:45:31 -03:00
|
|
|
namespace Kernel {
|
|
|
|
|
class SysFSUSBDeviceInformation;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 01:10:37 -03:00
|
|
|
namespace Kernel::USB {
|
|
|
|
|
|
2021-08-08 15:50:20 -03:00
|
|
|
class USBController;
|
2022-04-11 07:18:31 -03:00
|
|
|
class USBConfiguration;
|
2021-08-08 15:50:20 -03:00
|
|
|
|
2021-02-27 01:10:37 -03:00
|
|
|
//
|
|
|
|
|
// Some nice info from FTDI on device enumeration and how some of this
|
|
|
|
|
// glues together:
|
|
|
|
|
//
|
|
|
|
|
// https://www.ftdichip.com/Support/Documents/TechnicalNotes/TN_113_Simplified%20Description%20of%20USB%20Device%20Enumeration.pdf
|
2022-04-23 03:45:31 -03:00
|
|
|
class Hub;
|
2022-08-19 12:26:07 -03:00
|
|
|
class Device : public AtomicRefCounted<Device> {
|
2021-02-27 01:10:37 -03:00
|
|
|
public:
|
|
|
|
|
enum class DeviceSpeed : u8 {
|
|
|
|
|
FullSpeed = 0,
|
|
|
|
|
LowSpeed
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-19 15:53:40 -03:00
|
|
|
static ErrorOr<NonnullLockRefPtr<Device>> try_create(USBController const&, u8, DeviceSpeed);
|
2021-02-27 01:10:37 -03:00
|
|
|
|
2021-08-13 20:20:53 -03:00
|
|
|
Device(USBController const&, u8, DeviceSpeed, NonnullOwnPtr<Pipe> default_pipe);
|
2021-08-13 16:47:13 -03:00
|
|
|
Device(Device const& device, NonnullOwnPtr<Pipe> default_pipe);
|
|
|
|
|
virtual ~Device();
|
2021-02-27 01:10:37 -03:00
|
|
|
|
2021-11-07 20:51:39 -03:00
|
|
|
ErrorOr<void> enumerate_device();
|
2021-02-27 01:10:37 -03:00
|
|
|
|
2021-08-13 20:20:53 -03:00
|
|
|
u8 port() const { return m_device_port; }
|
2021-02-27 01:10:37 -03:00
|
|
|
DeviceSpeed speed() const { return m_device_speed; }
|
|
|
|
|
|
|
|
|
|
u8 address() const { return m_address; }
|
|
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
USBDeviceDescriptor const& device_descriptor() const { return m_device_descriptor; }
|
2021-06-08 09:31:32 -03:00
|
|
|
|
2021-08-13 16:47:13 -03:00
|
|
|
USBController& controller() { return *m_controller; }
|
|
|
|
|
USBController const& controller() const { return *m_controller; }
|
|
|
|
|
|
2022-04-11 09:00:27 -03:00
|
|
|
ErrorOr<size_t> control_transfer(u8 request_type, u8 request, u16 value, u16 index, u16 length, void* data);
|
|
|
|
|
|
2022-05-24 11:24:49 -03:00
|
|
|
Vector<USBConfiguration> const& configurations() const { return m_configurations; }
|
|
|
|
|
|
2022-04-23 03:45:31 -03:00
|
|
|
SysFSUSBDeviceInformation& sysfs_device_info_node(Badge<USB::Hub>) { return *m_sysfs_device_info_node; }
|
|
|
|
|
|
2021-08-13 16:47:13 -03:00
|
|
|
protected:
|
2022-08-19 15:53:40 -03:00
|
|
|
Device(NonnullLockRefPtr<USBController> controller, u8 address, u8 port, DeviceSpeed speed, NonnullOwnPtr<Pipe> default_pipe);
|
2021-08-13 16:47:13 -03:00
|
|
|
|
2021-08-13 20:20:53 -03:00
|
|
|
u8 m_device_port { 0 }; // What port is this device attached to. NOTE: This is 1-based.
|
2021-02-27 01:10:37 -03:00
|
|
|
DeviceSpeed m_device_speed; // What speed is this device running at
|
|
|
|
|
u8 m_address { 0 }; // USB address assigned to this device
|
|
|
|
|
|
|
|
|
|
// Device description
|
2022-03-14 01:13:01 -03:00
|
|
|
u16 m_vendor_id { 0 }; // This device's vendor ID assigned by the USB group
|
|
|
|
|
u16 m_product_id { 0 }; // This device's product ID assigned by the USB group
|
|
|
|
|
USBDeviceDescriptor m_device_descriptor {}; // Device Descriptor obtained from USB Device
|
2022-04-11 07:18:31 -03:00
|
|
|
Vector<USBConfiguration> m_configurations; // Configurations for this device
|
2021-02-27 01:10:37 -03:00
|
|
|
|
2022-08-19 15:53:40 -03:00
|
|
|
NonnullLockRefPtr<USBController> m_controller;
|
2021-02-27 01:10:37 -03:00
|
|
|
NonnullOwnPtr<Pipe> m_default_pipe; // Default communication pipe (endpoint0) used during enumeration
|
2021-08-13 16:47:13 -03:00
|
|
|
|
|
|
|
|
private:
|
2022-08-19 15:53:40 -03:00
|
|
|
IntrusiveListNode<Device, NonnullLockRefPtr<Device>> m_hub_child_node;
|
2021-08-13 16:47:13 -03:00
|
|
|
|
2022-04-23 03:45:31 -03:00
|
|
|
protected:
|
2022-08-19 15:53:40 -03:00
|
|
|
LockRefPtr<SysFSUSBDeviceInformation> m_sysfs_device_info_node;
|
2022-04-23 03:45:31 -03:00
|
|
|
|
2021-08-13 16:47:13 -03:00
|
|
|
public:
|
2021-09-09 09:00:59 -03:00
|
|
|
using List = IntrusiveList<&Device::m_hub_child_node>;
|
2021-02-27 01:10:37 -03:00
|
|
|
};
|
|
|
|
|
}
|