i915_sysfs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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, bias = 100ULL;
  40. if (!intel_enable_rc6(dev))
  41. return 0;
  42. /* On VLV, residency time is in CZ units rather than 1.28us */
  43. if (IS_VALLEYVIEW(dev)) {
  44. u32 clkctl2;
  45. clkctl2 = I915_READ(VLV_CLK_CTL2) >>
  46. CLK_CTL2_CZCOUNT_30NS_SHIFT;
  47. if (!clkctl2) {
  48. WARN(!clkctl2, "bogus CZ count value");
  49. return 0;
  50. }
  51. units = DIV_ROUND_UP_ULL(30ULL * bias, (u64)clkctl2);
  52. if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)
  53. units <<= 8;
  54. div = 1000000ULL * bias;
  55. }
  56. raw_time = I915_READ(reg) * units;
  57. return DIV_ROUND_UP_ULL(raw_time, div);
  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. if (IS_VALLEYVIEW(dminor->dev))
  78. rc6p_residency = 0;
  79. return snprintf(buf, PAGE_SIZE, "%u\n", rc6p_residency);
  80. }
  81. static ssize_t
  82. show_rc6pp_ms(struct device *kdev, struct device_attribute *attr, char *buf)
  83. {
  84. struct drm_minor *dminor = dev_to_drm_minor(kdev);
  85. u32 rc6pp_residency = calc_residency(dminor->dev, GEN6_GT_GFX_RC6pp);
  86. if (IS_VALLEYVIEW(dminor->dev))
  87. rc6pp_residency = 0;
  88. return snprintf(buf, PAGE_SIZE, "%u\n", rc6pp_residency);
  89. }
  90. static DEVICE_ATTR(rc6_enable, S_IRUGO, show_rc6_mask, NULL);
  91. static DEVICE_ATTR(rc6_residency_ms, S_IRUGO, show_rc6_ms, NULL);
  92. static DEVICE_ATTR(rc6p_residency_ms, S_IRUGO, show_rc6p_ms, NULL);
  93. static DEVICE_ATTR(rc6pp_residency_ms, S_IRUGO, show_rc6pp_ms, NULL);
  94. static struct attribute *rc6_attrs[] = {
  95. &dev_attr_rc6_enable.attr,
  96. &dev_attr_rc6_residency_ms.attr,
  97. &dev_attr_rc6p_residency_ms.attr,
  98. &dev_attr_rc6pp_residency_ms.attr,
  99. NULL
  100. };
  101. static struct attribute_group rc6_attr_group = {
  102. .name = power_group_name,
  103. .attrs = rc6_attrs
  104. };
  105. #endif
  106. static int l3_access_valid(struct drm_device *dev, loff_t offset)
  107. {
  108. if (!HAS_L3_DPF(dev))
  109. return -EPERM;
  110. if (offset % 4 != 0)
  111. return -EINVAL;
  112. if (offset >= GEN7_L3LOG_SIZE)
  113. return -ENXIO;
  114. return 0;
  115. }
  116. static ssize_t
  117. i915_l3_read(struct file *filp, struct kobject *kobj,
  118. struct bin_attribute *attr, char *buf,
  119. loff_t offset, size_t count)
  120. {
  121. struct device *dev = container_of(kobj, struct device, kobj);
  122. struct drm_minor *dminor = dev_to_drm_minor(dev);
  123. struct drm_device *drm_dev = dminor->dev;
  124. struct drm_i915_private *dev_priv = drm_dev->dev_private;
  125. int slice = (int)(uintptr_t)attr->private;
  126. int ret;
  127. count = round_down(count, 4);
  128. ret = l3_access_valid(drm_dev, offset);
  129. if (ret)
  130. return ret;
  131. count = min_t(size_t, GEN7_L3LOG_SIZE - offset, count);
  132. ret = i915_mutex_lock_interruptible(drm_dev);
  133. if (ret)
  134. return ret;
  135. if (dev_priv->l3_parity.remap_info[slice])
  136. memcpy(buf,
  137. dev_priv->l3_parity.remap_info[slice] + (offset/4),
  138. count);
  139. else
  140. memset(buf, 0, count);
  141. mutex_unlock(&drm_dev->struct_mutex);
  142. return count;
  143. }
  144. static ssize_t
  145. i915_l3_write(struct file *filp, struct kobject *kobj,
  146. struct bin_attribute *attr, char *buf,
  147. loff_t offset, size_t count)
  148. {
  149. struct device *dev = container_of(kobj, struct device, kobj);
  150. struct drm_minor *dminor = dev_to_drm_minor(dev);
  151. struct drm_device *drm_dev = dminor->dev;
  152. struct drm_i915_private *dev_priv = drm_dev->dev_private;
  153. struct i915_hw_context *ctx;
  154. u32 *temp = NULL; /* Just here to make handling failures easy */
  155. int slice = (int)(uintptr_t)attr->private;
  156. int ret;
  157. ret = l3_access_valid(drm_dev, offset);
  158. if (ret)
  159. return ret;
  160. if (dev_priv->hw_contexts_disabled)
  161. return -ENXIO;
  162. ret = i915_mutex_lock_interruptible(drm_dev);
  163. if (ret)
  164. return ret;
  165. if (!dev_priv->l3_parity.remap_info[slice]) {
  166. temp = kzalloc(GEN7_L3LOG_SIZE, GFP_KERNEL);
  167. if (!temp) {
  168. mutex_unlock(&drm_dev->struct_mutex);
  169. return -ENOMEM;
  170. }
  171. }
  172. ret = i915_gpu_idle(drm_dev);
  173. if (ret) {
  174. kfree(temp);
  175. mutex_unlock(&drm_dev->struct_mutex);
  176. return ret;
  177. }
  178. /* TODO: Ideally we really want a GPU reset here to make sure errors
  179. * aren't propagated. Since I cannot find a stable way to reset the GPU
  180. * at this point it is left as a TODO.
  181. */
  182. if (temp)
  183. dev_priv->l3_parity.remap_info[slice] = temp;
  184. memcpy(dev_priv->l3_parity.remap_info[slice] + (offset/4), buf, count);
  185. /* NB: We defer the remapping until we switch to the context */
  186. list_for_each_entry(ctx, &dev_priv->context_list, link)
  187. ctx->remap_slice |= (1<<slice);
  188. mutex_unlock(&drm_dev->struct_mutex);
  189. return count;
  190. }
  191. static struct bin_attribute dpf_attrs = {
  192. .attr = {.name = "l3_parity", .mode = (S_IRUSR | S_IWUSR)},
  193. .size = GEN7_L3LOG_SIZE,
  194. .read = i915_l3_read,
  195. .write = i915_l3_write,
  196. .mmap = NULL,
  197. .private = (void *)0
  198. };
  199. static struct bin_attribute dpf_attrs_1 = {
  200. .attr = {.name = "l3_parity_slice_1", .mode = (S_IRUSR | S_IWUSR)},
  201. .size = GEN7_L3LOG_SIZE,
  202. .read = i915_l3_read,
  203. .write = i915_l3_write,
  204. .mmap = NULL,
  205. .private = (void *)1
  206. };
  207. static ssize_t gt_cur_freq_mhz_show(struct device *kdev,
  208. struct device_attribute *attr, char *buf)
  209. {
  210. struct drm_minor *minor = dev_to_drm_minor(kdev);
  211. struct drm_device *dev = minor->dev;
  212. struct drm_i915_private *dev_priv = dev->dev_private;
  213. int ret;
  214. flush_delayed_work(&dev_priv->rps.delayed_resume_work);
  215. mutex_lock(&dev_priv->rps.hw_lock);
  216. if (IS_VALLEYVIEW(dev_priv->dev)) {
  217. u32 freq;
  218. freq = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
  219. ret = vlv_gpu_freq(dev_priv->mem_freq, (freq >> 8) & 0xff);
  220. } else {
  221. ret = dev_priv->rps.cur_delay * GT_FREQUENCY_MULTIPLIER;
  222. }
  223. mutex_unlock(&dev_priv->rps.hw_lock);
  224. return snprintf(buf, PAGE_SIZE, "%d\n", ret);
  225. }
  226. static ssize_t vlv_rpe_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. return snprintf(buf, PAGE_SIZE, "%d\n",
  233. vlv_gpu_freq(dev_priv->mem_freq,
  234. dev_priv->rps.rpe_delay));
  235. }
  236. static ssize_t gt_max_freq_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf)
  237. {
  238. struct drm_minor *minor = dev_to_drm_minor(kdev);
  239. struct drm_device *dev = minor->dev;
  240. struct drm_i915_private *dev_priv = dev->dev_private;
  241. int ret;
  242. flush_delayed_work(&dev_priv->rps.delayed_resume_work);
  243. mutex_lock(&dev_priv->rps.hw_lock);
  244. if (IS_VALLEYVIEW(dev_priv->dev))
  245. ret = vlv_gpu_freq(dev_priv->mem_freq, dev_priv->rps.max_delay);
  246. else
  247. ret = dev_priv->rps.max_delay * GT_FREQUENCY_MULTIPLIER;
  248. mutex_unlock(&dev_priv->rps.hw_lock);
  249. return snprintf(buf, PAGE_SIZE, "%d\n", ret);
  250. }
  251. static ssize_t gt_max_freq_mhz_store(struct device *kdev,
  252. struct device_attribute *attr,
  253. const char *buf, size_t count)
  254. {
  255. struct drm_minor *minor = dev_to_drm_minor(kdev);
  256. struct drm_device *dev = minor->dev;
  257. struct drm_i915_private *dev_priv = dev->dev_private;
  258. u32 val, rp_state_cap, hw_max, hw_min, non_oc_max;
  259. ssize_t ret;
  260. ret = kstrtou32(buf, 0, &val);
  261. if (ret)
  262. return ret;
  263. flush_delayed_work(&dev_priv->rps.delayed_resume_work);
  264. mutex_lock(&dev_priv->rps.hw_lock);
  265. if (IS_VALLEYVIEW(dev_priv->dev)) {
  266. val = vlv_freq_opcode(dev_priv->mem_freq, val);
  267. hw_max = valleyview_rps_max_freq(dev_priv);
  268. hw_min = valleyview_rps_min_freq(dev_priv);
  269. non_oc_max = hw_max;
  270. } else {
  271. val /= GT_FREQUENCY_MULTIPLIER;
  272. rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
  273. hw_max = dev_priv->rps.hw_max;
  274. non_oc_max = (rp_state_cap & 0xff);
  275. hw_min = ((rp_state_cap & 0xff0000) >> 16);
  276. }
  277. if (val < hw_min || val > hw_max ||
  278. val < dev_priv->rps.min_delay) {
  279. mutex_unlock(&dev_priv->rps.hw_lock);
  280. return -EINVAL;
  281. }
  282. if (val > non_oc_max)
  283. DRM_DEBUG("User requested overclocking to %d\n",
  284. val * GT_FREQUENCY_MULTIPLIER);
  285. if (dev_priv->rps.cur_delay > val) {
  286. if (IS_VALLEYVIEW(dev_priv->dev))
  287. valleyview_set_rps(dev_priv->dev, val);
  288. else
  289. gen6_set_rps(dev_priv->dev, val);
  290. }
  291. dev_priv->rps.max_delay = val;
  292. mutex_unlock(&dev_priv->rps.hw_lock);
  293. return count;
  294. }
  295. static ssize_t gt_min_freq_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf)
  296. {
  297. struct drm_minor *minor = dev_to_drm_minor(kdev);
  298. struct drm_device *dev = minor->dev;
  299. struct drm_i915_private *dev_priv = dev->dev_private;
  300. int ret;
  301. flush_delayed_work(&dev_priv->rps.delayed_resume_work);
  302. mutex_lock(&dev_priv->rps.hw_lock);
  303. if (IS_VALLEYVIEW(dev_priv->dev))
  304. ret = vlv_gpu_freq(dev_priv->mem_freq, dev_priv->rps.min_delay);
  305. else
  306. ret = dev_priv->rps.min_delay * GT_FREQUENCY_MULTIPLIER;
  307. mutex_unlock(&dev_priv->rps.hw_lock);
  308. return snprintf(buf, PAGE_SIZE, "%d\n", ret);
  309. }
  310. static ssize_t gt_min_freq_mhz_store(struct device *kdev,
  311. struct device_attribute *attr,
  312. const char *buf, size_t count)
  313. {
  314. struct drm_minor *minor = dev_to_drm_minor(kdev);
  315. struct drm_device *dev = minor->dev;
  316. struct drm_i915_private *dev_priv = dev->dev_private;
  317. u32 val, rp_state_cap, hw_max, hw_min;
  318. ssize_t ret;
  319. ret = kstrtou32(buf, 0, &val);
  320. if (ret)
  321. return ret;
  322. flush_delayed_work(&dev_priv->rps.delayed_resume_work);
  323. mutex_lock(&dev_priv->rps.hw_lock);
  324. if (IS_VALLEYVIEW(dev)) {
  325. val = vlv_freq_opcode(dev_priv->mem_freq, val);
  326. hw_max = valleyview_rps_max_freq(dev_priv);
  327. hw_min = valleyview_rps_min_freq(dev_priv);
  328. } else {
  329. val /= GT_FREQUENCY_MULTIPLIER;
  330. rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
  331. hw_max = dev_priv->rps.hw_max;
  332. hw_min = ((rp_state_cap & 0xff0000) >> 16);
  333. }
  334. if (val < hw_min || val > hw_max || val > dev_priv->rps.max_delay) {
  335. mutex_unlock(&dev_priv->rps.hw_lock);
  336. return -EINVAL;
  337. }
  338. if (dev_priv->rps.cur_delay < val) {
  339. if (IS_VALLEYVIEW(dev))
  340. valleyview_set_rps(dev, val);
  341. else
  342. gen6_set_rps(dev_priv->dev, val);
  343. }
  344. dev_priv->rps.min_delay = val;
  345. mutex_unlock(&dev_priv->rps.hw_lock);
  346. return count;
  347. }
  348. static DEVICE_ATTR(gt_cur_freq_mhz, S_IRUGO, gt_cur_freq_mhz_show, NULL);
  349. static DEVICE_ATTR(gt_max_freq_mhz, S_IRUGO | S_IWUSR, gt_max_freq_mhz_show, gt_max_freq_mhz_store);
  350. static DEVICE_ATTR(gt_min_freq_mhz, S_IRUGO | S_IWUSR, gt_min_freq_mhz_show, gt_min_freq_mhz_store);
  351. static DEVICE_ATTR(vlv_rpe_freq_mhz, S_IRUGO, vlv_rpe_freq_mhz_show, NULL);
  352. static ssize_t gt_rp_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf);
  353. static DEVICE_ATTR(gt_RP0_freq_mhz, S_IRUGO, gt_rp_mhz_show, NULL);
  354. static DEVICE_ATTR(gt_RP1_freq_mhz, S_IRUGO, gt_rp_mhz_show, NULL);
  355. static DEVICE_ATTR(gt_RPn_freq_mhz, S_IRUGO, gt_rp_mhz_show, NULL);
  356. /* For now we have a static number of RP states */
  357. static ssize_t gt_rp_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf)
  358. {
  359. struct drm_minor *minor = dev_to_drm_minor(kdev);
  360. struct drm_device *dev = minor->dev;
  361. struct drm_i915_private *dev_priv = dev->dev_private;
  362. u32 val, rp_state_cap;
  363. ssize_t ret;
  364. ret = mutex_lock_interruptible(&dev->struct_mutex);
  365. if (ret)
  366. return ret;
  367. rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
  368. mutex_unlock(&dev->struct_mutex);
  369. if (attr == &dev_attr_gt_RP0_freq_mhz) {
  370. val = ((rp_state_cap & 0x0000ff) >> 0) * GT_FREQUENCY_MULTIPLIER;
  371. } else if (attr == &dev_attr_gt_RP1_freq_mhz) {
  372. val = ((rp_state_cap & 0x00ff00) >> 8) * GT_FREQUENCY_MULTIPLIER;
  373. } else if (attr == &dev_attr_gt_RPn_freq_mhz) {
  374. val = ((rp_state_cap & 0xff0000) >> 16) * GT_FREQUENCY_MULTIPLIER;
  375. } else {
  376. BUG();
  377. }
  378. return snprintf(buf, PAGE_SIZE, "%d\n", val);
  379. }
  380. static const struct attribute *gen6_attrs[] = {
  381. &dev_attr_gt_cur_freq_mhz.attr,
  382. &dev_attr_gt_max_freq_mhz.attr,
  383. &dev_attr_gt_min_freq_mhz.attr,
  384. &dev_attr_gt_RP0_freq_mhz.attr,
  385. &dev_attr_gt_RP1_freq_mhz.attr,
  386. &dev_attr_gt_RPn_freq_mhz.attr,
  387. NULL,
  388. };
  389. static const struct attribute *vlv_attrs[] = {
  390. &dev_attr_gt_cur_freq_mhz.attr,
  391. &dev_attr_gt_max_freq_mhz.attr,
  392. &dev_attr_gt_min_freq_mhz.attr,
  393. &dev_attr_vlv_rpe_freq_mhz.attr,
  394. NULL,
  395. };
  396. static ssize_t error_state_read(struct file *filp, struct kobject *kobj,
  397. struct bin_attribute *attr, char *buf,
  398. loff_t off, size_t count)
  399. {
  400. struct device *kdev = container_of(kobj, struct device, kobj);
  401. struct drm_minor *minor = dev_to_drm_minor(kdev);
  402. struct drm_device *dev = minor->dev;
  403. struct i915_error_state_file_priv error_priv;
  404. struct drm_i915_error_state_buf error_str;
  405. ssize_t ret_count = 0;
  406. int ret;
  407. memset(&error_priv, 0, sizeof(error_priv));
  408. ret = i915_error_state_buf_init(&error_str, count, off);
  409. if (ret)
  410. return ret;
  411. error_priv.dev = dev;
  412. i915_error_state_get(dev, &error_priv);
  413. ret = i915_error_state_to_str(&error_str, &error_priv);
  414. if (ret)
  415. goto out;
  416. ret_count = count < error_str.bytes ? count : error_str.bytes;
  417. memcpy(buf, error_str.buf, ret_count);
  418. out:
  419. i915_error_state_put(&error_priv);
  420. i915_error_state_buf_release(&error_str);
  421. return ret ?: ret_count;
  422. }
  423. static ssize_t error_state_write(struct file *file, struct kobject *kobj,
  424. struct bin_attribute *attr, char *buf,
  425. loff_t off, size_t count)
  426. {
  427. struct device *kdev = container_of(kobj, struct device, kobj);
  428. struct drm_minor *minor = dev_to_drm_minor(kdev);
  429. struct drm_device *dev = minor->dev;
  430. int ret;
  431. DRM_DEBUG_DRIVER("Resetting error state\n");
  432. ret = mutex_lock_interruptible(&dev->struct_mutex);
  433. if (ret)
  434. return ret;
  435. i915_destroy_error_state(dev);
  436. mutex_unlock(&dev->struct_mutex);
  437. return count;
  438. }
  439. static struct bin_attribute error_state_attr = {
  440. .attr.name = "error",
  441. .attr.mode = S_IRUSR | S_IWUSR,
  442. .size = 0,
  443. .read = error_state_read,
  444. .write = error_state_write,
  445. };
  446. void i915_setup_sysfs(struct drm_device *dev)
  447. {
  448. int ret;
  449. #ifdef CONFIG_PM
  450. if (INTEL_INFO(dev)->gen >= 6) {
  451. ret = sysfs_merge_group(&dev->primary->kdev->kobj,
  452. &rc6_attr_group);
  453. if (ret)
  454. DRM_ERROR("RC6 residency sysfs setup failed\n");
  455. }
  456. #endif
  457. if (HAS_L3_DPF(dev)) {
  458. ret = device_create_bin_file(dev->primary->kdev, &dpf_attrs);
  459. if (ret)
  460. DRM_ERROR("l3 parity sysfs setup failed\n");
  461. if (NUM_L3_SLICES(dev) > 1) {
  462. ret = device_create_bin_file(dev->primary->kdev,
  463. &dpf_attrs_1);
  464. if (ret)
  465. DRM_ERROR("l3 parity slice 1 setup failed\n");
  466. }
  467. }
  468. ret = 0;
  469. if (IS_VALLEYVIEW(dev))
  470. ret = sysfs_create_files(&dev->primary->kdev->kobj, vlv_attrs);
  471. else if (INTEL_INFO(dev)->gen >= 6)
  472. ret = sysfs_create_files(&dev->primary->kdev->kobj, gen6_attrs);
  473. if (ret)
  474. DRM_ERROR("RPS sysfs setup failed\n");
  475. ret = sysfs_create_bin_file(&dev->primary->kdev->kobj,
  476. &error_state_attr);
  477. if (ret)
  478. DRM_ERROR("error_state sysfs setup failed\n");
  479. }
  480. void i915_teardown_sysfs(struct drm_device *dev)
  481. {
  482. sysfs_remove_bin_file(&dev->primary->kdev->kobj, &error_state_attr);
  483. if (IS_VALLEYVIEW(dev))
  484. sysfs_remove_files(&dev->primary->kdev->kobj, vlv_attrs);
  485. else
  486. sysfs_remove_files(&dev->primary->kdev->kobj, gen6_attrs);
  487. device_remove_bin_file(dev->primary->kdev, &dpf_attrs_1);
  488. device_remove_bin_file(dev->primary->kdev, &dpf_attrs);
  489. #ifdef CONFIG_PM
  490. sysfs_unmerge_group(&dev->primary->kdev->kobj, &rc6_attr_group);
  491. #endif
  492. }