Skip to content

Device Structure

struct device_physical_location {
    enum device_physical_location_panel     panel;
    enum device_physical_location_vertical_position vertical_position;
    enum device_physical_location_horizontal_position horizontal_position;
    bool                                    dock;
    bool                                    lid;
};
struct device_driver {
    const char            *name;
    enum device_bus_type  bus;
    enum errno            (*probe)(struct device *dev);
    void                  (*remove)(struct device *dev);
    enum errno            (*suspend)(struct device *dev, enum device_power_state target);
    enum errno            (*resume)(struct device *dev);
};
struct device_resource {
    enum device_resource_type  type;
    uint64_t                   start;
    uint64_t                   size;
    uint32_t                   flags;
};
struct device_ops {
    void  (*print)(struct device *);
};
struct device {
    const char                       *name;
    uint32_t                         id;
    enum device_type                 type;
    enum device_bus_type             bus;
    struct device                    *parent;
    struct list_head                 children;
    struct rbt_node                  tree_node;
    struct list_head                 list_node;
    struct device_ops                *ops;
    struct device_driver             *driver;
    void                             *driver_data;
    enum device_state                state;
    enum device_power_state          power;
    enum device_flags                flags;
    refcount_t                       refcount;
    struct device_resource           resources[DEVICE_MAX_RESOURCES];
    uint8_t                          resource_count;
    numa_node_t                      numa_node;
    struct device_physical_location  location;
    struct iommu_domain              *iommu_domain;
    struct mutex                     mutex;
    struct spinlock                  lock;
    void                             *private;
};
enum device_physical_location_panel {
    DEVICE_PANEL_TOP,
    DEVICE_PANEL_BOTTOM,
    DEVICE_PANEL_LEFT,
    DEVICE_PANEL_RIGHT,
    DEVICE_PANEL_FRONT,
    DEVICE_PANEL_BACK,
    DEVICE_PANEL_UNKNOWN,
};

device_physical_location_vertical_position

Section titled “device_physical_location_vertical_position”
enum device_physical_location_vertical_position {
    DEVICE_VERT_POS_UPPER,
    DEVICE_VERT_POS_CENTER,
    DEVICE_VERT_POS_LOWER,
};

device_physical_location_horizontal_position

Section titled “device_physical_location_horizontal_position”
enum device_physical_location_horizontal_position {
    DEVICE_HORI_POS_LEFT,
    DEVICE_HORI_POS_CENTER,
    DEVICE_HORI_POS_RIGHT,
};
enum device_bus_type {
    DEVICE_BUS_TYPE_PLATFORM,
    DEVICE_BUS_TYPE_PCI,
    DEVICE_BUS_TYPE_USB,
    DEVICE_BUS_TYPE_I2C,
    DEVICE_BUS_TYPE_SPI,
    DEVICE_BUS_TYPE_VIRTIO,
    DEVICE_BUS_TYPE_ACPI,
};
enum device_type {
    DEVICE_TYPE_UNKNOWN,
    DEVICE_TYPE_BLOCK,
    DEVICE_TYPE_CHAR,
    DEVICE_TYPE_NET,
    DEVICE_TYPE_INPUT,
    DEVICE_TYPE_DISPLAY,
    DEVICE_TYPE_AUDIO,
    DEVICE_TYPE_SERIAL,
    DEVICE_TYPE_GPU,
    DEVICE_TYPE_TIMER,
    DEVICE_TYPE_BUS,
};
enum device_power_state {
    DEVICE_POWER_D0,
    DEVICE_POWER_D1,
    DEVICE_POWER_D2,
    DEVICE_POWER_D3_HOT,
    DEVICE_POWER_D3_COLD,
    DEVICE_POWER_REMOVED,
};
enum device_state {
    DEVICE_STATE_UNBOUND,
    DEVICE_STATE_PROBING,
    DEVICE_STATE_BOUND,
    DEVICE_STATE_SUSPENDED,
    DEVICE_STATE_REMOVING,
    DEVICE_STATE_REMOVED,
    DEVICE_STATE_ERROR,
};
enum device_flags {
    DEVICE_FLAG_HOTPLUG = (1u << 0),
    DEVICE_FLAG_DMA = (1u << 1),
    DEVICE_FLAG_MMIO = (1u << 2),
    DEVICE_FLAG_PIO = (1u << 3),
    DEVICE_FLAG_MSI = (1u << 4),
    DEVICE_FLAG_VIRTUAL = (1u << 5),
    DEVICE_FLAG_REMOVABLE = (1u << 6),
    DEVICE_FLAG_WAKEUP = (1u << 7),
};
enum device_resource_type {
    DEVICE_RESOURCE_MEM,
    DEVICE_RESOURCE_IO,
    DEVICE_RESOURCE_IRQ,
    DEVICE_RESOURCE_DMA,
};
void device_init(struct device *dev);
#define DEVICE_MAX_RESOURCES 8