drivers/iommu/generic_pt/fmt/vtdss.h

Source file repositories/reference/linux-study-clean/drivers/iommu/generic_pt/fmt/vtdss.h

File Facts

System
Linux kernel
Corpus path
drivers/iommu/generic_pt/fmt/vtdss.h
Extension
.h
Size
7707 bytes
Lines
286
Domain
Driver Families
Bucket
drivers/iommu
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

#ifndef __GENERIC_PT_FMT_VTDSS_H
#define __GENERIC_PT_FMT_VTDSS_H

#include "defs_vtdss.h"
#include "../pt_defs.h"

#include <linux/bitfield.h>
#include <linux/container_of.h>
#include <linux/log2.h>

enum {
	PT_MAX_OUTPUT_ADDRESS_LG2 = 52,
	PT_MAX_VA_ADDRESS_LG2 = 57,
	PT_ITEM_WORD_SIZE = sizeof(u64),
	PT_MAX_TOP_LEVEL = 4,
	PT_GRANULE_LG2SZ = 12,
	PT_TABLEMEM_LG2SZ = 12,

	/* SSPTPTR is 4k aligned and limited by HAW */
	PT_TOP_PHYS_MASK = GENMASK_ULL(63, 12),
};

/* Shared descriptor bits */
enum {
	VTDSS_FMT_R = BIT(0),
	VTDSS_FMT_W = BIT(1),
	VTDSS_FMT_A = BIT(8),
	VTDSS_FMT_D = BIT(9),
	VTDSS_FMT_SNP = BIT(11),
	VTDSS_FMT_OA = GENMASK_ULL(51, 12),
};

/* PDPTE/PDE */
enum {
	VTDSS_FMT_PS = BIT(7),
};

#define common_to_vtdss_pt(common_ptr) \
	container_of_const(common_ptr, struct pt_vtdss, common)
#define to_vtdss_pt(pts) common_to_vtdss_pt((pts)->range->common)

static inline pt_oaddr_t vtdss_pt_table_pa(const struct pt_state *pts)
{
	return oalog2_mul(FIELD_GET(VTDSS_FMT_OA, pts->entry),
			  PT_TABLEMEM_LG2SZ);
}
#define pt_table_pa vtdss_pt_table_pa

static inline pt_oaddr_t vtdss_pt_entry_oa(const struct pt_state *pts)
{
	return oalog2_mul(FIELD_GET(VTDSS_FMT_OA, pts->entry),
			  PT_GRANULE_LG2SZ);
}
#define pt_entry_oa vtdss_pt_entry_oa

static inline bool vtdss_pt_can_have_leaf(const struct pt_state *pts)
{
	return pts->level <= 2;
}
#define pt_can_have_leaf vtdss_pt_can_have_leaf

static inline unsigned int vtdss_pt_num_items_lg2(const struct pt_state *pts)
{
	return PT_TABLEMEM_LG2SZ - ilog2(sizeof(u64));
}
#define pt_num_items_lg2 vtdss_pt_num_items_lg2

static inline enum pt_entry_type vtdss_pt_load_entry_raw(struct pt_state *pts)
{
	const u64 *tablep = pt_cur_table(pts, u64);
	u64 entry;

	pts->entry = entry = READ_ONCE(tablep[pts->index]);
	if (!entry)
		return PT_ENTRY_EMPTY;
	if (pts->level == 0 ||
	    (vtdss_pt_can_have_leaf(pts) && (pts->entry & VTDSS_FMT_PS)))
		return PT_ENTRY_OA;
	return PT_ENTRY_TABLE;
}
#define pt_load_entry_raw vtdss_pt_load_entry_raw

static inline void
vtdss_pt_install_leaf_entry(struct pt_state *pts, pt_oaddr_t oa,
			    unsigned int oasz_lg2,
			    const struct pt_write_attrs *attrs)
{
	u64 *tablep = pt_cur_table(pts, u64);
	u64 entry;

Annotation

Implementation Notes