adreno_sysfs.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _ADRENO_SYSFS_H_
  6. #define _ADRENO_SYSFS_H_
  7. /*
  8. * struct adreno_sysfs_attribute_u32 - Container for accessing and modifying
  9. * integers in kgsl via sysfs
  10. */
  11. struct adreno_sysfs_attribute_u32 {
  12. /** #attr: The device attribute corresponding to the sysfs node */
  13. struct device_attribute attr;
  14. /** @show: Function to show the value of the integer */
  15. u32 (*show)(struct adreno_device *adreno_dev);
  16. /** @store: Function to store the value of the integer */
  17. int (*store)(struct adreno_device *adreno_dev, u32 val);
  18. };
  19. /*
  20. * struct adreno_sysfs_attribute_bool - Container for accessing and modifying
  21. * booleans in kgsl via sysfs
  22. */
  23. struct adreno_sysfs_attribute_bool {
  24. /** #attr: The device attribute corresponding to the sysfs node */
  25. struct device_attribute attr;
  26. /** @show: Function to show the value of the boolean */
  27. bool (*show)(struct adreno_device *adreno_dev);
  28. /** @store: Function to store the value of the boolean */
  29. int (*store)(struct adreno_device *adreno_dev, bool val);
  30. };
  31. /* Helper function to modify an integer in kgsl */
  32. ssize_t adreno_sysfs_store_u32(struct device *dev,
  33. struct device_attribute *attr, const char *buf, size_t count);
  34. /* Helper function to read an integer in kgsl */
  35. ssize_t adreno_sysfs_show_u32(struct device *dev,
  36. struct device_attribute *attr, char *buf);
  37. /* Helper function to modify a boolean in kgsl */
  38. ssize_t adreno_sysfs_store_bool(struct device *dev,
  39. struct device_attribute *attr, const char *buf, size_t count);
  40. /* Helper function to read a boolean in kgsl */
  41. ssize_t adreno_sysfs_show_bool(struct device *dev,
  42. struct device_attribute *attr, char *buf);
  43. #define ADRENO_SYSFS_BOOL(_name) \
  44. const struct adreno_sysfs_attribute_bool adreno_attr_##_name = { \
  45. .attr = __ATTR(_name, 0644, adreno_sysfs_show_bool, \
  46. adreno_sysfs_store_bool), \
  47. .show = _ ## _name ## _show, \
  48. .store = _ ## _name ## _store, \
  49. }
  50. #define ADRENO_SYSFS_RO_BOOL(_name) \
  51. const struct adreno_sysfs_attribute_bool adreno_attr_##_name = { \
  52. .attr = __ATTR(_name, 0444, adreno_sysfs_show_bool, NULL), \
  53. .show = _ ## _name ## _show, \
  54. }
  55. #define ADRENO_SYSFS_U32(_name) \
  56. const struct adreno_sysfs_attribute_u32 adreno_attr_##_name = { \
  57. .attr = __ATTR(_name, 0644, adreno_sysfs_show_u32, \
  58. adreno_sysfs_store_u32), \
  59. .show = _ ## _name ## _show, \
  60. .store = _ ## _name ## _store, \
  61. }
  62. #define ADRENO_SYSFS_RO_U32(_name) \
  63. const struct adreno_sysfs_attribute_u32 adreno_attr_##_name = { \
  64. .attr = __ATTR(_name, 0444, adreno_sysfs_show_u32, NULL), \
  65. .show = _ ## _name ## _show, \
  66. }
  67. #endif