qti-smmu-proxy-common.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #include <linux/cdev.h>
  6. #include "qti-smmu-proxy-common.h"
  7. #include "smcinvoke.h"
  8. #include "../include/linux/ITrustedCameraDriver.h"
  9. #include "../include/linux/CTrustedCameraDriver.h"
  10. #include "../include/linux/IClientEnv.h"
  11. #define SMMU_PROXY_MAX_DEVS 1
  12. static dev_t smmu_proxy_dev_no;
  13. static struct class *smmu_proxy_class;
  14. static struct cdev smmu_proxy_char_dev;
  15. static struct csf_version cached_csf_version;
  16. int smmu_proxy_get_csf_version(struct csf_version *csf_version)
  17. {
  18. int ret;
  19. struct Object client_env = {0};
  20. struct Object sc_object;
  21. /* Assumption is that cached_csf_version.arch_ver !=0 ==> other vals are set */
  22. if (cached_csf_version.arch_ver != 0) {
  23. csf_version->arch_ver = cached_csf_version.arch_ver;
  24. csf_version->max_ver = cached_csf_version.max_ver;
  25. csf_version->min_ver = cached_csf_version.min_ver;
  26. return 0;
  27. }
  28. ret = get_client_env_object(&client_env);
  29. if (ret) {
  30. pr_err("%s: Failed to get env object rc: %d\n", __func__,
  31. ret);
  32. return ret;
  33. }
  34. ret = IClientEnv_open(client_env, CTrustedCameraDriver_UID, &sc_object);
  35. if (ret) {
  36. pr_err("%s: Failed to get seccam object rc: %d\n", __func__,
  37. ret);
  38. return ret;
  39. }
  40. ret = ITrustedCameraDriver_getVersion(sc_object, &csf_version->arch_ver,
  41. &csf_version->max_ver,
  42. &csf_version->min_ver);
  43. Object_release(sc_object);
  44. Object_release(client_env);
  45. /*
  46. * Once we set cached_csf_version.arch_ver, concurrent callers will get
  47. * the cached value.
  48. */
  49. cached_csf_version.min_ver = csf_version->min_ver;
  50. cached_csf_version.max_ver = csf_version->max_ver;
  51. cached_csf_version.arch_ver = csf_version->arch_ver;
  52. return ret;
  53. }
  54. EXPORT_SYMBOL(smmu_proxy_get_csf_version);
  55. int smmu_proxy_create_dev(const struct file_operations *fops)
  56. {
  57. int ret;
  58. struct device *class_dev;
  59. ret = alloc_chrdev_region(&smmu_proxy_dev_no, 0, SMMU_PROXY_MAX_DEVS,
  60. "qti-smmu-proxy");
  61. if (ret < 0)
  62. return ret;
  63. smmu_proxy_class = class_create(THIS_MODULE, "qti-smmu-proxy");
  64. if (IS_ERR(smmu_proxy_class)) {
  65. ret = PTR_ERR(smmu_proxy_class);
  66. goto err_class_create;
  67. }
  68. cdev_init(&smmu_proxy_char_dev, fops);
  69. ret = cdev_add(&smmu_proxy_char_dev, smmu_proxy_dev_no,
  70. SMMU_PROXY_MAX_DEVS);
  71. if (ret < 0)
  72. goto err_cdev_add;
  73. class_dev = device_create(smmu_proxy_class, NULL, smmu_proxy_dev_no, NULL,
  74. "qti-smmu-proxy");
  75. if (IS_ERR(class_dev)) {
  76. ret = PTR_ERR(class_dev);
  77. goto err_dev_create;
  78. }
  79. return 0;
  80. err_dev_create:
  81. cdev_del(&smmu_proxy_char_dev);
  82. err_cdev_add:
  83. class_destroy(smmu_proxy_class);
  84. err_class_create:
  85. unregister_chrdev_region(smmu_proxy_dev_no, SMMU_PROXY_MAX_DEVS);
  86. return ret;
  87. }