linux/drivers/gpu/drm/xe/xe_pt_walk.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright © 2022 Intel Corporation
 */
#include "xe_pt_walk.h"

/**
 * DOC: GPU page-table tree walking.
 * The utilities in this file are similar to the CPU page-table walk
 * utilities in mm/pagewalk.c. The main difference is that we distinguish
 * the various levels of a page-table tree with an unsigned integer rather
 * than by name. 0 is the lowest level, and page-tables with level 0 can
 * not be directories pointing to lower levels, whereas all other levels
 * can. The user of the utilities determines the highest level.
 *
 * Nomenclature:
 * Each struct xe_ptw, regardless of level is referred to as a page table, and
 * multiple page tables typically form a page table tree with page tables at
 * intermediate levels being page directories pointing at page tables at lower
 * levels. A shared page table for a given address range is a page-table which
 * is neither fully within nor fully outside the address range and that can
 * thus be shared by two or more address ranges.
 *
 * Please keep this code generic so that it can used as a drm-wide page-
 * table walker should other drivers find use for it.
 */
static u64 xe_pt_addr_end(u64 addr, u64 end, unsigned int level,
			  const struct xe_pt_walk *walk)
{}

static bool xe_pt_next(pgoff_t *offset, u64 *addr, u64 next, u64 end,
		       unsigned int level, const struct xe_pt_walk *walk)
{}

/**
 * xe_pt_walk_range() - Walk a range of a gpu page table tree with callbacks
 * for each page-table entry in all levels.
 * @parent: The root page table for walk start.
 * @level: The root page table level.
 * @addr: Virtual address start.
 * @end: Virtual address end + 1.
 * @walk: Walk info.
 *
 * Similar to the CPU page-table walker, this is a helper to walk
 * a gpu page table and call a provided callback function for each entry.
 *
 * Return: 0 on success, negative error code on error. The error is
 * propagated from the callback and on error the walk is terminated.
 */
int xe_pt_walk_range(struct xe_ptw *parent, unsigned int level,
		     u64 addr, u64 end, struct xe_pt_walk *walk)
{}

/**
 * xe_pt_walk_shared() - Walk shared page tables of a page-table tree.
 * @parent: Root page table directory.
 * @level: Level of the root.
 * @addr: Start address.
 * @end: Last address + 1.
 * @walk: Walk info.
 *
 * This function is similar to xe_pt_walk_range() but it skips page tables
 * that are private to the range. Since the root (or @parent) page table is
 * typically also a shared page table this function is different in that it
 * calls the pt_entry callback and the post_descend callback also for the
 * root. The root can be detected in the callbacks by checking whether
 * parent == *child.
 * Walking only the shared page tables is common for unbind-type operations
 * where the page-table entries for an address range are cleared or detached
 * from the main page-table tree.
 *
 * Return: 0 on success, negative error code on error: If a callback
 * returns an error, the walk will be terminated and the error returned by
 * this function.
 */
int xe_pt_walk_shared(struct xe_ptw *parent, unsigned int level,
		      u64 addr, u64 end, struct xe_pt_walk *walk)
{}