diff --git a/Makefile b/Makefile index 078f93f..552c2ff 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ ccflags-y += -I$(srctree.nvidia)/include obj-$(CONFIG_DEBUG_FS) += os/linux/debugfs.o obj-y += os/linux/driver.o -obj-y += os/linux/io.o +obj-y += os/linux/io_utils.o obj-y += os/linux/ip_utils.o obj-y += os/linux/ioctl.o obj-y += os/linux/kmem.o diff --git a/include/tegra_hwpm_io.h b/include/tegra_hwpm_io.h index b8b0f5b..f14c8ec 100644 --- a/include/tegra_hwpm_io.h +++ b/include/tegra_hwpm_io.h @@ -49,22 +49,55 @@ static inline u32 get_field(u32 input_data, u32 mask) return (input_data & mask); } +#ifdef __KERNEL__ +#include +#else +int tegra_hwpm_read_sticky_bits_impl(struct tegra_soc_hwpm *hwpm, + u64 reg_base, u64 reg_offset, u32 *val) +{ + return -EINVAL; +} -struct tegra_soc_hwpm; -struct hwpm_ip_inst; -struct hwpm_ip_aperture; +int tegra_hwpm_readl_impl(struct tegra_soc_hwpm *hwpm, + struct hwpm_ip_aperture *aperture, u64 addr, u32 *val) +{ + return -EINVAL; +} -int tegra_hwpm_read_sticky_bits(struct tegra_soc_hwpm *hwpm, - u64 reg_base, u64 reg_offset, u32 *val); -int tegra_hwpm_readl(struct tegra_soc_hwpm *hwpm, - struct hwpm_ip_aperture *aperture, u64 addr, u32 *val); -int tegra_hwpm_writel(struct tegra_soc_hwpm *hwpm, - struct hwpm_ip_aperture *aperture, u64 addr, u32 val); -int tegra_hwpm_regops_readl(struct tegra_soc_hwpm *hwpm, +int tegra_hwpm_writel_impl(struct tegra_soc_hwpm *hwpm, + struct hwpm_ip_aperture *aperture, u64 addr, u32 val) +{ + return -EINVAL; +} + +int tegra_hwpm_regops_readl_impl(struct tegra_soc_hwpm *hwpm, struct hwpm_ip_inst *ip_inst, struct hwpm_ip_aperture *aperture, - u64 addr, u32 *val); -int tegra_hwpm_regops_writel(struct tegra_soc_hwpm *hwpm, + u64 addr, u32 *val) +{ + return -EINVAL; +} + +int tegra_hwpm_regops_writel_impl(struct tegra_soc_hwpm *hwpm, struct hwpm_ip_inst *ip_inst, struct hwpm_ip_aperture *aperture, - u64 addr, u32 val); + u64 addr, u32 val) +{ + return -EINVAL; +} +#endif + +#define tegra_hwpm_read_sticky_bits(hwpm, reg_base, reg_offset, val) \ + tegra_hwpm_read_sticky_bits_impl(hwpm, reg_base, reg_offset, val) + +#define tegra_hwpm_readl(hwpm, aperture, addr, val) \ + tegra_hwpm_readl_impl(hwpm, aperture, addr, val) + +#define tegra_hwpm_writel(hwpm, aperture, addr, val) \ + tegra_hwpm_writel_impl(hwpm, aperture, addr, val) + +#define tegra_hwpm_regops_readl(hwpm, ip_inst, aperture, addr, val) \ + tegra_hwpm_regops_readl_impl(hwpm, ip_inst, aperture, addr, val) + +#define tegra_hwpm_regops_writel(hwpm, ip_inst, aperture, addr, val) \ + tegra_hwpm_regops_writel_impl(hwpm, ip_inst, aperture, addr, val) #endif /* TEGRA_HWPM_IO_H */ diff --git a/os/linux/io.c b/os/linux/io_utils.c similarity index 96% rename from os/linux/io.c rename to os/linux/io_utils.c index efbee69..b96bc03 100644 --- a/os/linux/io.c +++ b/os/linux/io_utils.c @@ -23,7 +23,7 @@ #include #include -int tegra_hwpm_read_sticky_bits(struct tegra_soc_hwpm *hwpm, +int tegra_hwpm_read_sticky_bits_impl(struct tegra_soc_hwpm *hwpm, u64 reg_base, u64 reg_offset, u32 *val) { void __iomem *ptr = NULL; @@ -217,7 +217,7 @@ static int hwpm_writel(struct tegra_soc_hwpm *hwpm, * Read a HWPM domain register. It is assumed that valid aperture * is passed to the function. */ -int tegra_hwpm_readl(struct tegra_soc_hwpm *hwpm, +int tegra_hwpm_readl_impl(struct tegra_soc_hwpm *hwpm, struct hwpm_ip_aperture *aperture, u64 addr, u32 *val) { tegra_hwpm_fn(hwpm, " "); @@ -244,7 +244,7 @@ int tegra_hwpm_readl(struct tegra_soc_hwpm *hwpm, * Write to a HWPM domain register. It is assumed that valid aperture * is passed to the function. */ -int tegra_hwpm_writel(struct tegra_soc_hwpm *hwpm, +int tegra_hwpm_writel_impl(struct tegra_soc_hwpm *hwpm, struct hwpm_ip_aperture *aperture, u64 addr, u32 val) { tegra_hwpm_fn(hwpm, " "); @@ -271,7 +271,7 @@ int tegra_hwpm_writel(struct tegra_soc_hwpm *hwpm, * Read a register from the EXEC_REG_OPS IOCTL. It is assumed that the allowlist * check has been done before calling this function. */ -int tegra_hwpm_regops_readl(struct tegra_soc_hwpm *hwpm, +int tegra_hwpm_regops_readl_impl(struct tegra_soc_hwpm *hwpm, struct hwpm_ip_inst *ip_inst, struct hwpm_ip_aperture *aperture, u64 addr, u32 *val) { @@ -300,7 +300,7 @@ int tegra_hwpm_regops_readl(struct tegra_soc_hwpm *hwpm, * Write a register from the EXEC_REG_OPS IOCTL. It is assumed that the * allowlist check has been done before calling this function. */ -int tegra_hwpm_regops_writel(struct tegra_soc_hwpm *hwpm, +int tegra_hwpm_regops_writel_impl(struct tegra_soc_hwpm *hwpm, struct hwpm_ip_inst *ip_inst, struct hwpm_ip_aperture *aperture, u64 addr, u32 val) { diff --git a/os/linux/io_utils.h b/os/linux/io_utils.h new file mode 100644 index 0000000..9ae59ad --- /dev/null +++ b/os/linux/io_utils.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#ifndef TEGRA_HWPM_OS_LINUX_IO_UTILS_H +#define TEGRA_HWPM_OS_LINUX_IO_UTILS_H + +struct tegra_soc_hwpm; +struct hwpm_ip_inst; +struct hwpm_ip_aperture; + +int tegra_hwpm_read_sticky_bits_impl(struct tegra_soc_hwpm *hwpm, + u64 reg_base, u64 reg_offset, u32 *val); +int tegra_hwpm_readl_impl(struct tegra_soc_hwpm *hwpm, + struct hwpm_ip_aperture *aperture, u64 addr, u32 *val); +int tegra_hwpm_writel_impl(struct tegra_soc_hwpm *hwpm, + struct hwpm_ip_aperture *aperture, u64 addr, u32 val); +int tegra_hwpm_regops_readl_impl(struct tegra_soc_hwpm *hwpm, + struct hwpm_ip_inst *ip_inst, struct hwpm_ip_aperture *aperture, + u64 addr, u32 *val); +int tegra_hwpm_regops_writel_impl(struct tegra_soc_hwpm *hwpm, + struct hwpm_ip_inst *ip_inst, struct hwpm_ip_aperture *aperture, + u64 addr, u32 val); + +#endif /* TEGRA_HWPM_OS_LINUX_IO_UTILS_H */ \ No newline at end of file