static int vtd_dev_to_context_entry(IntelIOMMUState *s, uint8_t bus_num,

                                    uint8_t devfn, VTDContextEntry *ce)

{

    VTDRootEntry re;

    int ret_fr;

    X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(s);



    ret_fr = vtd_get_root_entry(s, bus_num, &re);

    if (ret_fr) {

        return ret_fr;

    }



    if (!vtd_root_entry_present(&re)) {

        /* Not error - it's okay we don't have root entry. */

        trace_vtd_re_not_present(bus_num);

        return -VTD_FR_ROOT_ENTRY_P;

    }



    if (re.rsvd || (re.val & VTD_ROOT_ENTRY_RSVD(VTD_HOST_ADDRESS_WIDTH))) {

        trace_vtd_re_invalid(re.rsvd, re.val);

        return -VTD_FR_ROOT_ENTRY_RSVD;

    }



    ret_fr = vtd_get_context_entry_from_root(&re, devfn, ce);

    if (ret_fr) {

        return ret_fr;

    }



    if (!vtd_ce_present(ce)) {

        /* Not error - it's okay we don't have context entry. */

        trace_vtd_ce_not_present(bus_num, devfn);

        return -VTD_FR_CONTEXT_ENTRY_P;

    }



    if ((ce->hi & VTD_CONTEXT_ENTRY_RSVD_HI) ||

               (ce->lo & VTD_CONTEXT_ENTRY_RSVD_LO(VTD_HOST_ADDRESS_WIDTH))) {

        trace_vtd_ce_invalid(ce->hi, ce->lo);

        return -VTD_FR_CONTEXT_ENTRY_RSVD;

    }



    /* Check if the programming of context-entry is valid */

    if (!vtd_is_level_supported(s, vtd_ce_get_level(ce))) {

        trace_vtd_ce_invalid(ce->hi, ce->lo);

        return -VTD_FR_CONTEXT_ENTRY_INV;

    }



    /* Do translation type check */

    if (!vtd_ce_type_check(x86_iommu, ce)) {

        trace_vtd_ce_invalid(ce->hi, ce->lo);

        return -VTD_FR_CONTEXT_ENTRY_INV;

    }



    return 0;

}

static int vtd_dev_to_context_entry(IntelIOMMUState *s, uint8_t bus_num,

                                    uint8_t devfn, VTDContextEntry *ce)

{

    VTDRootEntry re;

    int ret_fr;

    X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(s);



    ret_fr = vtd_get_root_entry(s, bus_num, &re);

    if (ret_fr) {

        return ret_fr;

    }



    if (!vtd_root_entry_present(&re)) {

        

        trace_vtd_re_not_present(bus_num);

        return -VTD_FR_ROOT_ENTRY_P;

    }



    if (re.rsvd || (re.val & VTD_ROOT_ENTRY_RSVD(VTD_HOST_ADDRESS_WIDTH))) {

        trace_vtd_re_invalid(re.rsvd, re.val);

        return -VTD_FR_ROOT_ENTRY_RSVD;

    }



    ret_fr = vtd_get_context_entry_from_root(&re, devfn, ce);

    if (ret_fr) {

        return ret_fr;

    }



    if (!vtd_ce_present(ce)) {

        

        trace_vtd_ce_not_present(bus_num, devfn);

        return -VTD_FR_CONTEXT_ENTRY_P;

    }



    if ((ce->hi & VTD_CONTEXT_ENTRY_RSVD_HI) ||

               (ce->lo & VTD_CONTEXT_ENTRY_RSVD_LO(VTD_HOST_ADDRESS_WIDTH))) {

        trace_vtd_ce_invalid(ce->hi, ce->lo);

        return -VTD_FR_CONTEXT_ENTRY_RSVD;

    }



    

    if (!vtd_is_level_supported(s, vtd_ce_get_level(ce))) {

        trace_vtd_ce_invalid(ce->hi, ce->lo);

        return -VTD_FR_CONTEXT_ENTRY_INV;

    }



    

    if (!vtd_ce_type_check(x86_iommu, ce)) {

        trace_vtd_ce_invalid(ce->hi, ce->lo);

        return -VTD_FR_CONTEXT_ENTRY_INV;

    }



    return 0;

}

static int FUNC_0(IntelIOMMUState *VAR_0, uint8_t VAR_1,

                                    uint8_t VAR_2, VTDContextEntry *VAR_3)

{

    VTDRootEntry re;

    int VAR_4;

    X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(VAR_0);



    VAR_4 = vtd_get_root_entry(VAR_0, VAR_1, &re);

    if (VAR_4) {

        return VAR_4;

    }



    if (!vtd_root_entry_present(&re)) {

        

        trace_vtd_re_not_present(VAR_1);

        return -VTD_FR_ROOT_ENTRY_P;

    }



    if (re.rsvd || (re.val & VTD_ROOT_ENTRY_RSVD(VTD_HOST_ADDRESS_WIDTH))) {

        trace_vtd_re_invalid(re.rsvd, re.val);

        return -VTD_FR_ROOT_ENTRY_RSVD;

    }



    VAR_4 = vtd_get_context_entry_from_root(&re, VAR_2, VAR_3);

    if (VAR_4) {

        return VAR_4;

    }



    if (!vtd_ce_present(VAR_3)) {

        

        trace_vtd_ce_not_present(VAR_1, VAR_2);

        return -VTD_FR_CONTEXT_ENTRY_P;

    }



    if ((VAR_3->hi & VTD_CONTEXT_ENTRY_RSVD_HI) ||

               (VAR_3->lo & VTD_CONTEXT_ENTRY_RSVD_LO(VTD_HOST_ADDRESS_WIDTH))) {

        trace_vtd_ce_invalid(VAR_3->hi, VAR_3->lo);

        return -VTD_FR_CONTEXT_ENTRY_RSVD;

    }



    

    if (!vtd_is_level_supported(VAR_0, vtd_ce_get_level(VAR_3))) {

        trace_vtd_ce_invalid(VAR_3->hi, VAR_3->lo);

        return -VTD_FR_CONTEXT_ENTRY_INV;

    }



    

    if (!vtd_ce_type_check(x86_iommu, VAR_3)) {

        trace_vtd_ce_invalid(VAR_3->hi, VAR_3->lo);

        return -VTD_FR_CONTEXT_ENTRY_INV;

    }



    return 0;

}

static int FUNC_0(IntelIOMMUState *VAR_0, uint8_t VAR_1,
uint8_t VAR_2, VTDContextEntry *VAR_3)
{ VTDRootEntry re; int VAR_4; X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(VAR_0); VAR_4 = vtd_get_root_entry(VAR_0, VAR_1, &re); if (VAR_4) { return VAR_4; } if (!vtd_root_entry_present(&re)) { trace_vtd_re_not_present(VAR_1); return -VTD_FR_ROOT_ENTRY_P; } if (re.rsvd || (re.val & VTD_ROOT_ENTRY_RSVD(VTD_HOST_ADDRESS_WIDTH))) { trace_vtd_re_invalid(re.rsvd, re.val); return -VTD_FR_ROOT_ENTRY_RSVD; } VAR_4 = vtd_get_context_entry_from_root(&re, VAR_2, VAR_3); if (VAR_4) { return VAR_4; } if (!vtd_ce_present(VAR_3)) { trace_vtd_ce_not_present(VAR_1, VAR_2); return -VTD_FR_CONTEXT_ENTRY_P; } if ((VAR_3->hi & VTD_CONTEXT_ENTRY_RSVD_HI) ||
(VAR_3->lo & VTD_CONTEXT_ENTRY_RSVD_LO(VTD_HOST_ADDRESS_WIDTH))) { trace_vtd_ce_invalid(VAR_3->hi, VAR_3->lo); return -VTD_FR_CONTEXT_ENTRY_RSVD; } if (!vtd_is_level_supported(VAR_0, vtd_ce_get_level(VAR_3))) { trace_vtd_ce_invalid(VAR_3->hi, VAR_3->lo); return -VTD_FR_CONTEXT_ENTRY_INV; } if (!vtd_ce_type_check(x86_iommu, VAR_3)) { trace_vtd_ce_invalid(VAR_3->hi, VAR_3->lo); return -VTD_FR_CONTEXT_ENTRY_INV; } return 0; }