From 2208b0283616863f166ef470fb9286223ba8f9ba Mon Sep 17 00:00:00 2001 From: liuyanshi Date: Fri, 23 Aug 2019 13:47:03 +0800 Subject: [PATCH] pcie: hisi pcie dfx driver driver inclusion category: feature bugzilla: NA CVE: NA hisi_pcie_cae:hisi pcie debug driver for hiarmtool. This driver can create /dev/pcie_reg_dev file and map pcie regs to userspace. Hiarmtool can use this file to access pcie regs in order to get useful dfx information about pcie module. Signed-off-by: liuyanshi Reviewed-by: Li Jingyi Acked-by: Hanjun Guo Signed-off-by: Yang Yingliang --- MAINTAINERS | 5 ++ drivers/pci/controller/Kconfig | 1 + drivers/pci/controller/Makefile | 1 + .../pci/controller/hisi-pcie-customer/Kconfig | 3 + .../controller/hisi-pcie-customer/Makefile | 2 + .../hisi-pcie-customer/hisi_pcie_cae.c | 86 +++++++++++++++++++ 6 files changed, 98 insertions(+) create mode 100644 drivers/pci/controller/hisi-pcie-customer/Kconfig create mode 100644 drivers/pci/controller/hisi-pcie-customer/Makefile create mode 100644 drivers/pci/controller/hisi-pcie-customer/hisi_pcie_cae.c diff --git a/MAINTAINERS b/MAINTAINERS index cd866ea2fc31..9d68ff5e9c7f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11355,6 +11355,11 @@ S: Maintained F: Documentation/devicetree/bindings/pci/hisilicon-histb-pcie.txt F: drivers/pci/controller/dwc/pcie-histb.c +PCIE DFX DRIVER FOR HISILICON +M: Liu Yanshi +S: Maintained +F: drivers/pci/controller/hisi-pcie-customer/ + PCIE DRIVER FOR MEDIATEK M: Ryder Lee L: linux-pci@vger.kernel.org diff --git a/drivers/pci/controller/Kconfig b/drivers/pci/controller/Kconfig index 028b287466fb..21bda955e66a 100644 --- a/drivers/pci/controller/Kconfig +++ b/drivers/pci/controller/Kconfig @@ -279,4 +279,5 @@ config VMD module will be called vmd. source "drivers/pci/controller/dwc/Kconfig" +source "drivers/pci/controller/hisi-pcie-customer/Kconfig" endmenu diff --git a/drivers/pci/controller/Makefile b/drivers/pci/controller/Makefile index d56a507495c5..0771b957ce7b 100644 --- a/drivers/pci/controller/Makefile +++ b/drivers/pci/controller/Makefile @@ -31,6 +31,7 @@ obj-$(CONFIG_PCIE_TANGO_SMP8759) += pcie-tango.o obj-$(CONFIG_VMD) += vmd.o # pcie-hisi.o quirks are needed even without CONFIG_PCIE_DW obj-y += dwc/ +obj-y += hisi-pcie-customer/ # The following drivers are for devices that use the generic ACPI diff --git a/drivers/pci/controller/hisi-pcie-customer/Kconfig b/drivers/pci/controller/hisi-pcie-customer/Kconfig new file mode 100644 index 000000000000..4c0203dc508f --- /dev/null +++ b/drivers/pci/controller/hisi-pcie-customer/Kconfig @@ -0,0 +1,3 @@ +config HISILICON_PCIE_CAE + tristate "hisi custom pcie driver for hiarmtool" + default m \ No newline at end of file diff --git a/drivers/pci/controller/hisi-pcie-customer/Makefile b/drivers/pci/controller/hisi-pcie-customer/Makefile new file mode 100644 index 000000000000..9b2c7ef42bab --- /dev/null +++ b/drivers/pci/controller/hisi-pcie-customer/Makefile @@ -0,0 +1,2 @@ +pcie_cae-objs := hisi_pcie_cae.o +obj-$(CONFIG_HISILICON_PCIE_CAE) += pcie_cae.o \ No newline at end of file diff --git a/drivers/pci/controller/hisi-pcie-customer/hisi_pcie_cae.c b/drivers/pci/controller/hisi-pcie-customer/hisi_pcie_cae.c new file mode 100644 index 000000000000..66113e816f7b --- /dev/null +++ b/drivers/pci/controller/hisi-pcie-customer/hisi_pcie_cae.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright (c) 2016-2017 Hisilicon Limited. + +#include +#include +#include +#include + +#define CHIP_OFFSET 0x200000000000UL +#define APB_SUBCTRL_BASE 0x148070000UL + +#define DEVICE_NAME "pcie_reg_dev" + +static const struct vm_operations_struct mmap_pcie_mem_ops = { +#ifdef CONFIG_HAVE_IOREMAP_PROT + .access = generic_access_phys +#endif +}; + +static int pcie_reg_mmap(struct file *filep, struct vm_area_struct *vma) +{ + u64 size = vma->vm_end - vma->vm_start; + u32 chip_id = (u32)vma->vm_pgoff; + u64 phy_addr; + + pr_info("[PCIe Base] tools map chipid:%d\n", chip_id); + phy_addr = APB_SUBCTRL_BASE + CHIP_OFFSET * chip_id; + /* It's illegal to wrap around the end of the physical address space. */ + vma->vm_pgoff = phy_addr >> PAGE_SHIFT; + + vma->vm_page_prot = pgprot_device(vma->vm_page_prot); + + vma->vm_ops = &mmap_pcie_mem_ops; + + /* Remap-pfn-range will mark the range VM_IO */ + if (remap_pfn_range(vma, + vma->vm_start, + vma->vm_pgoff, + size, + vma->vm_page_prot)) { + return -EAGAIN; + } + return 0; +} + +static int pcie_open(struct inode *inode, struct file *f) +{ + return 0; +} + +static int pcie_release(struct inode *inode, struct file *f) +{ + return 0; +} + +static const struct file_operations pcie_dfx_fops = { + .owner = THIS_MODULE, + .open = pcie_open, + .release = pcie_release, + .llseek = noop_llseek, + .mmap = pcie_reg_mmap, +}; + +static struct miscdevice pcie_dfx_misc = { + .minor = MISC_DYNAMIC_MINOR, + .fops = &pcie_dfx_fops, + .name = DEVICE_NAME, +}; + +static int __init misc_dev_init(void) +{ + return misc_register(&pcie_dfx_misc); +} + +static void __exit misc_dev_exit(void) +{ + (void)misc_deregister(&pcie_dfx_misc); +} + +module_init(misc_dev_init); +module_exit(misc_dev_exit); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Huawei Technology Company"); +MODULE_DESCRIPTION("PCIe DFX TOOL"); +MODULE_VERSION("V1.0"); + -- GitLab