gpu_sysfs_target_kgsl.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. #include "gpu_sysfs_header.h"
  2. /* *
  3. * *********************************************************************
  4. * Path defines for all the sysfs files.
  5. * *********************************************************************
  6. * */
  7. #define GPU_MIN_CLOCK "/sys/devices/fdb00000.qcom,kgsl-3d0/kgsl/kgsl-3d0/devfreq/min_freq"
  8. #define GPU_MAX_CLOCK "/sys/devices/fdb00000.qcom,kgsl-3d0/kgsl/kgsl-3d0/devfreq/max_freq"
  9. #define GPU_BUSY "/sys/devices/fdb00000.qcom,kgsl-3d0/kgsl/kgsl-3d0/gpubusy"
  10. #define GPU_VOL "/sys/devices/fdb00000.qcom,kgsl-3d0/kgsl/kgsl-3d0/vol"
  11. #define GPU_FREQ "/sys/kernel/debug/clk/oxili_gfx3d_clk/measure"
  12. #define GPU_FREQ_TABLE "/sys/devices/fdb00000.qcom,kgsl-3d0/kgsl/kgsl-3d0/gpu_available_frequencies"
  13. #define GPU_GOVERNOR "/sys/devices/fdb00000.qcom,kgsl-3d0/kgsl/kgsl-3d0/devfreq/governor"
  14. #define GPU_AVAIL_GOVERNOR "/sys/devices/fdb00000.qcom,kgsl-3d0/kgsl/kgsl-3d0/devfreq/available_governors"
  15. /*#define GPU_CORES_CONFIG "/sys/devices/fdb00000.qcom,kgsl-3d0/kgsl/kgsl-3d0/core_mask" -- Not available from sysfs. */
  16. #define GPU_TMU "/sys/devices/fdb00000.qcom,kgsl-3d0/kgsl/kgsl-3d0/thermal_pwrlevel"
  17. /*#define GPU_MODEL "/sys/devices/fdb00000.qcom,kgsl-3d0/kgsl/kgsl-3d0/modalias" -- Not available from sysfs. */
  18. #define GPU_VERSION "/sys/devices/fdb00000.qcom,kgsl-3d0/kgsl/kgsl-3d0/uevent"
  19. /*#define GPU_MEM "/sys/devices/fdb00000.qcom,kgsl-3d0/kgsl/kgsl-3d0/gpu_mem" -- Not available directly from sysfs. */
  20. #define QUALCOMM_SYSFS_GPU_FPS "/sys/devices/platform/gpusysfs/fps"
  21. /*
  22. * atoi function ----
  23. * Taken from drivers/video/msm/external_common.c
  24. * from Kernel source for KLTE device.
  25. * */
  26. static int atoi_ignore_space(const char *name)
  27. {
  28. int val = 0;
  29. for (;; name++) {
  30. switch (*name) {
  31. case '0' ... '9':
  32. val = 10*val+(*name-'0');
  33. break;
  34. case ' ':
  35. break;
  36. default:
  37. return val;
  38. }
  39. }
  40. }
  41. /* *
  42. * *********************************************************************
  43. * Device ATTR functions. Will be called when read from sysfs.
  44. * *********************************************************************
  45. * */
  46. ssize_t gpu_min_clock_show(struct device *dev, struct device_attribute *attr, char *buf)
  47. {
  48. char input_buffer[INPUT_BUFFER_SIZE_32];
  49. int status = 0;
  50. status = open_file_and_read_buffer(GPU_MIN_CLOCK, input_buffer, INPUT_BUFFER_SIZE_32);
  51. if (status == SRUK_TRUE)
  52. {
  53. return sprintf(buf, "%s", input_buffer);
  54. }
  55. else
  56. {
  57. return sprintf(buf, "-1");
  58. }
  59. }
  60. ssize_t gpu_max_clock_show(struct device *dev, struct device_attribute *attr, char *buf)
  61. {
  62. char input_buffer[INPUT_BUFFER_SIZE_32];
  63. int status = 0;
  64. status = open_file_and_read_buffer(GPU_MAX_CLOCK, input_buffer, INPUT_BUFFER_SIZE_32);
  65. if (status == SRUK_TRUE)
  66. {
  67. return sprintf(buf, "%s", input_buffer);
  68. }
  69. else
  70. {
  71. return sprintf(buf, "-1");
  72. }
  73. }
  74. ssize_t gpu_busy_show(struct device *dev, struct device_attribute *attr, char *buf)
  75. {
  76. char time_consumed_str[INPUT_BUFFER_SIZE_32] = {0};
  77. char time_elapsed_str[INPUT_BUFFER_SIZE_32] = {0};
  78. unsigned int time_consumed = 0;
  79. unsigned int time_elapsed = 0;
  80. char input_buffer[INPUT_BUFFER_SIZE_32];
  81. int status = 0;
  82. status = open_file_and_read_buffer(GPU_MAX_CLOCK, input_buffer, INPUT_BUFFER_SIZE_32);
  83. if (status != SRUK_TRUE)
  84. {
  85. return sprintf(buf, "-1");
  86. }
  87. /* ************************************ */
  88. /* Parse input to find utilization ratio.
  89. * This is target specific.
  90. * kgsl drive outputs utilzation in terms of
  91. * elapsed time using "%7d %7d"
  92. * */
  93. /* ************************************ */
  94. strncpy(time_consumed_str, input_buffer, 7);
  95. strncpy(time_elapsed_str, input_buffer+8, 7);
  96. time_consumed = atoi_ignore_space(time_consumed_str);
  97. time_elapsed = atoi_ignore_space(time_elapsed_str);
  98. return sprintf(buf, "%d\n", ((time_consumed*100)/time_elapsed));
  99. }
  100. ssize_t gpu_vol_show(struct device *dev, struct device_attribute *attr, char *buf)
  101. {
  102. return sprintf(buf, "gpu_voltage -- Not available.\n");
  103. }
  104. ssize_t gpu_freq_show(struct device *dev, struct device_attribute *attr, char *buf)
  105. {
  106. char input_buffer[INPUT_BUFFER_SIZE_32];
  107. int status = 0;
  108. status = open_file_and_read_buffer(GPU_FREQ, input_buffer, INPUT_BUFFER_SIZE_32);
  109. if (status == SRUK_TRUE)
  110. {
  111. return sprintf(buf, "%s", input_buffer);
  112. }
  113. else
  114. {
  115. return sprintf(buf, "-1");
  116. }
  117. }
  118. ssize_t gpu_freq_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  119. {
  120. pr_info("SRUK ----------- %s -- %d", __FUNCTION__, __LINE__);
  121. if (open_file_and_write_buffer(GPU_GOVERNOR, "performance", strlen("performance")) == 0)
  122. {
  123. pr_info("SRUK ----------- %s -- %d", __FUNCTION__, __LINE__);
  124. return 0;
  125. }
  126. /*
  127. pr_info("SRUK ----------- %s -- %d", __FUNCTION__, __LINE__);
  128. if (open_file_and_write_buffer(GPU_FREQ, buf, strlen(buf)) == 0)
  129. {
  130. pr_info("SRUK ----------- %s -- %d", __FUNCTION__, __LINE__);
  131. return 0;
  132. }
  133. */
  134. pr_info("SRUK ----------- %s -- %d", __FUNCTION__, __LINE__);
  135. /* Return success status. */
  136. return count;
  137. }
  138. ssize_t gpu_freq_table_show(struct device *dev, struct device_attribute *attr, char *buf)
  139. {
  140. char input_buffer[INPUT_BUFFER_SIZE_128];
  141. int status = 0;
  142. status = open_file_and_read_buffer(GPU_FREQ_TABLE, input_buffer, INPUT_BUFFER_SIZE_128);
  143. if (status == SRUK_TRUE)
  144. {
  145. return sprintf(buf, "%s", input_buffer);
  146. }
  147. else
  148. {
  149. return sprintf(buf, "-1");
  150. }
  151. }
  152. ssize_t gpu_governor_show(struct device *dev, struct device_attribute *attr, char *buf)
  153. {
  154. char input_buffer[INPUT_BUFFER_SIZE_32];
  155. int status = 0;
  156. status = open_file_and_read_buffer(GPU_GOVERNOR, input_buffer, INPUT_BUFFER_SIZE_32);
  157. if (status == SRUK_TRUE)
  158. {
  159. return sprintf(buf, "%s", input_buffer);
  160. }
  161. else
  162. {
  163. return sprintf(buf, "-1");
  164. }
  165. }
  166. ssize_t gpu_governor_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  167. {
  168. pr_info("SRUK ----------- %s -- %d", __FUNCTION__, __LINE__);
  169. if (open_file_and_write_buffer(GPU_GOVERNOR, buf, strlen(buf)) == 0)
  170. {
  171. pr_info("SRUK ----------- %s -- %d", __FUNCTION__, __LINE__);
  172. return 0;
  173. }
  174. pr_info("SRUK ----------- %s -- %d", __FUNCTION__, __LINE__);
  175. /* Return success status. */
  176. return count;
  177. }
  178. ssize_t gpu_available_governor_show(struct device *dev, struct device_attribute *attr, char *buf)
  179. {
  180. char input_buffer[INPUT_BUFFER_SIZE_256];
  181. int status = 0;
  182. status = open_file_and_read_buffer(GPU_AVAIL_GOVERNOR, input_buffer, INPUT_BUFFER_SIZE_256);
  183. if (status == SRUK_TRUE)
  184. {
  185. return sprintf(buf, "%s", input_buffer);
  186. }
  187. else
  188. {
  189. return sprintf(buf, "-1");
  190. }
  191. }
  192. ssize_t gpu_cores_config_show(struct device *dev, struct device_attribute *attr, char *buf)
  193. {
  194. return sprintf(buf, "gpu_core_config -- Not available.\n");
  195. }
  196. ssize_t gpu_tmu_show(struct device *dev, struct device_attribute *attr, char *buf)
  197. {
  198. char input_buffer[INPUT_BUFFER_SIZE_32];
  199. int status = 0;
  200. status = open_file_and_read_buffer(GPU_TMU, input_buffer, INPUT_BUFFER_SIZE_32);
  201. if (status == SRUK_TRUE)
  202. {
  203. return sprintf(buf, "%s", input_buffer);
  204. }
  205. else
  206. {
  207. return sprintf(buf, "-1");
  208. }
  209. }
  210. ssize_t gpu_model_show(struct device *dev, struct device_attribute *attr, char *buf)
  211. {
  212. char input_buffer[INPUT_BUFFER_SIZE_128];
  213. int status = 0;
  214. char *parse_pointer = input_buffer;
  215. int char_counter = 0, equal_char_counter = 0;
  216. status = open_file_and_read_buffer(GPU_VERSION, input_buffer, INPUT_BUFFER_SIZE_128);
  217. if (status != SRUK_TRUE)
  218. {
  219. return sprintf(buf, "-1");
  220. }
  221. /* ************************************ */
  222. /* Parse input to find gpu version.
  223. * This is target specific.
  224. * The driver gives information in following
  225. * format:
  226. * MAJOR=242
  227. * MINOR=0
  228. * DEVNAME=kgsl-3d0
  229. * */
  230. /* ************************************ */
  231. while (*parse_pointer != '\0')
  232. {
  233. /* Look for '='. */
  234. if (*parse_pointer == '=')
  235. {
  236. equal_char_counter++;
  237. }
  238. /* */
  239. parse_pointer++;
  240. char_counter++;
  241. if (equal_char_counter == 3)
  242. {
  243. break;
  244. }
  245. }
  246. /* Copy the model string to the output string.*/
  247. return sprintf(buf, "%s\n", input_buffer+char_counter);
  248. }
  249. ssize_t gpu_version_show(struct device *dev, struct device_attribute *attr, char *buf)
  250. {
  251. char version_major_str[INPUT_BUFFER_SIZE_16] = {0};
  252. char version_minor_str[INPUT_BUFFER_SIZE_16] = {0};
  253. unsigned int version_major = 0, version_minor = 0;
  254. char input_buffer[INPUT_BUFFER_SIZE_128];
  255. int status = 0;
  256. status = open_file_and_read_buffer(GPU_VERSION, input_buffer, INPUT_BUFFER_SIZE_128);
  257. if (status != SRUK_TRUE)
  258. {
  259. return sprintf(buf, "-1");
  260. }
  261. /* ************************************ */
  262. /* Parse input to find gpu version.
  263. * This is target specific.
  264. * The driver gives information in following
  265. * format:
  266. * MAJOR=242
  267. * MINOR=0
  268. * DEVNAME=kgsl-3d0
  269. * */
  270. /* ************************************ */
  271. strncpy(version_major_str, input_buffer+6, 5);
  272. strncpy(version_minor_str, input_buffer+17, 5);
  273. version_major = atoi_ignore_space(version_major_str);
  274. version_minor = atoi_ignore_space(version_minor_str);
  275. return sprintf(buf, "%d.%d\n", version_major, version_minor);
  276. }
  277. ssize_t gpu_mem_show(struct device *dev, struct device_attribute *attr, char *buf)
  278. {
  279. return sprintf(buf, "gpu_mem -- Not available.\n");
  280. }
  281. char global_fps_string[INPUT_BUFFER_SIZE_32];
  282. ssize_t fps_show(struct device *dev, struct device_attribute *attr, char *buf)
  283. {
  284. return sprintf(buf, "%s", global_fps_string);
  285. }
  286. ssize_t fps_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  287. {
  288. pr_info("SRUK ----------- %s -- %d", __FUNCTION__, __LINE__);
  289. if (buf != NULL)
  290. {
  291. snprintf(global_fps_string,sizeof(global_fps_string),"%s", buf);
  292. }
  293. else
  294. {
  295. sprintf(global_fps_string,"0");
  296. }
  297. /* Return success status. */
  298. return count;
  299. }