i915_sysfs.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /*
  2. * Copyright © 2012 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Ben Widawsky <ben@bwidawsk.net>
  25. *
  26. */
  27. #include <linux/device.h>
  28. #include <linux/module.h>
  29. #include <linux/stat.h>
  30. #include <linux/sysfs.h>
  31. #include "intel_drv.h"
  32. #include "i915_drv.h"
  33. #define dev_to_drm_minor(d) dev_get_drvdata((d))
  34. #ifdef CONFIG_PM
  35. static u32 calc_residency(struct drm_device *dev, const u32 reg)
  36. {
  37. struct drm_i915_private *dev_priv = dev->dev_private;
  38. u64 raw_time; /* 32b value may overflow during fixed point math */
  39. u64 units = 128ULL, div = 100000ULL;
  40. u32 ret;
  41. if (!intel_enable_rc6(dev))
  42. return 0;
  43. intel_runtime_pm_get(dev_priv);
  44. /* On VLV and CHV, residency time is in CZ units rather than 1.28us */
  45. if (IS_VALLEYVIEW(dev)) {
  46. units = 1;
  47. div = dev_priv->czclk_freq;
  48. if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)
  49. units <<= 8;
  50. } else if (IS_BROXTON(dev)) {
  51. units = 1;
  52. div = 1200; /* 833.33ns */
  53. }
  54. raw_time = I915_READ(reg) * units;
  55. ret = DIV_ROUND_UP_ULL(raw_time, div);
  56. intel_runtime_pm_put(dev_priv);
  57. return ret;
  58. }
  59. static ssize_t
  60. show_rc6_mask(struct device *kdev, struct device_attribute *attr, char *buf)
  61. {
  62. struct drm_minor *dminor = dev_to_drm_minor(kdev);
  63. return snprintf(buf, PAGE_SIZE, "%x\n", intel_enable_rc6(dminor->dev));
  64. }
  65. static ssize_t
  66. show_rc6_ms(struct device *kdev, struct device_attribute *attr, char *buf)
  67. {
  68. struct drm_minor *dminor = dev_get_drvdata(kdev);
  69. u32 rc6_residency = calc_residency(dminor->dev, GEN6_GT_GFX_RC6);
  70. return snprintf(buf, PAGE_SIZE, "%u\n", rc6_residency);
  71. }
  72. static ssize_t
  73. show_rc6p_ms(struct device *kdev, struct device_attribute *attr, char *buf)
  74. {
  75. struct drm_minor *dminor = dev_to_drm_minor(kdev);
  76. u32 rc6p_residency = calc_residency(dminor->dev, GEN6_GT_GFX_RC6p);
  77. return snprintf(buf, PAGE_SIZE, "%u\n", rc6p_residency);
  78. }
  79. static ssize_t
  80. show_rc6pp_ms(struct device *kdev, struct device_attribute *attr, char *buf)
  81. {
  82. struct drm_minor *dminor = dev_to_drm_minor(kdev);
  83. u32 rc6pp_residency = calc_residency(dminor->dev, GEN6_GT_GFX_RC6pp);
  84. return snprintf(buf, PAGE_SIZE, "%u\n", rc6pp_residency);
  85. }
  86. static ssize_t
  87. show_media_rc6_ms(struct device *kdev, struct device_attribute *attr, char *buf)
  88. {
  89. struct drm_minor *dminor = dev_get_drvdata(kdev);
  90. u32 rc6_residency = calc_residency(dminor->dev, VLV_GT_MEDIA_RC6);
  91. return snprintf(buf, PAGE_SIZE, "%u\n", rc6_residency);
  92. }
  93. static DEVICE_ATTR(rc6_enable, S_IRUGO, show_rc6_mask, NULL);
  94. static DEVICE_ATTR(rc6_residency_ms, S_IRUGO, show_rc6_ms, NULL);
  95. static DEVICE_ATTR(rc6p_residency_ms, S_IRUGO, show_rc6p_ms, NULL);
  96. static DEVICE_ATTR(rc6pp_residency_ms, S_IRUGO, show_rc6pp_ms, NULL);
  97. static DEVICE_ATTR(media_rc6_residency_ms, S_IRUGO, show_media_rc6_ms, NULL);
  98. static struct attribute *rc6_attrs[] = {
  99. &dev_attr_rc6_enable.attr,
  100. &dev_attr_rc6_residency_ms.attr,
  101. NULL
  102. };
  103. static struct attribute_group rc6_attr_group = {
  104. .name = power_group_name,
  105. .attrs = rc6_attrs
  106. };
  107. static struct attribute *rc6p_attrs[] = {
  108. &dev_attr_rc6p_residency_ms.attr,
  109. &dev_attr_rc6pp_residency_ms.attr,
  110. NULL
  111. };
  112. static struct attribute_group rc6p_attr_group = {
  113. .name = power_group_name,
  114. .attrs = rc6p_attrs
  115. };
  116. static struct attribute *media_rc6_attrs[] = {
  117. &dev_attr_media_rc6_residency_ms.attr,
  118. NULL
  119. };
  120. static struct attribute_group media_rc6_attr_group = {
  121. .name = power_group_name,
  122. .attrs = media_rc6_attrs
  123. };
  124. #endif
  125. static int l3_access_valid(struct drm_device *dev, loff_t offset)
  126. {
  127. if (!HAS_L3_DPF(dev))
  128. return -EPERM;
  129. if (offset % 4 != 0)
  130. return -EINVAL;
  131. if (offset >= GEN7_L3LOG_SIZE)
  132. return -ENXIO;
  133. return 0;
  134. }
  135. static ssize_t
  136. i915_l3_read(struct file *filp, struct kobject *kobj,
  137. struct bin_attribute *attr, char *buf,
  138. loff_t offset, size_t count)
  139. {
  140. struct device *dev = container_of(kobj, struct device, kobj);
  141. struct drm_minor *dminor = dev_to_drm_minor(dev);
  142. struct drm_device *drm_dev = dminor->dev;
  143. struct drm_i915_private *dev_priv = drm_dev->dev_private;
  144. int slice = (int)(uintptr_t)attr->private;
  145. int ret;
  146. count = round_down(count, 4);
  147. ret = l3_access_valid(drm_dev, offset);
  148. if (ret)
  149. return ret;
  150. count = min_t(size_t, GEN7_L3LOG_SIZE - offset, count);
  151. ret = i915_mutex_lock_interruptible(drm_dev);
  152. if (ret)
  153. return ret;
  154. if (dev_priv->l3_parity.remap_info[slice])
  155. memcpy(buf,
  156. dev_priv->l3_parity.remap_info[slice] + (offset/4),
  157. count);
  158. else
  159. memset(buf, 0, count);
  160. mutex_unlock(&drm_dev->struct_mutex);
  161. return count;
  162. }
  163. static ssize_t
  164. i915_l3_write(struct file *filp, struct kobject *kobj,
  165. struct bin_attribute *attr, char *buf,
  166. loff_t offset, size_t count)
  167. {
  168. struct device *dev = container_of(kobj, struct device, kobj);
  169. struct drm_minor *dminor = dev_to_drm_minor(dev);
  170. struct drm_device *drm_dev = dminor->dev;
  171. struct drm_i915_private *dev_priv = drm_dev->dev_private;
  172. struct intel_context *ctx;
  173. u32 *temp = NULL; /* Just here to make handling failures easy */
  174. int slice = (int)(uintptr_t)attr->private;
  175. int ret;
  176. if (!HAS_HW_CONTEXTS(drm_dev))
  177. return -ENXIO;
  178. ret = l3_access_valid(drm_dev, offset);
  179. if (ret)
  180. return ret;
  181. ret = i915_mutex_lock_interruptible(drm_dev);
  182. if (ret)
  183. return ret;
  184. if (!dev_priv->l3_parity.remap_info[slice]) {
  185. temp = kzalloc(GEN7_L3LOG_SIZE, GFP_KERNEL);
  186. if (!temp) {
  187. mutex_unlock(&drm_dev->struct_mutex);
  188. return -ENOMEM;
  189. }
  190. }
  191. ret = i915_gpu_idle(drm_dev);
  192. if (ret) {
  193. kfree(temp);
  194. mutex_unlock(&drm_dev->struct_mutex);
  195. return ret;
  196. }
  197. /* TODO: Ideally we really want a GPU reset here to make sure errors
  198. * aren't propagated. Since I cannot find a stable way to reset the GPU
  199. * at this point it is left as a TODO.
  200. */
  201. if (temp)
  202. dev_priv->l3_parity.remap_info[slice] = temp;
  203. memcpy(dev_priv->l3_parity.remap_info[slice] + (offset/4), buf, count);
  204. /* NB: We defer the remapping until we switch to the context */
  205. list_for_each_entry(ctx, &dev_priv->context_list, link)
  206. ctx->remap_slice |= (1<<slice);
  207. mutex_unlock(&drm_dev->struct_mutex);
  208. return count;
  209. }
  210. static struct bin_attribute dpf_attrs = {
  211. .attr = {.name = "l3_parity", .mode = (S_IRUSR | S_IWUSR)},
  212. .size = GEN7_L3LOG_SIZE,
  213. .read = i915_l3_read,
  214. .write = i915_l3_write,
  215. .mmap = NULL,
  216. .private = (void *)0
  217. };
  218. static struct bin_attribute dpf_attrs_1 = {
  219. .attr = {.name = "l3_parity_slice_1", .mode = (S_IRUSR | S_IWUSR)},
  220. .size = GEN7_L3LOG_SIZE,
  221. .read = i915_l3_read,
  222. .write = i915_l3_write,
  223. .mmap = NULL,
  224. .private = (void *)1
  225. };
  226. static ssize_t gt_act_freq_mhz_show(struct device *kdev,
  227. struct device_attribute *attr, char *buf)
  228. {
  229. struct drm_minor *minor = dev_to_drm_minor(kdev);
  230. struct drm_device *dev = minor->dev;
  231. struct drm_i915_private *dev_priv = dev->dev_private;
  232. int ret;
  233. flush_delayed_work(&dev_priv->rps.delayed_resume_work);
  234. intel_runtime_pm_get(dev_priv);
  235. mutex_lock(&dev_priv->rps.hw_lock);
  236. if (IS_VALLEYVIEW(dev_priv->dev)) {
  237. u32 freq;
  238. freq = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
  239. ret = intel_gpu_freq(dev_priv, (freq >> 8) & 0xff);
  240. } else {
  241. u32 rpstat = I915_READ(GEN6_RPSTAT1);
  242. if (IS_GEN9(dev_priv))
  243. ret = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
  244. else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  245. ret = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
  246. else
  247. ret = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
  248. ret = intel_gpu_freq(dev_priv, ret);
  249. }
  250. mutex_unlock(&dev_priv->rps.hw_lock);
  251. intel_runtime_pm_put(dev_priv);
  252. return snprintf(buf, PAGE_SIZE, "%d\n", ret);
  253. }
  254. static ssize_t gt_cur_freq_mhz_show(struct device *kdev,
  255. struct device_attribute *attr, char *buf)
  256. {
  257. struct drm_minor *minor = dev_to_drm_minor(kdev);
  258. struct drm_device *dev = minor->dev;
  259. struct drm_i915_private *dev_priv = dev->dev_private;
  260. int ret;
  261. flush_delayed_work(&dev_priv->rps.delayed_resume_work);
  262. intel_runtime_pm_get(dev_priv);
  263. mutex_lock(&dev_priv->rps.hw_lock);
  264. ret = intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq);
  265. mutex_unlock(&dev_priv->rps.hw_lock);
  266. intel_runtime_pm_put(dev_priv);
  267. return snprintf(buf, PAGE_SIZE, "%d\n", ret);
  268. }
  269. static ssize_t vlv_rpe_freq_mhz_show(struct device *kdev,
  270. struct device_attribute *attr, char *buf)
  271. {
  272. struct drm_minor *minor = dev_to_drm_minor(kdev);
  273. struct drm_device *dev = minor->dev;
  274. struct drm_i915_private *dev_priv = dev->dev_private;
  275. return snprintf(buf, PAGE_SIZE,
  276. "%d\n",
  277. intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
  278. }
  279. static ssize_t gt_max_freq_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf)
  280. {
  281. struct drm_minor *minor = dev_to_drm_minor(kdev);
  282. struct drm_device *dev = minor->dev;
  283. struct drm_i915_private *dev_priv = dev->dev_private;
  284. int ret;
  285. flush_delayed_work(&dev_priv->rps.delayed_resume_work);
  286. mutex_lock(&dev_priv->rps.hw_lock);
  287. ret = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
  288. mutex_unlock(&dev_priv->rps.hw_lock);
  289. return snprintf(buf, PAGE_SIZE, "%d\n", ret);
  290. }
  291. static ssize_t gt_max_freq_mhz_store(struct device *kdev,
  292. struct device_attribute *attr,
  293. const char *buf, size_t count)
  294. {
  295. struct drm_minor *minor = dev_to_drm_minor(kdev);
  296. struct drm_device *dev = minor->dev;
  297. struct drm_i915_private *dev_priv = dev->dev_private;
  298. u32 val;
  299. ssize_t ret;
  300. ret = kstrtou32(buf, 0, &val);
  301. if (ret)
  302. return ret;
  303. flush_delayed_work(&dev_priv->rps.delayed_resume_work);
  304. mutex_lock(&dev_priv->rps.hw_lock);
  305. val = intel_freq_opcode(dev_priv, val);
  306. if (val < dev_priv->rps.min_freq ||
  307. val > dev_priv->rps.max_freq ||
  308. val < dev_priv->rps.min_freq_softlimit) {
  309. mutex_unlock(&dev_priv->rps.hw_lock);
  310. return -EINVAL;
  311. }
  312. if (val > dev_priv->rps.rp0_freq)
  313. DRM_DEBUG("User requested overclocking to %d\n",
  314. intel_gpu_freq(dev_priv, val));
  315. dev_priv->rps.max_freq_softlimit = val;
  316. val = clamp_t(int, dev_priv->rps.cur_freq,
  317. dev_priv->rps.min_freq_softlimit,
  318. dev_priv->rps.max_freq_softlimit);
  319. /* We still need *_set_rps to process the new max_delay and
  320. * update the interrupt limits and PMINTRMSK even though
  321. * frequency request may be unchanged. */
  322. intel_set_rps(dev, val);
  323. mutex_unlock(&dev_priv->rps.hw_lock);
  324. return count;
  325. }
  326. static ssize_t gt_min_freq_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf)
  327. {
  328. struct drm_minor *minor = dev_to_drm_minor(kdev);
  329. struct drm_device *dev = minor->dev;
  330. struct drm_i915_private *dev_priv = dev->dev_private;
  331. int ret;
  332. flush_delayed_work(&dev_priv->rps.delayed_resume_work);
  333. mutex_lock(&dev_priv->rps.hw_lock);
  334. ret = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
  335. mutex_unlock(&dev_priv->rps.hw_lock);
  336. return snprintf(buf, PAGE_SIZE, "%d\n", ret);
  337. }
  338. static ssize_t gt_min_freq_mhz_store(struct device *kdev,
  339. struct device_attribute *attr,
  340. const char *buf, size_t count)
  341. {
  342. struct drm_minor *minor = dev_to_drm_minor(kdev);
  343. struct drm_device *dev = minor->dev;
  344. struct drm_i915_private *dev_priv = dev->dev_private;
  345. u32 val;
  346. ssize_t ret;
  347. ret = kstrtou32(buf, 0, &val);
  348. if (ret)
  349. return ret;
  350. flush_delayed_work(&dev_priv->rps.delayed_resume_work);
  351. mutex_lock(&dev_priv->rps.hw_lock);
  352. val = intel_freq_opcode(dev_priv, val);
  353. if (val < dev_priv->rps.min_freq ||
  354. val > dev_priv->rps.max_freq ||
  355. val > dev_priv->rps.max_freq_softlimit) {
  356. mutex_unlock(&dev_priv->rps.hw_lock);
  357. return -EINVAL;
  358. }
  359. dev_priv->rps.min_freq_softlimit = val;
  360. val = clamp_t(int, dev_priv->rps.cur_freq,
  361. dev_priv->rps.min_freq_softlimit,
  362. dev_priv->rps.max_freq_softlimit);
  363. /* We still need *_set_rps to process the new min_delay and
  364. * update the interrupt limits and PMINTRMSK even though
  365. * frequency request may be unchanged. */
  366. intel_set_rps(dev, val);
  367. mutex_unlock(&dev_priv->rps.hw_lock);
  368. return count;
  369. }
  370. static DEVICE_ATTR(gt_act_freq_mhz, S_IRUGO, gt_act_freq_mhz_show, NULL);
  371. static DEVICE_ATTR(gt_cur_freq_mhz, S_IRUGO, gt_cur_freq_mhz_show, NULL);
  372. static DEVICE_ATTR(gt_max_freq_mhz, S_IRUGO | S_IWUSR, gt_max_freq_mhz_show, gt_max_freq_mhz_store);
  373. static DEVICE_ATTR(gt_min_freq_mhz, S_IRUGO | S_IWUSR, gt_min_freq_mhz_show, gt_min_freq_mhz_store);
  374. static DEVICE_ATTR(vlv_rpe_freq_mhz, S_IRUGO, vlv_rpe_freq_mhz_show, NULL);
  375. static ssize_t gt_rp_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf);
  376. static DEVICE_ATTR(gt_RP0_freq_mhz, S_IRUGO, gt_rp_mhz_show, NULL);
  377. static DEVICE_ATTR(gt_RP1_freq_mhz, S_IRUGO, gt_rp_mhz_show, NULL);
  378. static DEVICE_ATTR(gt_RPn_freq_mhz, S_IRUGO, gt_rp_mhz_show, NULL);
  379. /* For now we have a static number of RP states */
  380. static ssize_t gt_rp_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf)
  381. {
  382. struct drm_minor *minor = dev_to_drm_minor(kdev);
  383. struct drm_device *dev = minor->dev;
  384. struct drm_i915_private *dev_priv = dev->dev_private;
  385. u32 val;
  386. if (attr == &dev_attr_gt_RP0_freq_mhz)
  387. val = intel_gpu_freq(dev_priv, dev_priv->rps.rp0_freq);
  388. else if (attr == &dev_attr_gt_RP1_freq_mhz)
  389. val = intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq);
  390. else if (attr == &dev_attr_gt_RPn_freq_mhz)
  391. val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq);
  392. else
  393. BUG();
  394. return snprintf(buf, PAGE_SIZE, "%d\n", val);
  395. }
  396. static const struct attribute *gen6_attrs[] = {
  397. &dev_attr_gt_act_freq_mhz.attr,
  398. &dev_attr_gt_cur_freq_mhz.attr,
  399. &dev_attr_gt_max_freq_mhz.attr,
  400. &dev_attr_gt_min_freq_mhz.attr,
  401. &dev_attr_gt_RP0_freq_mhz.attr,
  402. &dev_attr_gt_RP1_freq_mhz.attr,
  403. &dev_attr_gt_RPn_freq_mhz.attr,
  404. NULL,
  405. };
  406. static const struct attribute *vlv_attrs[] = {
  407. &dev_attr_gt_act_freq_mhz.attr,
  408. &dev_attr_gt_cur_freq_mhz.attr,
  409. &dev_attr_gt_max_freq_mhz.attr,
  410. &dev_attr_gt_min_freq_mhz.attr,
  411. &dev_attr_gt_RP0_freq_mhz.attr,
  412. &dev_attr_gt_RP1_freq_mhz.attr,
  413. &dev_attr_gt_RPn_freq_mhz.attr,
  414. &dev_attr_vlv_rpe_freq_mhz.attr,
  415. NULL,
  416. };
  417. static ssize_t error_state_read(struct file *filp, struct kobject *kobj,
  418. struct bin_attribute *attr, char *buf,
  419. loff_t off, size_t count)
  420. {
  421. struct device *kdev = container_of(kobj, struct device, kobj);
  422. struct drm_minor *minor = dev_to_drm_minor(kdev);
  423. struct drm_device *dev = minor->dev;
  424. struct i915_error_state_file_priv error_priv;
  425. struct drm_i915_error_state_buf error_str;
  426. ssize_t ret_count = 0;
  427. int ret;
  428. memset(&error_priv, 0, sizeof(error_priv));
  429. ret = i915_error_state_buf_init(&error_str, to_i915(dev), count, off);
  430. if (ret)
  431. return ret;
  432. error_priv.dev = dev;
  433. i915_error_state_get(dev, &error_priv);
  434. ret = i915_error_state_to_str(&error_str, &error_priv);
  435. if (ret)
  436. goto out;
  437. ret_count = count < error_str.bytes ? count : error_str.bytes;
  438. memcpy(buf, error_str.buf, ret_count);
  439. out:
  440. i915_error_state_put(&error_priv);
  441. i915_error_state_buf_release(&error_str);
  442. return ret ?: ret_count;
  443. }
  444. static ssize_t error_state_write(struct file *file, struct kobject *kobj,
  445. struct bin_attribute *attr, char *buf,
  446. loff_t off, size_t count)
  447. {
  448. struct device *kdev = container_of(kobj, struct device, kobj);
  449. struct drm_minor *minor = dev_to_drm_minor(kdev);
  450. struct drm_device *dev = minor->dev;
  451. int ret;
  452. DRM_DEBUG_DRIVER("Resetting error state\n");
  453. ret = mutex_lock_interruptible(&dev->struct_mutex);
  454. if (ret)
  455. return ret;
  456. i915_destroy_error_state(dev);
  457. mutex_unlock(&dev->struct_mutex);
  458. return count;
  459. }
  460. static struct bin_attribute error_state_attr = {
  461. .attr.name = "error",
  462. .attr.mode = S_IRUSR | S_IWUSR,
  463. .size = 0,
  464. .read = error_state_read,
  465. .write = error_state_write,
  466. };
  467. void i915_setup_sysfs(struct drm_device *dev)
  468. {
  469. int ret;
  470. #ifdef CONFIG_PM
  471. if (HAS_RC6(dev)) {
  472. ret = sysfs_merge_group(&dev->primary->kdev->kobj,
  473. &rc6_attr_group);
  474. if (ret)
  475. DRM_ERROR("RC6 residency sysfs setup failed\n");
  476. }
  477. if (HAS_RC6p(dev)) {
  478. ret = sysfs_merge_group(&dev->primary->kdev->kobj,
  479. &rc6p_attr_group);
  480. if (ret)
  481. DRM_ERROR("RC6p residency sysfs setup failed\n");
  482. }
  483. if (IS_VALLEYVIEW(dev)) {
  484. ret = sysfs_merge_group(&dev->primary->kdev->kobj,
  485. &media_rc6_attr_group);
  486. if (ret)
  487. DRM_ERROR("Media RC6 residency sysfs setup failed\n");
  488. }
  489. #endif
  490. if (HAS_L3_DPF(dev)) {
  491. ret = device_create_bin_file(dev->primary->kdev, &dpf_attrs);
  492. if (ret)
  493. DRM_ERROR("l3 parity sysfs setup failed\n");
  494. if (NUM_L3_SLICES(dev) > 1) {
  495. ret = device_create_bin_file(dev->primary->kdev,
  496. &dpf_attrs_1);
  497. if (ret)
  498. DRM_ERROR("l3 parity slice 1 setup failed\n");
  499. }
  500. }
  501. ret = 0;
  502. if (IS_VALLEYVIEW(dev))
  503. ret = sysfs_create_files(&dev->primary->kdev->kobj, vlv_attrs);
  504. else if (INTEL_INFO(dev)->gen >= 6)
  505. ret = sysfs_create_files(&dev->primary->kdev->kobj, gen6_attrs);
  506. if (ret)
  507. DRM_ERROR("RPS sysfs setup failed\n");
  508. ret = sysfs_create_bin_file(&dev->primary->kdev->kobj,
  509. &error_state_attr);
  510. if (ret)
  511. DRM_ERROR("error_state sysfs setup failed\n");
  512. }
  513. void i915_teardown_sysfs(struct drm_device *dev)
  514. {
  515. sysfs_remove_bin_file(&dev->primary->kdev->kobj, &error_state_attr);
  516. if (IS_VALLEYVIEW(dev))
  517. sysfs_remove_files(&dev->primary->kdev->kobj, vlv_attrs);
  518. else
  519. sysfs_remove_files(&dev->primary->kdev->kobj, gen6_attrs);
  520. device_remove_bin_file(dev->primary->kdev, &dpf_attrs_1);
  521. device_remove_bin_file(dev->primary->kdev, &dpf_attrs);
  522. #ifdef CONFIG_PM
  523. sysfs_unmerge_group(&dev->primary->kdev->kobj, &rc6_attr_group);
  524. sysfs_unmerge_group(&dev->primary->kdev->kobj, &rc6p_attr_group);
  525. #endif
  526. }