cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

intel_pxp_debugfs.c (1869B)


      1// SPDX-License-Identifier: MIT
      2/*
      3 * Copyright © 2021 Intel Corporation
      4 */
      5
      6#include <linux/debugfs.h>
      7#include <linux/string_helpers.h>
      8
      9#include <drm/drm_print.h>
     10
     11#include "gt/intel_gt_debugfs.h"
     12#include "pxp/intel_pxp.h"
     13#include "pxp/intel_pxp_irq.h"
     14#include "i915_drv.h"
     15
     16static int pxp_info_show(struct seq_file *m, void *data)
     17{
     18	struct intel_pxp *pxp = m->private;
     19	struct drm_printer p = drm_seq_file_printer(m);
     20	bool enabled = intel_pxp_is_enabled(pxp);
     21
     22	if (!enabled) {
     23		drm_printf(&p, "pxp disabled\n");
     24		return 0;
     25	}
     26
     27	drm_printf(&p, "active: %s\n", str_yes_no(intel_pxp_is_active(pxp)));
     28	drm_printf(&p, "instance counter: %u\n", pxp->key_instance);
     29
     30	return 0;
     31}
     32DEFINE_INTEL_GT_DEBUGFS_ATTRIBUTE(pxp_info);
     33
     34static int pxp_terminate_get(void *data, u64 *val)
     35{
     36	/* nothing to read */
     37	return -EPERM;
     38}
     39
     40static int pxp_terminate_set(void *data, u64 val)
     41{
     42	struct intel_pxp *pxp = data;
     43	struct intel_gt *gt = pxp_to_gt(pxp);
     44
     45	if (!intel_pxp_is_active(pxp))
     46		return -ENODEV;
     47
     48	/* simulate a termination interrupt */
     49	spin_lock_irq(&gt->irq_lock);
     50	intel_pxp_irq_handler(pxp, GEN12_DISPLAY_PXP_STATE_TERMINATED_INTERRUPT);
     51	spin_unlock_irq(&gt->irq_lock);
     52
     53	if (!wait_for_completion_timeout(&pxp->termination,
     54					 msecs_to_jiffies(100)))
     55		return -ETIMEDOUT;
     56
     57	return 0;
     58}
     59
     60DEFINE_SIMPLE_ATTRIBUTE(pxp_terminate_fops, pxp_terminate_get, pxp_terminate_set, "%llx\n");
     61void intel_pxp_debugfs_register(struct intel_pxp *pxp, struct dentry *gt_root)
     62{
     63	static const struct intel_gt_debugfs_file files[] = {
     64		{ "info", &pxp_info_fops, NULL },
     65		{ "terminate_state", &pxp_terminate_fops, NULL },
     66	};
     67	struct dentry *root;
     68
     69	if (!gt_root)
     70		return;
     71
     72	if (!HAS_PXP((pxp_to_gt(pxp)->i915)))
     73		return;
     74
     75	root = debugfs_create_dir("pxp", gt_root);
     76	if (IS_ERR(root))
     77		return;
     78
     79	intel_gt_debugfs_register_files(root, files, ARRAY_SIZE(files), pxp);
     80}