From e7db60a58d2d8062b09c972e0eba06a3fdd89f7e Mon Sep 17 00:00:00 2001 From: Ashish Mhetre Date: Thu, 1 Jun 2023 11:48:32 +0000 Subject: [PATCH] memory: tegra: Enable building of mc-t26x mc-t26x driver was not getting built because it's entry was missing in kernel-src-files-copy-list.txt. Add files required for mc-t26x in kernel-src-files-copy-list.txt. Also, move the mc-t26x driver to a private-soc directory to build separately from existing files in memory/tegra directory. Bug 3960743 Change-Id: I71a6271dcc5c962630a3c939f84ba0b511cae4dd Signed-off-by: Ashish Mhetre Reviewed-on: https://git-master.nvidia.com/r/c/linux-t264/+/2914088 Reviewed-by: Ketan Patil Reviewed-by: Sachin Nikam GVS: Gerrit_Virtual_Submit --- drivers/memory/tegra/private-soc/Makefile | 2 + drivers/memory/tegra/private-soc/mc-t26x.c | 75 ++++++++++++++++++++++ include/soc/tegra/mc-t26x.h | 4 ++ 3 files changed, 81 insertions(+) create mode 100644 drivers/memory/tegra/private-soc/Makefile create mode 100644 drivers/memory/tegra/private-soc/mc-t26x.c create mode 100644 include/soc/tegra/mc-t26x.h diff --git a/drivers/memory/tegra/private-soc/Makefile b/drivers/memory/tegra/private-soc/Makefile new file mode 100644 index 00000000..5cb443a4 --- /dev/null +++ b/drivers/memory/tegra/private-soc/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-m += mc-t26x.o diff --git a/drivers/memory/tegra/private-soc/mc-t26x.c b/drivers/memory/tegra/private-soc/mc-t26x.c new file mode 100644 index 00000000..c55aa24f --- /dev/null +++ b/drivers/memory/tegra/private-soc/mc-t26x.c @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2023 NVIDIA CORPORATION. All rights reserved. + +#define pr_fmt(fmt) "mc: " fmt +#include +#include +#include +#include + +#define MC_SECURITY_CARVEOUT_BASE 0x9404 +#define MC_CARVEOUT_NEXT 0xa0 +#define MC_SECURITY_CARVEOUT_LITE_BASE 0xa804 +#define MC_CARVEOUT_LITE_NEXT 0x60 +#define MC_CARVEOUT_BASE_HI 0x4 +#define MC_SECURITY_CARVEOUT_SIZE_128KB 0x8 + +static void __iomem *mcb_base; + +static inline u32 mc_readl(unsigned long offset) +{ + return readl_relaxed(mcb_base + offset); +} + +int tegra264_mc_get_carveout_info(unsigned int id, phys_addr_t *base, u64 *size) +{ + u32 offset; + if (id < 1 || id > 42) + return -EINVAL; + if (id < 32) + offset = MC_SECURITY_CARVEOUT_BASE + MC_CARVEOUT_NEXT * (id - 1); + else + offset = MC_SECURITY_CARVEOUT_LITE_BASE + MC_CARVEOUT_LITE_NEXT * (id - 32); + *base = mc_readl(offset + 0x0); +#ifdef CONFIG_PHYS_ADDR_T_64BIT + *base |= (phys_addr_t)mc_readl(offset + MC_CARVEOUT_BASE_HI) << 32; +#endif + if (size) + *size = mc_readl(offset + MC_SECURITY_CARVEOUT_SIZE_128KB) << 17; + return 0; +} +EXPORT_SYMBOL(tegra264_mc_get_carveout_info); + +const struct of_device_id tegra_mc_of_ids[] = { + { .compatible = "nvidia,tegra-t26x-mc" }, + { } +}; +MODULE_DEVICE_TABLE(of, tegra_mc_of_ids); + +static int tegra_mc_probe(struct platform_device *pdev) +{ + mcb_base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR_OR_NULL(mcb_base)) + return PTR_ERR(mcb_base); + return 0; +} + +static int tegra_mc_remove(struct platform_device *pdev) +{ + return 0; +} + +static struct platform_driver mc_driver = { + .driver = { + .name = "nv-tegra-t26x-mc", + .of_match_table = tegra_mc_of_ids, + .owner = THIS_MODULE, + }, + .remove = tegra_mc_remove, +}; + +module_platform_driver_probe(mc_driver, tegra_mc_probe); + +MODULE_AUTHOR("Ashish Mhetre "); +MODULE_DESCRIPTION("NVIDIA Tegra Memory Controller driver"); +MODULE_LICENSE("GPL v2"); diff --git a/include/soc/tegra/mc-t26x.h b/include/soc/tegra/mc-t26x.h new file mode 100644 index 00000000..240d1b4d --- /dev/null +++ b/include/soc/tegra/mc-t26x.h @@ -0,0 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2023 NVIDIA CORPORATION. All rights reserved. + +int tegra264_mc_get_carveout_info(unsigned int id, phys_addr_t *base, u64 *size);