intel_guc_log.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * Copyright © 2014-2017 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. */
  24. #include <linux/debugfs.h>
  25. #include <linux/relay.h>
  26. #include "i915_drv.h"
  27. static void guc_log_capture_logs(struct intel_guc *guc);
  28. /**
  29. * DOC: GuC firmware log
  30. *
  31. * Firmware log is enabled by setting i915.guc_log_level to non-negative level.
  32. * Log data is printed out via reading debugfs i915_guc_log_dump. Reading from
  33. * i915_guc_load_status will print out firmware loading status and scratch
  34. * registers value.
  35. *
  36. */
  37. static int guc_log_flush_complete(struct intel_guc *guc)
  38. {
  39. u32 action[] = {
  40. INTEL_GUC_ACTION_LOG_BUFFER_FILE_FLUSH_COMPLETE
  41. };
  42. return intel_guc_send(guc, action, ARRAY_SIZE(action));
  43. }
  44. static int guc_log_flush(struct intel_guc *guc)
  45. {
  46. u32 action[] = {
  47. INTEL_GUC_ACTION_FORCE_LOG_BUFFER_FLUSH,
  48. 0
  49. };
  50. return intel_guc_send(guc, action, ARRAY_SIZE(action));
  51. }
  52. static int guc_log_control(struct intel_guc *guc, u32 control_val)
  53. {
  54. u32 action[] = {
  55. INTEL_GUC_ACTION_UK_LOG_ENABLE_LOGGING,
  56. control_val
  57. };
  58. return intel_guc_send(guc, action, ARRAY_SIZE(action));
  59. }
  60. /*
  61. * Sub buffer switch callback. Called whenever relay has to switch to a new
  62. * sub buffer, relay stays on the same sub buffer if 0 is returned.
  63. */
  64. static int subbuf_start_callback(struct rchan_buf *buf,
  65. void *subbuf,
  66. void *prev_subbuf,
  67. size_t prev_padding)
  68. {
  69. /* Use no-overwrite mode by default, where relay will stop accepting
  70. * new data if there are no empty sub buffers left.
  71. * There is no strict synchronization enforced by relay between Consumer
  72. * and Producer. In overwrite mode, there is a possibility of getting
  73. * inconsistent/garbled data, the producer could be writing on to the
  74. * same sub buffer from which Consumer is reading. This can't be avoided
  75. * unless Consumer is fast enough and can always run in tandem with
  76. * Producer.
  77. */
  78. if (relay_buf_full(buf))
  79. return 0;
  80. return 1;
  81. }
  82. /*
  83. * file_create() callback. Creates relay file in debugfs.
  84. */
  85. static struct dentry *create_buf_file_callback(const char *filename,
  86. struct dentry *parent,
  87. umode_t mode,
  88. struct rchan_buf *buf,
  89. int *is_global)
  90. {
  91. struct dentry *buf_file;
  92. /* This to enable the use of a single buffer for the relay channel and
  93. * correspondingly have a single file exposed to User, through which
  94. * it can collect the logs in order without any post-processing.
  95. * Need to set 'is_global' even if parent is NULL for early logging.
  96. */
  97. *is_global = 1;
  98. if (!parent)
  99. return NULL;
  100. /* Not using the channel filename passed as an argument, since for each
  101. * channel relay appends the corresponding CPU number to the filename
  102. * passed in relay_open(). This should be fine as relay just needs a
  103. * dentry of the file associated with the channel buffer and that file's
  104. * name need not be same as the filename passed as an argument.
  105. */
  106. buf_file = debugfs_create_file("guc_log", mode,
  107. parent, buf, &relay_file_operations);
  108. return buf_file;
  109. }
  110. /*
  111. * file_remove() default callback. Removes relay file in debugfs.
  112. */
  113. static int remove_buf_file_callback(struct dentry *dentry)
  114. {
  115. debugfs_remove(dentry);
  116. return 0;
  117. }
  118. /* relay channel callbacks */
  119. static struct rchan_callbacks relay_callbacks = {
  120. .subbuf_start = subbuf_start_callback,
  121. .create_buf_file = create_buf_file_callback,
  122. .remove_buf_file = remove_buf_file_callback,
  123. };
  124. static int guc_log_relay_file_create(struct intel_guc *guc)
  125. {
  126. struct drm_i915_private *dev_priv = guc_to_i915(guc);
  127. struct dentry *log_dir;
  128. int ret;
  129. if (i915.guc_log_level < 0)
  130. return 0;
  131. /* For now create the log file in /sys/kernel/debug/dri/0 dir */
  132. log_dir = dev_priv->drm.primary->debugfs_root;
  133. /* If /sys/kernel/debug/dri/0 location do not exist, then debugfs is
  134. * not mounted and so can't create the relay file.
  135. * The relay API seems to fit well with debugfs only, for availing relay
  136. * there are 3 requirements which can be met for debugfs file only in a
  137. * straightforward/clean manner :-
  138. * i) Need the associated dentry pointer of the file, while opening the
  139. * relay channel.
  140. * ii) Should be able to use 'relay_file_operations' fops for the file.
  141. * iii) Set the 'i_private' field of file's inode to the pointer of
  142. * relay channel buffer.
  143. */
  144. if (!log_dir) {
  145. DRM_ERROR("Debugfs dir not available yet for GuC log file\n");
  146. return -ENODEV;
  147. }
  148. ret = relay_late_setup_files(guc->log.runtime.relay_chan, "guc_log", log_dir);
  149. if (ret < 0 && ret != -EEXIST) {
  150. DRM_ERROR("Couldn't associate relay chan with file %d\n", ret);
  151. return ret;
  152. }
  153. return 0;
  154. }
  155. static void guc_move_to_next_buf(struct intel_guc *guc)
  156. {
  157. /* Make sure the updates made in the sub buffer are visible when
  158. * Consumer sees the following update to offset inside the sub buffer.
  159. */
  160. smp_wmb();
  161. /* All data has been written, so now move the offset of sub buffer. */
  162. relay_reserve(guc->log.runtime.relay_chan, guc->log.vma->obj->base.size);
  163. /* Switch to the next sub buffer */
  164. relay_flush(guc->log.runtime.relay_chan);
  165. }
  166. static void *guc_get_write_buffer(struct intel_guc *guc)
  167. {
  168. if (!guc->log.runtime.relay_chan)
  169. return NULL;
  170. /* Just get the base address of a new sub buffer and copy data into it
  171. * ourselves. NULL will be returned in no-overwrite mode, if all sub
  172. * buffers are full. Could have used the relay_write() to indirectly
  173. * copy the data, but that would have been bit convoluted, as we need to
  174. * write to only certain locations inside a sub buffer which cannot be
  175. * done without using relay_reserve() along with relay_write(). So its
  176. * better to use relay_reserve() alone.
  177. */
  178. return relay_reserve(guc->log.runtime.relay_chan, 0);
  179. }
  180. static bool guc_check_log_buf_overflow(struct intel_guc *guc,
  181. enum guc_log_buffer_type type,
  182. unsigned int full_cnt)
  183. {
  184. unsigned int prev_full_cnt = guc->log.prev_overflow_count[type];
  185. bool overflow = false;
  186. if (full_cnt != prev_full_cnt) {
  187. overflow = true;
  188. guc->log.prev_overflow_count[type] = full_cnt;
  189. guc->log.total_overflow_count[type] += full_cnt - prev_full_cnt;
  190. if (full_cnt < prev_full_cnt) {
  191. /* buffer_full_cnt is a 4 bit counter */
  192. guc->log.total_overflow_count[type] += 16;
  193. }
  194. DRM_ERROR_RATELIMITED("GuC log buffer overflow\n");
  195. }
  196. return overflow;
  197. }
  198. static unsigned int guc_get_log_buffer_size(enum guc_log_buffer_type type)
  199. {
  200. switch (type) {
  201. case GUC_ISR_LOG_BUFFER:
  202. return (GUC_LOG_ISR_PAGES + 1) * PAGE_SIZE;
  203. case GUC_DPC_LOG_BUFFER:
  204. return (GUC_LOG_DPC_PAGES + 1) * PAGE_SIZE;
  205. case GUC_CRASH_DUMP_LOG_BUFFER:
  206. return (GUC_LOG_CRASH_PAGES + 1) * PAGE_SIZE;
  207. default:
  208. MISSING_CASE(type);
  209. }
  210. return 0;
  211. }
  212. static void guc_read_update_log_buffer(struct intel_guc *guc)
  213. {
  214. unsigned int buffer_size, read_offset, write_offset, bytes_to_copy, full_cnt;
  215. struct guc_log_buffer_state *log_buf_state, *log_buf_snapshot_state;
  216. struct guc_log_buffer_state log_buf_state_local;
  217. enum guc_log_buffer_type type;
  218. void *src_data, *dst_data;
  219. bool new_overflow;
  220. if (WARN_ON(!guc->log.runtime.buf_addr))
  221. return;
  222. /* Get the pointer to shared GuC log buffer */
  223. log_buf_state = src_data = guc->log.runtime.buf_addr;
  224. /* Get the pointer to local buffer to store the logs */
  225. log_buf_snapshot_state = dst_data = guc_get_write_buffer(guc);
  226. /* Actual logs are present from the 2nd page */
  227. src_data += PAGE_SIZE;
  228. dst_data += PAGE_SIZE;
  229. for (type = GUC_ISR_LOG_BUFFER; type < GUC_MAX_LOG_BUFFER; type++) {
  230. /* Make a copy of the state structure, inside GuC log buffer
  231. * (which is uncached mapped), on the stack to avoid reading
  232. * from it multiple times.
  233. */
  234. memcpy(&log_buf_state_local, log_buf_state,
  235. sizeof(struct guc_log_buffer_state));
  236. buffer_size = guc_get_log_buffer_size(type);
  237. read_offset = log_buf_state_local.read_ptr;
  238. write_offset = log_buf_state_local.sampled_write_ptr;
  239. full_cnt = log_buf_state_local.buffer_full_cnt;
  240. /* Bookkeeping stuff */
  241. guc->log.flush_count[type] += log_buf_state_local.flush_to_file;
  242. new_overflow = guc_check_log_buf_overflow(guc, type, full_cnt);
  243. /* Update the state of shared log buffer */
  244. log_buf_state->read_ptr = write_offset;
  245. log_buf_state->flush_to_file = 0;
  246. log_buf_state++;
  247. if (unlikely(!log_buf_snapshot_state))
  248. continue;
  249. /* First copy the state structure in snapshot buffer */
  250. memcpy(log_buf_snapshot_state, &log_buf_state_local,
  251. sizeof(struct guc_log_buffer_state));
  252. /* The write pointer could have been updated by GuC firmware,
  253. * after sending the flush interrupt to Host, for consistency
  254. * set write pointer value to same value of sampled_write_ptr
  255. * in the snapshot buffer.
  256. */
  257. log_buf_snapshot_state->write_ptr = write_offset;
  258. log_buf_snapshot_state++;
  259. /* Now copy the actual logs. */
  260. if (unlikely(new_overflow)) {
  261. /* copy the whole buffer in case of overflow */
  262. read_offset = 0;
  263. write_offset = buffer_size;
  264. } else if (unlikely((read_offset > buffer_size) ||
  265. (write_offset > buffer_size))) {
  266. DRM_ERROR("invalid log buffer state\n");
  267. /* copy whole buffer as offsets are unreliable */
  268. read_offset = 0;
  269. write_offset = buffer_size;
  270. }
  271. /* Just copy the newly written data */
  272. if (read_offset > write_offset) {
  273. i915_memcpy_from_wc(dst_data, src_data, write_offset);
  274. bytes_to_copy = buffer_size - read_offset;
  275. } else {
  276. bytes_to_copy = write_offset - read_offset;
  277. }
  278. i915_memcpy_from_wc(dst_data + read_offset,
  279. src_data + read_offset, bytes_to_copy);
  280. src_data += buffer_size;
  281. dst_data += buffer_size;
  282. }
  283. if (log_buf_snapshot_state)
  284. guc_move_to_next_buf(guc);
  285. else {
  286. /* Used rate limited to avoid deluge of messages, logs might be
  287. * getting consumed by User at a slow rate.
  288. */
  289. DRM_ERROR_RATELIMITED("no sub-buffer to capture logs\n");
  290. guc->log.capture_miss_count++;
  291. }
  292. }
  293. static void capture_logs_work(struct work_struct *work)
  294. {
  295. struct intel_guc *guc =
  296. container_of(work, struct intel_guc, log.runtime.flush_work);
  297. guc_log_capture_logs(guc);
  298. }
  299. static bool guc_log_has_runtime(struct intel_guc *guc)
  300. {
  301. return guc->log.runtime.buf_addr != NULL;
  302. }
  303. static int guc_log_runtime_create(struct intel_guc *guc)
  304. {
  305. struct drm_i915_private *dev_priv = guc_to_i915(guc);
  306. void *vaddr;
  307. struct rchan *guc_log_relay_chan;
  308. size_t n_subbufs, subbuf_size;
  309. int ret;
  310. lockdep_assert_held(&dev_priv->drm.struct_mutex);
  311. GEM_BUG_ON(guc_log_has_runtime(guc));
  312. ret = i915_gem_object_set_to_wc_domain(guc->log.vma->obj, true);
  313. if (ret)
  314. return ret;
  315. /* Create a WC (Uncached for read) vmalloc mapping of log
  316. * buffer pages, so that we can directly get the data
  317. * (up-to-date) from memory.
  318. */
  319. vaddr = i915_gem_object_pin_map(guc->log.vma->obj, I915_MAP_WC);
  320. if (IS_ERR(vaddr)) {
  321. DRM_ERROR("Couldn't map log buffer pages %d\n", ret);
  322. return PTR_ERR(vaddr);
  323. }
  324. guc->log.runtime.buf_addr = vaddr;
  325. /* Keep the size of sub buffers same as shared log buffer */
  326. subbuf_size = guc->log.vma->obj->base.size;
  327. /* Store up to 8 snapshots, which is large enough to buffer sufficient
  328. * boot time logs and provides enough leeway to User, in terms of
  329. * latency, for consuming the logs from relay. Also doesn't take
  330. * up too much memory.
  331. */
  332. n_subbufs = 8;
  333. /* Create a relay channel, so that we have buffers for storing
  334. * the GuC firmware logs, the channel will be linked with a file
  335. * later on when debugfs is registered.
  336. */
  337. guc_log_relay_chan = relay_open(NULL, NULL, subbuf_size,
  338. n_subbufs, &relay_callbacks, dev_priv);
  339. if (!guc_log_relay_chan) {
  340. DRM_ERROR("Couldn't create relay chan for GuC logging\n");
  341. ret = -ENOMEM;
  342. goto err_vaddr;
  343. }
  344. GEM_BUG_ON(guc_log_relay_chan->subbuf_size < subbuf_size);
  345. guc->log.runtime.relay_chan = guc_log_relay_chan;
  346. INIT_WORK(&guc->log.runtime.flush_work, capture_logs_work);
  347. /*
  348. * GuC log buffer flush work item has to do register access to
  349. * send the ack to GuC and this work item, if not synced before
  350. * suspend, can potentially get executed after the GFX device is
  351. * suspended.
  352. * By marking the WQ as freezable, we don't have to bother about
  353. * flushing of this work item from the suspend hooks, the pending
  354. * work item if any will be either executed before the suspend
  355. * or scheduled later on resume. This way the handling of work
  356. * item can be kept same between system suspend & rpm suspend.
  357. */
  358. guc->log.runtime.flush_wq = alloc_ordered_workqueue("i915-guc_log",
  359. WQ_HIGHPRI | WQ_FREEZABLE);
  360. if (!guc->log.runtime.flush_wq) {
  361. DRM_ERROR("Couldn't allocate the wq for GuC logging\n");
  362. ret = -ENOMEM;
  363. goto err_relaychan;
  364. }
  365. return 0;
  366. err_relaychan:
  367. relay_close(guc->log.runtime.relay_chan);
  368. err_vaddr:
  369. i915_gem_object_unpin_map(guc->log.vma->obj);
  370. guc->log.runtime.buf_addr = NULL;
  371. return ret;
  372. }
  373. static void guc_log_runtime_destroy(struct intel_guc *guc)
  374. {
  375. /*
  376. * It's possible that the runtime stuff was never allocated because
  377. * guc_log_level was < 0 at the time
  378. **/
  379. if (!guc_log_has_runtime(guc))
  380. return;
  381. destroy_workqueue(guc->log.runtime.flush_wq);
  382. relay_close(guc->log.runtime.relay_chan);
  383. i915_gem_object_unpin_map(guc->log.vma->obj);
  384. guc->log.runtime.buf_addr = NULL;
  385. }
  386. static int guc_log_late_setup(struct intel_guc *guc)
  387. {
  388. struct drm_i915_private *dev_priv = guc_to_i915(guc);
  389. int ret;
  390. lockdep_assert_held(&dev_priv->drm.struct_mutex);
  391. if (!guc_log_has_runtime(guc)) {
  392. /* If log_level was set as -1 at boot time, then setup needed to
  393. * handle log buffer flush interrupts would not have been done yet,
  394. * so do that now.
  395. */
  396. ret = guc_log_runtime_create(guc);
  397. if (ret)
  398. goto err;
  399. }
  400. ret = guc_log_relay_file_create(guc);
  401. if (ret)
  402. goto err_runtime;
  403. return 0;
  404. err_runtime:
  405. guc_log_runtime_destroy(guc);
  406. err:
  407. /* logging will remain off */
  408. i915.guc_log_level = -1;
  409. return ret;
  410. }
  411. static void guc_log_capture_logs(struct intel_guc *guc)
  412. {
  413. struct drm_i915_private *dev_priv = guc_to_i915(guc);
  414. guc_read_update_log_buffer(guc);
  415. /* Generally device is expected to be active only at this
  416. * time, so get/put should be really quick.
  417. */
  418. intel_runtime_pm_get(dev_priv);
  419. guc_log_flush_complete(guc);
  420. intel_runtime_pm_put(dev_priv);
  421. }
  422. static void guc_flush_logs(struct intel_guc *guc)
  423. {
  424. struct drm_i915_private *dev_priv = guc_to_i915(guc);
  425. if (!i915.enable_guc_submission || (i915.guc_log_level < 0))
  426. return;
  427. /* First disable the interrupts, will be renabled afterwards */
  428. gen9_disable_guc_interrupts(dev_priv);
  429. /* Before initiating the forceful flush, wait for any pending/ongoing
  430. * flush to complete otherwise forceful flush may not actually happen.
  431. */
  432. flush_work(&guc->log.runtime.flush_work);
  433. /* Ask GuC to update the log buffer state */
  434. guc_log_flush(guc);
  435. /* GuC would have updated log buffer by now, so capture it */
  436. guc_log_capture_logs(guc);
  437. }
  438. int intel_guc_log_create(struct intel_guc *guc)
  439. {
  440. struct i915_vma *vma;
  441. unsigned long offset;
  442. uint32_t size, flags;
  443. int ret;
  444. GEM_BUG_ON(guc->log.vma);
  445. if (i915.guc_log_level > GUC_LOG_VERBOSITY_MAX)
  446. i915.guc_log_level = GUC_LOG_VERBOSITY_MAX;
  447. /* The first page is to save log buffer state. Allocate one
  448. * extra page for others in case for overlap */
  449. size = (1 + GUC_LOG_DPC_PAGES + 1 +
  450. GUC_LOG_ISR_PAGES + 1 +
  451. GUC_LOG_CRASH_PAGES + 1) << PAGE_SHIFT;
  452. /* We require SSE 4.1 for fast reads from the GuC log buffer and
  453. * it should be present on the chipsets supporting GuC based
  454. * submisssions.
  455. */
  456. if (WARN_ON(!i915_has_memcpy_from_wc())) {
  457. ret = -EINVAL;
  458. goto err;
  459. }
  460. vma = intel_guc_allocate_vma(guc, size);
  461. if (IS_ERR(vma)) {
  462. ret = PTR_ERR(vma);
  463. goto err;
  464. }
  465. guc->log.vma = vma;
  466. if (i915.guc_log_level >= 0) {
  467. ret = guc_log_runtime_create(guc);
  468. if (ret < 0)
  469. goto err_vma;
  470. }
  471. /* each allocated unit is a page */
  472. flags = GUC_LOG_VALID | GUC_LOG_NOTIFY_ON_HALF_FULL |
  473. (GUC_LOG_DPC_PAGES << GUC_LOG_DPC_SHIFT) |
  474. (GUC_LOG_ISR_PAGES << GUC_LOG_ISR_SHIFT) |
  475. (GUC_LOG_CRASH_PAGES << GUC_LOG_CRASH_SHIFT);
  476. offset = guc_ggtt_offset(vma) >> PAGE_SHIFT; /* in pages */
  477. guc->log.flags = (offset << GUC_LOG_BUF_ADDR_SHIFT) | flags;
  478. return 0;
  479. err_vma:
  480. i915_vma_unpin_and_release(&guc->log.vma);
  481. err:
  482. /* logging will be off */
  483. i915.guc_log_level = -1;
  484. return ret;
  485. }
  486. void intel_guc_log_destroy(struct intel_guc *guc)
  487. {
  488. guc_log_runtime_destroy(guc);
  489. i915_vma_unpin_and_release(&guc->log.vma);
  490. }
  491. int i915_guc_log_control(struct drm_i915_private *dev_priv, u64 control_val)
  492. {
  493. struct intel_guc *guc = &dev_priv->guc;
  494. union guc_log_control log_param;
  495. int ret;
  496. log_param.value = control_val;
  497. if (log_param.verbosity < GUC_LOG_VERBOSITY_MIN ||
  498. log_param.verbosity > GUC_LOG_VERBOSITY_MAX)
  499. return -EINVAL;
  500. /* This combination doesn't make sense & won't have any effect */
  501. if (!log_param.logging_enabled && (i915.guc_log_level < 0))
  502. return 0;
  503. ret = guc_log_control(guc, log_param.value);
  504. if (ret < 0) {
  505. DRM_DEBUG_DRIVER("guc_logging_control action failed %d\n", ret);
  506. return ret;
  507. }
  508. if (log_param.logging_enabled) {
  509. i915.guc_log_level = log_param.verbosity;
  510. /* If log_level was set as -1 at boot time, then the relay channel file
  511. * wouldn't have been created by now and interrupts also would not have
  512. * been enabled. Try again now, just in case.
  513. */
  514. ret = guc_log_late_setup(guc);
  515. if (ret < 0) {
  516. DRM_DEBUG_DRIVER("GuC log late setup failed %d\n", ret);
  517. return ret;
  518. }
  519. /* GuC logging is currently the only user of Guc2Host interrupts */
  520. gen9_enable_guc_interrupts(dev_priv);
  521. } else {
  522. /* Once logging is disabled, GuC won't generate logs & send an
  523. * interrupt. But there could be some data in the log buffer
  524. * which is yet to be captured. So request GuC to update the log
  525. * buffer state and then collect the left over logs.
  526. */
  527. guc_flush_logs(guc);
  528. /* As logging is disabled, update log level to reflect that */
  529. i915.guc_log_level = -1;
  530. }
  531. return ret;
  532. }
  533. void i915_guc_log_register(struct drm_i915_private *dev_priv)
  534. {
  535. if (!i915.enable_guc_submission || i915.guc_log_level < 0)
  536. return;
  537. mutex_lock(&dev_priv->drm.struct_mutex);
  538. guc_log_late_setup(&dev_priv->guc);
  539. mutex_unlock(&dev_priv->drm.struct_mutex);
  540. }
  541. void i915_guc_log_unregister(struct drm_i915_private *dev_priv)
  542. {
  543. if (!i915.enable_guc_submission)
  544. return;
  545. mutex_lock(&dev_priv->drm.struct_mutex);
  546. /* GuC logging is currently the only user of Guc2Host interrupts */
  547. gen9_disable_guc_interrupts(dev_priv);
  548. guc_log_runtime_destroy(&dev_priv->guc);
  549. mutex_unlock(&dev_priv->drm.struct_mutex);
  550. }