mirror of
https://github.com/torvalds/linux.git
synced 2024-11-21 19:46:16 +00:00
6ce2082fd3
The fault-inject.h users across the kernel need to add a lot of #ifdef
CONFIG_FAULT_INJECTION to cater for shortcomings in the header. Make
fault-inject.h self-contained for CONFIG_FAULT_INJECTION=n, and add stubs
for DECLARE_FAULT_ATTR(), setup_fault_attr(), should_fail_ex(), and
should_fail() to allow removal of conditional compilation.
[akpm@linux-foundation.org: repair fallout from no longer including debugfs.h into fault-inject.h]
[akpm@linux-foundation.org: fix drivers/misc/xilinx_tmr_inject.c]
[akpm@linux-foundation.org: Add debugfs.h inclusion to more files, per Stephen]
Link: https://lkml.kernel.org/r/20240813121237.2382534-1-jani.nikula@intel.com
Fixes: 6ff1cb355e
("[PATCH] fault-injection capabilities infrastructure")
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Abhinav Kumar <quic_abhinavk@quicinc.com>
Cc: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
173 lines
4.4 KiB
C
173 lines
4.4 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Driver for Xilinx TMR Inject IP.
|
|
*
|
|
* Copyright (C) 2022 Advanced Micro Devices, Inc.
|
|
*
|
|
* Description:
|
|
* This driver is developed for TMR Inject IP,The Triple Modular Redundancy(TMR)
|
|
* Inject provides fault injection.
|
|
*/
|
|
|
|
#include <asm/xilinx_mb_manager.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
#include <linux/debugfs.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/fault-inject.h>
|
|
|
|
/* TMR Inject Register offsets */
|
|
#define XTMR_INJECT_CR_OFFSET 0x0
|
|
#define XTMR_INJECT_AIR_OFFSET 0x4
|
|
#define XTMR_INJECT_IIR_OFFSET 0xC
|
|
#define XTMR_INJECT_EAIR_OFFSET 0x10
|
|
#define XTMR_INJECT_ERR_OFFSET 0x204
|
|
|
|
/* Register Bitmasks/shifts */
|
|
#define XTMR_INJECT_CR_CPUID_SHIFT 8
|
|
#define XTMR_INJECT_CR_IE_SHIFT 10
|
|
#define XTMR_INJECT_IIR_ADDR_MASK GENMASK(31, 16)
|
|
|
|
#define XTMR_INJECT_MAGIC_MAX_VAL 255
|
|
|
|
/**
|
|
* struct xtmr_inject_dev - Driver data for TMR Inject
|
|
* @regs: device physical base address
|
|
* @magic: Magic hardware configuration value
|
|
*/
|
|
struct xtmr_inject_dev {
|
|
void __iomem *regs;
|
|
u32 magic;
|
|
};
|
|
|
|
static DECLARE_FAULT_ATTR(inject_fault);
|
|
static char *inject_request;
|
|
module_param(inject_request, charp, 0);
|
|
MODULE_PARM_DESC(inject_request, "default fault injection attributes");
|
|
static struct dentry *dbgfs_root;
|
|
|
|
/* IO accessors */
|
|
static inline void xtmr_inject_write(struct xtmr_inject_dev *xtmr_inject,
|
|
u32 addr, u32 value)
|
|
{
|
|
iowrite32(value, xtmr_inject->regs + addr);
|
|
}
|
|
|
|
static inline u32 xtmr_inject_read(struct xtmr_inject_dev *xtmr_inject,
|
|
u32 addr)
|
|
{
|
|
return ioread32(xtmr_inject->regs + addr);
|
|
}
|
|
|
|
static int xtmr_inject_set(void *data, u64 val)
|
|
{
|
|
if (val != 1)
|
|
return -EINVAL;
|
|
|
|
xmb_inject_err();
|
|
return 0;
|
|
}
|
|
DEFINE_DEBUGFS_ATTRIBUTE(xtmr_inject_fops, NULL, xtmr_inject_set, "%llu\n");
|
|
|
|
static void xtmr_init_debugfs(struct xtmr_inject_dev *xtmr_inject)
|
|
{
|
|
struct dentry *dir;
|
|
|
|
dbgfs_root = debugfs_create_dir("xtmr_inject", NULL);
|
|
dir = fault_create_debugfs_attr("inject_fault", dbgfs_root,
|
|
&inject_fault);
|
|
debugfs_create_file("inject_fault", 0200, dir, NULL,
|
|
&xtmr_inject_fops);
|
|
}
|
|
|
|
static void xtmr_inject_init(struct xtmr_inject_dev *xtmr_inject)
|
|
{
|
|
u32 cr_val;
|
|
|
|
if (inject_request)
|
|
setup_fault_attr(&inject_fault, inject_request);
|
|
/* Allow fault injection */
|
|
cr_val = xtmr_inject->magic |
|
|
(1 << XTMR_INJECT_CR_IE_SHIFT) |
|
|
(1 << XTMR_INJECT_CR_CPUID_SHIFT);
|
|
xtmr_inject_write(xtmr_inject, XTMR_INJECT_CR_OFFSET,
|
|
cr_val);
|
|
/* Initialize the address inject and instruction inject registers */
|
|
xtmr_inject_write(xtmr_inject, XTMR_INJECT_AIR_OFFSET,
|
|
XMB_INJECT_ERR_OFFSET);
|
|
xtmr_inject_write(xtmr_inject, XTMR_INJECT_IIR_OFFSET,
|
|
XMB_INJECT_ERR_OFFSET & XTMR_INJECT_IIR_ADDR_MASK);
|
|
}
|
|
|
|
/**
|
|
* xtmr_inject_probe - Driver probe function
|
|
* @pdev: Pointer to the platform_device structure
|
|
*
|
|
* This is the driver probe routine. It does all the memory
|
|
* allocation for the device.
|
|
*
|
|
* Return: 0 on success and failure value on error
|
|
*/
|
|
static int xtmr_inject_probe(struct platform_device *pdev)
|
|
{
|
|
struct xtmr_inject_dev *xtmr_inject;
|
|
int err;
|
|
|
|
xtmr_inject = devm_kzalloc(&pdev->dev, sizeof(*xtmr_inject),
|
|
GFP_KERNEL);
|
|
if (!xtmr_inject)
|
|
return -ENOMEM;
|
|
|
|
xtmr_inject->regs = devm_platform_ioremap_resource(pdev, 0);
|
|
if (IS_ERR(xtmr_inject->regs))
|
|
return PTR_ERR(xtmr_inject->regs);
|
|
|
|
err = of_property_read_u32(pdev->dev.of_node, "xlnx,magic",
|
|
&xtmr_inject->magic);
|
|
if (err < 0) {
|
|
dev_err(&pdev->dev, "unable to read xlnx,magic property");
|
|
return err;
|
|
}
|
|
|
|
if (xtmr_inject->magic > XTMR_INJECT_MAGIC_MAX_VAL) {
|
|
dev_err(&pdev->dev, "invalid xlnx,magic property value");
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* Initialize TMR Inject */
|
|
xtmr_inject_init(xtmr_inject);
|
|
|
|
xtmr_init_debugfs(xtmr_inject);
|
|
|
|
platform_set_drvdata(pdev, xtmr_inject);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void xtmr_inject_remove(struct platform_device *pdev)
|
|
{
|
|
debugfs_remove_recursive(dbgfs_root);
|
|
dbgfs_root = NULL;
|
|
}
|
|
|
|
static const struct of_device_id xtmr_inject_of_match[] = {
|
|
{
|
|
.compatible = "xlnx,tmr-inject-1.0",
|
|
},
|
|
{ /* end of table */ }
|
|
};
|
|
MODULE_DEVICE_TABLE(of, xtmr_inject_of_match);
|
|
|
|
static struct platform_driver xtmr_inject_driver = {
|
|
.driver = {
|
|
.name = "xilinx-tmr_inject",
|
|
.of_match_table = xtmr_inject_of_match,
|
|
},
|
|
.probe = xtmr_inject_probe,
|
|
.remove_new = xtmr_inject_remove,
|
|
};
|
|
module_platform_driver(xtmr_inject_driver);
|
|
MODULE_AUTHOR("Advanced Micro Devices, Inc");
|
|
MODULE_DESCRIPTION("Xilinx TMR Inject Driver");
|
|
MODULE_LICENSE("GPL");
|