<commit_before>/*
 * Copyright (c) 2018, ETH Zurich.
 * All rights reserved.
 *
 * This file is distributed under the terms in the attached LICENSE file.
 * If you do not find this file, copies can be found by writing to:
 * ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
 */

#ifndef INTEL_VTD_H_
#define INTEL_VTD_H_ 1

#include <dev/vtd_dev.h>

#include "intel_vtd_debug.h"

struct vtd;


extern vregion_flags_t vtd_table_map_attrs;


typedef uint16_t vtd_domid_t;


#define VTD_NUM_ROOT_ENTRIES	256

typedef enum {
    VTD_ENTRY_TYPE_BASE,
    VTD_ENTRY_TYPE_EXTENDED,
} vtd_entry_type_t;

struct vtd_root_table {
    struct capref   rtcap;
    struct capref   mappingcncap;
    struct cnoderef mappigncn;
};


struct vtd_ctxt_table {
    struct capref   ctcap;
    struct capref   mappingcncap;
    struct cnoderef mappigncn;
    uint8_t         rt_idx;
};

struct vtd_domain {
    vtd_domid_t                id;
    struct capref              ptroot;
    lpaddr_t                   ptroot_base;
    struct vtd_domain_mapping *devmappings;
};

struct vtd_domain_mapping {
    struct vtd_domain_mapping *next;
    struct vtd_domain_mapping *prev;
    struct vtd                *vtd;
    struct vtd_domain         *domain;
    struct capref              mappingcap;

    uint8_t             bus;
    uint8_t             idx;
};

#define vtd_ctxt_id_to_dev(idx) (idx >> 3)
#define vtd_ctxt_id_to_fun(idx) (idx & 0x7)
#define vtd_dev_fun_to_ctxt_id(dev, fun) ((dev << 3) | fun)


typedef enum {
    VTD_VERSION_INVALID = 0,
    VTD_VERSION_1_0     = 1,
    VTD_VERSION_MAX     = 2,
} vtd_version_t;

struct vtd {
    vtd_t                   vtd_dev;
<commit_msg>iommu: adding comments to the struct declarations of VT-d<commit_after>/*
 * Copyright (c) 2018, ETH Zurich.
 * All rights reserved.
 *
 * This file is distributed under the terms in the attached LICENSE file.
 * If you do not find this file, copies can be found by writing to:
 * ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
 */

#ifndef INTEL_VTD_H_
#define INTEL_VTD_H_ 1

#include <dev/vtd_dev.h>

#include "intel_vtd_debug.h"

struct vtd;


extern vregion_flags_t vtd_table_map_attrs;


typedef uint16_t vtd_domid_t;


/**
 * @brief the number of entries in the root table. this corresponds to the
 *        maximum possible number of PCI busses which is an 8-bit number,
 *        hence 256 entries
 */
#define VTD_NUM_ROOT_ENTRIES	256

/**
 * @brief the entry format of the root and context tables.
 *
 * There exist two different entry types. a base version and the extended
 * representation
 */
typedef enum {
    VTD_ENTRY_TYPE_BASE,
    VTD_ENTRY_TYPE_EXTENDED,
} vtd_entry_type_t;


/**
 * @brief structure to hold the software representation of the VT-d root table
 */
struct vtd_root_table {
    ///< capability of the root table
    struct capref   rtcap;

    ///< capability of the mapping cap CNODE
    struct capref   mappingcncap;

    ////< cnode reference of the mapping cap
    struct cnoderef mappigncn;

    ///< the VT-d unit this root tabel belongs
    struct vtd  *vtd;
    /*
     * TODO: currently we use one root table per VT-d unit. However, we might
     * share a single root table between multiple VT-d units, if applicable
     */
};

/**
 * @brief structure represent a VT-d context table
 *
 * each context table has one root table.
 */
struct vtd_ctxt_table {
    ///< capability of the context table
    struct capref           ctcap;

    ///< capability of the CNODE for this context table
    struct capref           mappingcncap;

    ///< cnode for the mapping caps
    struct cnoderef         mappigncn;

    ///< pointer to the parent root table.
    struct vtd_root_table  *root_table;

    ///< index of the context table in the root tbale
    uint8_t                 root_table_idx;
};


/**
 * @brief represents a protection domain of the VT-d unit
 */
struct vtd_domain {
    ///< the domain id
    vtd_domid_t                 id;

    ///< the root page table of the domain
    struct capref               ptroot;

    ///< the physical base address of the root page table
    lpaddr_t                    ptroot_base;


    ///< list of mappings
    struct vtd_domain_mapping  *devmappings;
};



struct vtd_domain_mapping {
    struct vtd_domain_mapping *next;
    struct vtd_domain_mapping *prev;
    struct vtd                *vtd;
    struct vtd_domain         *domain;
    struct capref              mappingcap;

    uint8_t             bus;
    uint8_t             idx;
};



#define vtd_ctxt_id_to_dev(idx) (idx >> 3)
#define vtd_ctxt_id_to_fun(idx) (idx & 0x7)
#define vtd_dev_fun_to_ctxt_id(dev, fun) ((dev << 3) | fun)


typedef enum {
    VTD_VERSION_INVALID = 0,
    VTD_VERSION_1_0     = 1,
    VTD_VERSION_MAX     = 2,
} vtd_version_t;

struct vtd {
    vtd_t                   vtd_dev;

{'fraction_non_alphanumeric': 0.07421074210742107, 'fraction_numerical': 0.011890118901189012, 'mean_word_length': 2.475071225071225, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6098307', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1624, 'n_words': 510}