dfl-fme-main.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Driver for FPGA Management Engine (FME)
  4. *
  5. * Copyright (C) 2017-2018 Intel Corporation, Inc.
  6. *
  7. * Authors:
  8. * Kang Luwei <luwei.kang@intel.com>
  9. * Xiao Guangrong <guangrong.xiao@linux.intel.com>
  10. * Joseph Grecco <joe.grecco@intel.com>
  11. * Enno Luebbers <enno.luebbers@intel.com>
  12. * Tim Whisonant <tim.whisonant@intel.com>
  13. * Ananda Ravuri <ananda.ravuri@intel.com>
  14. * Henry Mitchel <henry.mitchel@intel.com>
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include "dfl.h"
  19. static int fme_hdr_init(struct platform_device *pdev,
  20. struct dfl_feature *feature)
  21. {
  22. dev_dbg(&pdev->dev, "FME HDR Init.\n");
  23. return 0;
  24. }
  25. static void fme_hdr_uinit(struct platform_device *pdev,
  26. struct dfl_feature *feature)
  27. {
  28. dev_dbg(&pdev->dev, "FME HDR UInit.\n");
  29. }
  30. static const struct dfl_feature_ops fme_hdr_ops = {
  31. .init = fme_hdr_init,
  32. .uinit = fme_hdr_uinit,
  33. };
  34. static struct dfl_feature_driver fme_feature_drvs[] = {
  35. {
  36. .id = FME_FEATURE_ID_HEADER,
  37. .ops = &fme_hdr_ops,
  38. },
  39. {
  40. .ops = NULL,
  41. },
  42. };
  43. static int fme_open(struct inode *inode, struct file *filp)
  44. {
  45. struct platform_device *fdev = dfl_fpga_inode_to_feature_dev(inode);
  46. struct dfl_feature_platform_data *pdata = dev_get_platdata(&fdev->dev);
  47. int ret;
  48. if (WARN_ON(!pdata))
  49. return -ENODEV;
  50. ret = dfl_feature_dev_use_begin(pdata);
  51. if (ret)
  52. return ret;
  53. dev_dbg(&fdev->dev, "Device File Open\n");
  54. filp->private_data = pdata;
  55. return 0;
  56. }
  57. static int fme_release(struct inode *inode, struct file *filp)
  58. {
  59. struct dfl_feature_platform_data *pdata = filp->private_data;
  60. struct platform_device *pdev = pdata->dev;
  61. dev_dbg(&pdev->dev, "Device File Release\n");
  62. dfl_feature_dev_use_end(pdata);
  63. return 0;
  64. }
  65. static long fme_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  66. {
  67. struct dfl_feature_platform_data *pdata = filp->private_data;
  68. struct platform_device *pdev = pdata->dev;
  69. struct dfl_feature *f;
  70. long ret;
  71. dev_dbg(&pdev->dev, "%s cmd 0x%x\n", __func__, cmd);
  72. switch (cmd) {
  73. default:
  74. /*
  75. * Let sub-feature's ioctl function to handle the cmd.
  76. * Sub-feature's ioctl returns -ENODEV when cmd is not
  77. * handled in this sub feature, and returns 0 or other
  78. * error code if cmd is handled.
  79. */
  80. dfl_fpga_dev_for_each_feature(pdata, f) {
  81. if (f->ops && f->ops->ioctl) {
  82. ret = f->ops->ioctl(pdev, f, cmd, arg);
  83. if (ret != -ENODEV)
  84. return ret;
  85. }
  86. }
  87. }
  88. return -EINVAL;
  89. }
  90. static const struct file_operations fme_fops = {
  91. .owner = THIS_MODULE,
  92. .open = fme_open,
  93. .release = fme_release,
  94. .unlocked_ioctl = fme_ioctl,
  95. };
  96. static int fme_probe(struct platform_device *pdev)
  97. {
  98. int ret;
  99. ret = dfl_fpga_dev_feature_init(pdev, fme_feature_drvs);
  100. if (ret)
  101. goto exit;
  102. ret = dfl_fpga_dev_ops_register(pdev, &fme_fops, THIS_MODULE);
  103. if (ret)
  104. goto feature_uinit;
  105. return 0;
  106. feature_uinit:
  107. dfl_fpga_dev_feature_uinit(pdev);
  108. exit:
  109. return ret;
  110. }
  111. static int fme_remove(struct platform_device *pdev)
  112. {
  113. dfl_fpga_dev_ops_unregister(pdev);
  114. dfl_fpga_dev_feature_uinit(pdev);
  115. return 0;
  116. }
  117. static struct platform_driver fme_driver = {
  118. .driver = {
  119. .name = DFL_FPGA_FEATURE_DEV_FME,
  120. },
  121. .probe = fme_probe,
  122. .remove = fme_remove,
  123. };
  124. module_platform_driver(fme_driver);
  125. MODULE_DESCRIPTION("FPGA Management Engine driver");
  126. MODULE_AUTHOR("Intel Corporation");
  127. MODULE_LICENSE("GPL v2");
  128. MODULE_ALIAS("platform:dfl-fme");