/* * * pmu_server.c * Description: * Puma7_pmu over MRPC server driver * * * GPL LICENSE SUMMARY * * Copyright(c) 2018 Intel Corporation. * * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that 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. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. * The full GNU General Public License is included in this distribution * in the file called LICENSE.GPL. * * Contact Information: * Intel Corporation * 2200 Mission College Blvd. * Santa Clara, CA 97052 */ #define pr_fmt(fmt) KBUILD_MODNAME ":%s:%d " fmt "\n", __func__, __LINE__ /************************************************/ /** Includes */ /************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef DEBUG #define DBG(fmt, ...) pr_err(fmt, ##__VA_ARGS__) #else #define DBG(fmt, ...) pr_debug(fmt, ##__VA_ARGS__) #endif #define MRPC_SERVER_NAME "pmu_server" /* driver private database */ struct pmu_private { struct platform_device *pdev; /* platform device */ struct mrpc_server *mrpc; /* mrpc server handle */ }; struct mrpc_PUMA7_SRAM_Ctrl_args { Puma7PmuSram_e sram_id; int to_power_on; }; /* p_arglen is assigned the sizeof(func_args), therefor each arguments struct name should begin with the function's name */ #define PMU_PROC_32(proc, func) \ [proc] = { \ .procid = proc, \ .p_func = func, \ .p_arglen = sizeof(struct func ## _args), \ .p_replen = sizeof(Uint32), \ .p_name = #func, \ } enum { PMU_PUMA7_SRAM_CTRL, }; static int mrpc_PUMA7_SRAM_Ctrl(void *arg, ssize_t arglen, void *rep, ssize_t replen) { struct mrpc_PUMA7_SRAM_Ctrl_args *arguments = arg; Uint32 *p_rep = rep; *p_rep = PUMA7_SRAM_Ctrl(arguments->sram_id, arguments->to_power_on); *p_rep = htonl(*p_rep); return 0; } static struct mrpc_procinfo pmu_server_procs[] = { PMU_PROC_32(PMU_PUMA7_SRAM_CTRL, mrpc_PUMA7_SRAM_Ctrl), }; /* sysfs for future use */ static ssize_t status_show(struct device *dev, struct device_attribute *attr, char *buf) { struct pmu_private *priv = dev_get_drvdata(dev); if (!priv) return -EINVAL; return scnprintf(buf, PAGE_SIZE, "status ok"); } static DEVICE_ATTR(status, S_IRUGO, status_show, NULL); static struct attribute *pmu_attrs[] = { &dev_attr_status.attr, NULL }; static struct attribute_group pmu_attrs_group = { .attrs = pmu_attrs, }; /** * pmu_probe * * @param pdev platform device * * @return 0 for success, error code otherwise */ static int pmu_probe(struct platform_device *pdev) { struct pmu_private *priv; int ret; priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) { pr_err("memory allocation failed"); return -ENOMEM; } dev_set_drvdata(&pdev->dev, priv); priv->pdev = pdev; ret = sysfs_create_group(&priv->pdev->dev.kobj, &pmu_attrs_group); if (ret) { pr_err("sysfs_create_group failed (ret=%d)", ret); return ret; } priv->mrpc = mrpc_server_register(MRPC_RESERVED_ID_PMU, MRPC_SERVER_NAME, pmu_server_procs, ARRAY_SIZE(pmu_server_procs)); if (!priv->mrpc) { pr_err("failed to register pmu"); ret = -ENODEV; goto out_remove_group; } return 0; out_remove_group: sysfs_remove_group(&priv->pdev->dev.kobj, &pmu_attrs_group); return ret; } /** * pmu_remove * * This function is called when the pmu driver is removed. * * @param pdev platform device * * @return 0 for success, error code otherwise */ static int pmu_remove(struct platform_device *pdev) { struct pmu_private *priv = platform_get_drvdata(pdev); mrpc_server_unregister(priv->mrpc); sysfs_remove_group(&priv->pdev->dev.kobj, &pmu_attrs_group); dev_set_drvdata(&pdev->dev, NULL); return 0; } static struct platform_driver pmu_driver = { .driver = { .name = MRPC_SERVER_NAME, }, .probe = pmu_probe, .remove = pmu_remove, }; static struct platform_device *pmu_device; static int __init pmu_server_init(void) { int ret; ret = platform_driver_register(&pmu_driver); if (ret < 0) { printk("Failed to register pmu platform driver: %d\n", ret); return ret; } pmu_device = platform_device_register_simple(MRPC_SERVER_NAME, -1, NULL, 0); if (IS_ERR(pmu_device)) { printk("Failed to register pmu platform device\n"); platform_driver_unregister(&pmu_driver); return PTR_ERR(pmu_device); } return 0; } static void __exit pmu_server_exit(void) { platform_device_unregister(pmu_device); platform_driver_unregister(&pmu_driver); } /******************************************************/ /** Module Declarations **/ /******************************************************/ module_init(pmu_server_init); module_exit(pmu_server_exit); MODULE_AUTHOR("Intel Corporation"); MODULE_DESCRIPTION("pmu mrpc server"); MODULE_LICENSE("GPL"); MODULE_VERSION("1.0");