#![allow(clippy::new_without_default)]
#![no_std]

extern crate alloc;

pub mod error;
pub mod queue;
pub mod transport;

use bitflags::bitflags;
use tock_registers::{
    register_structs,
    registers::{ReadOnly, ReadWrite},
};

register_structs! {
    pub CommonConfiguration {
        (0x00 => device_feature_select: ReadWrite<u32>),
        (0x04 => device_feature: ReadOnly<u32>),
        (0x08 => driver_feature_select: ReadWrite<u32>),
        (0x0C => driver_feature: ReadWrite<u32>),
        (0x10 => msix_config: ReadWrite<u16>),
        (0x12 => num_queues: ReadOnly<u16>),
        (0x14 => device_status: ReadWrite<u8>),
        (0x15 => config_generation: ReadOnly<u8>),

        (0x16 => queue_select: ReadWrite<u16>),
        (0x18 => queue_size: ReadWrite<u16>),
        (0x1A => queue_msix_vector: ReadWrite<u16>),
        (0x1C => queue_enable: ReadWrite<u16>),
        (0x1E => queue_notify_off: ReadWrite<u16>),
        (0x20 => queue_desc: ReadWrite<u64>),
        (0x28 => queue_driver: ReadWrite<u64>),
        (0x30 => queue_device: ReadWrite<u64>),

        (0x38 => @END),
    }
}

bitflags! {
    #[derive(Clone, Copy)]
    pub struct DeviceStatus: u8 {
        const ACKNOWLEDGE = 1 << 0;
        const DRIVER = 1 << 1;
        const DRIVER_OK = 1 << 2;
        const FEATURES_OK = 1 << 3;
        const DEVICE_NEEDS_RESET = 1 << 6;
        const FAILED = 1 << 7;
    }
}

impl DeviceStatus {
    pub const RESET_VALUE: Self = Self::empty();
}
