drivers/iommu/generic_pt/fmt/riscv.h

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

File Facts

System
Linux kernel
Corpus path
drivers/iommu/generic_pt/fmt/riscv.h
Extension
.h
Size
8955 bytes
Lines
323
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_RISCV_H
#define __GENERIC_PT_FMT_RISCV_H

#include "defs_riscv.h"
#include "../pt_defs.h"

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

enum {
	PT_ITEM_WORD_SIZE = sizeof(pt_riscv_entry_t),
#ifdef PT_RISCV_32BIT
	PT_MAX_VA_ADDRESS_LG2 = 32,
	PT_MAX_OUTPUT_ADDRESS_LG2 = 34,
	PT_MAX_TOP_LEVEL = 1,
#else
	PT_MAX_VA_ADDRESS_LG2 = 57,
	PT_MAX_OUTPUT_ADDRESS_LG2 = 56,
	PT_MAX_TOP_LEVEL = 4,
#endif
	PT_GRANULE_LG2SZ = 12,
	PT_TABLEMEM_LG2SZ = 12,

	/* fsc.PPN is 44 bits wide, all PPNs are 4k aligned */
	PT_TOP_PHYS_MASK = GENMASK_ULL(55, 12),
};

/* PTE bits */
enum {
	RISCVPT_V = BIT(0),
	RISCVPT_R = BIT(1),
	RISCVPT_W = BIT(2),
	RISCVPT_X = BIT(3),
	RISCVPT_U = BIT(4),
	RISCVPT_G = BIT(5),
	RISCVPT_A = BIT(6),
	RISCVPT_D = BIT(7),
	RISCVPT_RSW = GENMASK(9, 8),
	RISCVPT_PPN32 = GENMASK(31, 10),

	RISCVPT_PPN64 = GENMASK_ULL(53, 10),
	RISCVPT_PPN64_64K = GENMASK_ULL(53, 14),
	RISCVPT_PBMT = GENMASK_ULL(62, 61),
	RISCVPT_NC = BIT_ULL(61),
	RISCVPT_IO = BIT_ULL(62),
	RISCVPT_N = BIT_ULL(63),

	/* Svnapot encodings for ppn[0] */
	RISCVPT_PPN64_64K_SZ = BIT(13),
};

#ifdef PT_RISCV_32BIT
#define RISCVPT_PPN RISCVPT_PPN32
#define pt_riscv pt_riscv_32
#else
#define RISCVPT_PPN RISCVPT_PPN64
#define pt_riscv pt_riscv_64
#endif

#define common_to_riscvpt(common_ptr) \
	container_of_const(common_ptr, struct pt_riscv, common)
#define to_riscvpt(pts) common_to_riscvpt((pts)->range->common)

static inline pt_oaddr_t riscvpt_table_pa(const struct pt_state *pts)
{
	return oalog2_mul(FIELD_GET(RISCVPT_PPN, pts->entry), PT_GRANULE_LG2SZ);
}
#define pt_table_pa riscvpt_table_pa

static inline pt_oaddr_t riscvpt_entry_oa(const struct pt_state *pts)
{
	if (pts_feature(pts, PT_FEAT_RISCV_SVNAPOT_64K) &&
	    pts->entry & RISCVPT_N) {
		PT_WARN_ON(pts->level != 0);
		return oalog2_mul(FIELD_GET(RISCVPT_PPN64_64K, pts->entry),
				  ilog2(SZ_64K));
	}
	return oalog2_mul(FIELD_GET(RISCVPT_PPN, pts->entry), PT_GRANULE_LG2SZ);
}
#define pt_entry_oa riscvpt_entry_oa

static inline bool riscvpt_can_have_leaf(const struct pt_state *pts)
{
	return true;
}
#define pt_can_have_leaf riscvpt_can_have_leaf

/* Body in pt_fmt_defaults.h */

Annotation

Implementation Notes