#!/bin/bash

source ./kernel_config_utils.sh

dpdk_check() {
    local arch="$(uname -m)"
    local is_error

    is_error="false"
    if [  "$(kernel_version_cmp "$KERNEL_VERSION" "v4.19")" -lt "0" ]; then
        echo "DPDK need kernel version '$KERNEL_VERSION' >= 'v4.19'"
        return 1
    fi
    if ! kernel_config_check CONFIG_CPU_FREQ cpufreq; then
        is_error="true"
    fi
    if ! kernel_config_check CONFIG_HUGETLBFS; then
        is_error="true"
    fi
    if ! kernel_config_check CONFIG_IOMMU_API; then
        is_error="true"
    fi
    if ! kernel_config_check CONFIG_MMU; then
        is_error="true"
    fi
    if [ "$arch" == "riscv64" ]; then
        if ! kernel_config_check CONFIG_OF; then
            is_error="true"
        fi
    fi
    if ! kernel_config_check CONFIG_PM; then
        is_error="true"
    fi
    if ! kernel_config_check CONFIG_VHOST vhost; then
        is_error="true"
    fi
    if ! kernel_config_check CONFIG_VHOST_MENU; then
        is_error="true"
    fi
    if ! kernel_config_check CONFIG_VHOST_NET vhost_net; then
        is_error="true"
    fi

    if ! kernel_config_check CONFIG_PROC_PAGE_MONITOR; then
        is_error="true"
    fi
    if ! kernel_config_check CONFIG_UIO uio; then
        is_error="true"
    fi
    if ! kernel_config_check CONFIG_UIO_PCI_GENERIC uio_pci_generic; then
        is_error="true"
    fi
    if ! kernel_config_check CONFIG_VFIO vfio; then
        is_error="true"
    fi
    if ! kernel_config_check CONFIG_VFIO_NOIOMMU; then
        is_error="true"
    fi
    if ! kernel_config_check CONFIG_VFIO_PCI vfio_pci; then
        is_error="true"
    fi
    if [ "$is_error" == "true" ]; then
        return 1
    fi

    return 0
}

