Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 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 | */ |
Michal Wajdeczko | d62e2bf | 2017-10-04 18:13:39 +0000 | [diff] [blame] | 24 | |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 25 | #include <linux/debugfs.h> |
| 26 | #include <linux/relay.h> |
Michal Wajdeczko | d62e2bf | 2017-10-04 18:13:39 +0000 | [diff] [blame] | 27 | |
| 28 | #include "intel_guc_log.h" |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 29 | #include "i915_drv.h" |
| 30 | |
| 31 | static void guc_log_capture_logs(struct intel_guc *guc); |
| 32 | |
| 33 | /** |
| 34 | * DOC: GuC firmware log |
| 35 | * |
Michal Wajdeczko | 0ed8795 | 2018-01-11 15:24:40 +0000 | [diff] [blame] | 36 | * Firmware log is enabled by setting i915.guc_log_level to the positive level. |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 37 | * Log data is printed out via reading debugfs i915_guc_log_dump. Reading from |
| 38 | * i915_guc_load_status will print out firmware loading status and scratch |
| 39 | * registers value. |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 40 | */ |
| 41 | |
| 42 | static int guc_log_flush_complete(struct intel_guc *guc) |
| 43 | { |
| 44 | u32 action[] = { |
| 45 | INTEL_GUC_ACTION_LOG_BUFFER_FILE_FLUSH_COMPLETE |
| 46 | }; |
| 47 | |
| 48 | return intel_guc_send(guc, action, ARRAY_SIZE(action)); |
| 49 | } |
| 50 | |
| 51 | static int guc_log_flush(struct intel_guc *guc) |
| 52 | { |
| 53 | u32 action[] = { |
| 54 | INTEL_GUC_ACTION_FORCE_LOG_BUFFER_FLUSH, |
| 55 | 0 |
| 56 | }; |
| 57 | |
| 58 | return intel_guc_send(guc, action, ARRAY_SIZE(action)); |
| 59 | } |
| 60 | |
Michal Wajdeczko | 35fe703 | 2018-01-11 15:24:41 +0000 | [diff] [blame] | 61 | static int guc_log_control(struct intel_guc *guc, bool enable, u32 verbosity) |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 62 | { |
Michal Wajdeczko | 35fe703 | 2018-01-11 15:24:41 +0000 | [diff] [blame] | 63 | union guc_log_control control_val = { |
| 64 | .logging_enabled = enable, |
| 65 | .verbosity = verbosity, |
| 66 | }; |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 67 | u32 action[] = { |
| 68 | INTEL_GUC_ACTION_UK_LOG_ENABLE_LOGGING, |
Michal Wajdeczko | 35fe703 | 2018-01-11 15:24:41 +0000 | [diff] [blame] | 69 | control_val.value |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | return intel_guc_send(guc, action, ARRAY_SIZE(action)); |
| 73 | } |
| 74 | |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 75 | /* |
| 76 | * Sub buffer switch callback. Called whenever relay has to switch to a new |
| 77 | * sub buffer, relay stays on the same sub buffer if 0 is returned. |
| 78 | */ |
| 79 | static int subbuf_start_callback(struct rchan_buf *buf, |
| 80 | void *subbuf, |
| 81 | void *prev_subbuf, |
| 82 | size_t prev_padding) |
| 83 | { |
Sagar Arun Kamble | 2fcf068 | 2018-01-24 21:17:00 +0530 | [diff] [blame] | 84 | /* |
| 85 | * Use no-overwrite mode by default, where relay will stop accepting |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 86 | * new data if there are no empty sub buffers left. |
| 87 | * There is no strict synchronization enforced by relay between Consumer |
| 88 | * and Producer. In overwrite mode, there is a possibility of getting |
| 89 | * inconsistent/garbled data, the producer could be writing on to the |
| 90 | * same sub buffer from which Consumer is reading. This can't be avoided |
| 91 | * unless Consumer is fast enough and can always run in tandem with |
| 92 | * Producer. |
| 93 | */ |
| 94 | if (relay_buf_full(buf)) |
| 95 | return 0; |
| 96 | |
| 97 | return 1; |
| 98 | } |
| 99 | |
| 100 | /* |
| 101 | * file_create() callback. Creates relay file in debugfs. |
| 102 | */ |
| 103 | static struct dentry *create_buf_file_callback(const char *filename, |
| 104 | struct dentry *parent, |
| 105 | umode_t mode, |
| 106 | struct rchan_buf *buf, |
| 107 | int *is_global) |
| 108 | { |
| 109 | struct dentry *buf_file; |
| 110 | |
Sagar Arun Kamble | 2fcf068 | 2018-01-24 21:17:00 +0530 | [diff] [blame] | 111 | /* |
| 112 | * This to enable the use of a single buffer for the relay channel and |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 113 | * correspondingly have a single file exposed to User, through which |
| 114 | * it can collect the logs in order without any post-processing. |
| 115 | * Need to set 'is_global' even if parent is NULL for early logging. |
| 116 | */ |
| 117 | *is_global = 1; |
| 118 | |
| 119 | if (!parent) |
| 120 | return NULL; |
| 121 | |
Sagar Arun Kamble | 2fcf068 | 2018-01-24 21:17:00 +0530 | [diff] [blame] | 122 | /* |
| 123 | * Not using the channel filename passed as an argument, since for each |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 124 | * channel relay appends the corresponding CPU number to the filename |
| 125 | * passed in relay_open(). This should be fine as relay just needs a |
| 126 | * dentry of the file associated with the channel buffer and that file's |
| 127 | * name need not be same as the filename passed as an argument. |
| 128 | */ |
| 129 | buf_file = debugfs_create_file("guc_log", mode, |
| 130 | parent, buf, &relay_file_operations); |
| 131 | return buf_file; |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * file_remove() default callback. Removes relay file in debugfs. |
| 136 | */ |
| 137 | static int remove_buf_file_callback(struct dentry *dentry) |
| 138 | { |
| 139 | debugfs_remove(dentry); |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | /* relay channel callbacks */ |
| 144 | static struct rchan_callbacks relay_callbacks = { |
| 145 | .subbuf_start = subbuf_start_callback, |
| 146 | .create_buf_file = create_buf_file_callback, |
| 147 | .remove_buf_file = remove_buf_file_callback, |
| 148 | }; |
| 149 | |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 150 | static int guc_log_relay_file_create(struct intel_guc *guc) |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 151 | { |
| 152 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 153 | struct dentry *log_dir; |
| 154 | int ret; |
| 155 | |
Michal Wajdeczko | 0ed8795 | 2018-01-11 15:24:40 +0000 | [diff] [blame] | 156 | if (!i915_modparams.guc_log_level) |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 157 | return 0; |
| 158 | |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 159 | mutex_lock(&guc->log.runtime.relay_lock); |
| 160 | |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 161 | /* For now create the log file in /sys/kernel/debug/dri/0 dir */ |
| 162 | log_dir = dev_priv->drm.primary->debugfs_root; |
| 163 | |
Sagar Arun Kamble | 2fcf068 | 2018-01-24 21:17:00 +0530 | [diff] [blame] | 164 | /* |
| 165 | * If /sys/kernel/debug/dri/0 location do not exist, then debugfs is |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 166 | * not mounted and so can't create the relay file. |
| 167 | * The relay API seems to fit well with debugfs only, for availing relay |
| 168 | * there are 3 requirements which can be met for debugfs file only in a |
| 169 | * straightforward/clean manner :- |
| 170 | * i) Need the associated dentry pointer of the file, while opening the |
| 171 | * relay channel. |
| 172 | * ii) Should be able to use 'relay_file_operations' fops for the file. |
| 173 | * iii) Set the 'i_private' field of file's inode to the pointer of |
| 174 | * relay channel buffer. |
| 175 | */ |
| 176 | if (!log_dir) { |
| 177 | DRM_ERROR("Debugfs dir not available yet for GuC log file\n"); |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 178 | ret = -ENODEV; |
| 179 | goto out_unlock; |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 182 | ret = relay_late_setup_files(guc->log.runtime.relay_chan, "guc_log", log_dir); |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 183 | if (ret < 0 && ret != -EEXIST) { |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 184 | DRM_ERROR("Couldn't associate relay chan with file %d\n", ret); |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 185 | goto out_unlock; |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Sagar Arun Kamble | b1852d3 | 2018-01-31 11:44:37 +0530 | [diff] [blame] | 188 | ret = 0; |
| 189 | |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 190 | out_unlock: |
| 191 | mutex_unlock(&guc->log.runtime.relay_lock); |
| 192 | return ret; |
| 193 | } |
| 194 | |
| 195 | static bool guc_log_has_relay(struct intel_guc *guc) |
| 196 | { |
| 197 | lockdep_assert_held(&guc->log.runtime.relay_lock); |
| 198 | |
| 199 | return guc->log.runtime.relay_chan != NULL; |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | static void guc_move_to_next_buf(struct intel_guc *guc) |
| 203 | { |
Sagar Arun Kamble | 2fcf068 | 2018-01-24 21:17:00 +0530 | [diff] [blame] | 204 | /* |
| 205 | * Make sure the updates made in the sub buffer are visible when |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 206 | * Consumer sees the following update to offset inside the sub buffer. |
| 207 | */ |
| 208 | smp_wmb(); |
| 209 | |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 210 | if (!guc_log_has_relay(guc)) |
| 211 | return; |
| 212 | |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 213 | /* All data has been written, so now move the offset of sub buffer. */ |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 214 | relay_reserve(guc->log.runtime.relay_chan, guc->log.vma->obj->base.size); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 215 | |
| 216 | /* Switch to the next sub buffer */ |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 217 | relay_flush(guc->log.runtime.relay_chan); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | static void *guc_get_write_buffer(struct intel_guc *guc) |
| 221 | { |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 222 | if (!guc_log_has_relay(guc)) |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 223 | return NULL; |
| 224 | |
Sagar Arun Kamble | 2fcf068 | 2018-01-24 21:17:00 +0530 | [diff] [blame] | 225 | /* |
| 226 | * Just get the base address of a new sub buffer and copy data into it |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 227 | * ourselves. NULL will be returned in no-overwrite mode, if all sub |
| 228 | * buffers are full. Could have used the relay_write() to indirectly |
| 229 | * copy the data, but that would have been bit convoluted, as we need to |
| 230 | * write to only certain locations inside a sub buffer which cannot be |
| 231 | * done without using relay_reserve() along with relay_write(). So its |
| 232 | * better to use relay_reserve() alone. |
| 233 | */ |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 234 | return relay_reserve(guc->log.runtime.relay_chan, 0); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | static bool guc_check_log_buf_overflow(struct intel_guc *guc, |
| 238 | enum guc_log_buffer_type type, |
| 239 | unsigned int full_cnt) |
| 240 | { |
| 241 | unsigned int prev_full_cnt = guc->log.prev_overflow_count[type]; |
| 242 | bool overflow = false; |
| 243 | |
| 244 | if (full_cnt != prev_full_cnt) { |
| 245 | overflow = true; |
| 246 | |
| 247 | guc->log.prev_overflow_count[type] = full_cnt; |
| 248 | guc->log.total_overflow_count[type] += full_cnt - prev_full_cnt; |
| 249 | |
| 250 | if (full_cnt < prev_full_cnt) { |
| 251 | /* buffer_full_cnt is a 4 bit counter */ |
| 252 | guc->log.total_overflow_count[type] += 16; |
| 253 | } |
| 254 | DRM_ERROR_RATELIMITED("GuC log buffer overflow\n"); |
| 255 | } |
| 256 | |
| 257 | return overflow; |
| 258 | } |
| 259 | |
| 260 | static unsigned int guc_get_log_buffer_size(enum guc_log_buffer_type type) |
| 261 | { |
| 262 | switch (type) { |
| 263 | case GUC_ISR_LOG_BUFFER: |
| 264 | return (GUC_LOG_ISR_PAGES + 1) * PAGE_SIZE; |
| 265 | case GUC_DPC_LOG_BUFFER: |
| 266 | return (GUC_LOG_DPC_PAGES + 1) * PAGE_SIZE; |
| 267 | case GUC_CRASH_DUMP_LOG_BUFFER: |
| 268 | return (GUC_LOG_CRASH_PAGES + 1) * PAGE_SIZE; |
| 269 | default: |
| 270 | MISSING_CASE(type); |
| 271 | } |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | static void guc_read_update_log_buffer(struct intel_guc *guc) |
| 277 | { |
| 278 | unsigned int buffer_size, read_offset, write_offset, bytes_to_copy, full_cnt; |
| 279 | struct guc_log_buffer_state *log_buf_state, *log_buf_snapshot_state; |
| 280 | struct guc_log_buffer_state log_buf_state_local; |
| 281 | enum guc_log_buffer_type type; |
| 282 | void *src_data, *dst_data; |
| 283 | bool new_overflow; |
| 284 | |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 285 | if (WARN_ON(!guc->log.runtime.buf_addr)) |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 286 | return; |
| 287 | |
| 288 | /* Get the pointer to shared GuC log buffer */ |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 289 | log_buf_state = src_data = guc->log.runtime.buf_addr; |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 290 | |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 291 | mutex_lock(&guc->log.runtime.relay_lock); |
| 292 | |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 293 | /* Get the pointer to local buffer to store the logs */ |
| 294 | log_buf_snapshot_state = dst_data = guc_get_write_buffer(guc); |
| 295 | |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 296 | if (unlikely(!log_buf_snapshot_state)) { |
Sagar Arun Kamble | 2fcf068 | 2018-01-24 21:17:00 +0530 | [diff] [blame] | 297 | /* |
| 298 | * Used rate limited to avoid deluge of messages, logs might be |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 299 | * getting consumed by User at a slow rate. |
| 300 | */ |
| 301 | DRM_ERROR_RATELIMITED("no sub-buffer to capture logs\n"); |
| 302 | guc->log.capture_miss_count++; |
| 303 | mutex_unlock(&guc->log.runtime.relay_lock); |
| 304 | |
| 305 | return; |
| 306 | } |
| 307 | |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 308 | /* Actual logs are present from the 2nd page */ |
| 309 | src_data += PAGE_SIZE; |
| 310 | dst_data += PAGE_SIZE; |
| 311 | |
| 312 | for (type = GUC_ISR_LOG_BUFFER; type < GUC_MAX_LOG_BUFFER; type++) { |
Sagar Arun Kamble | 2fcf068 | 2018-01-24 21:17:00 +0530 | [diff] [blame] | 313 | /* |
| 314 | * Make a copy of the state structure, inside GuC log buffer |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 315 | * (which is uncached mapped), on the stack to avoid reading |
| 316 | * from it multiple times. |
| 317 | */ |
| 318 | memcpy(&log_buf_state_local, log_buf_state, |
| 319 | sizeof(struct guc_log_buffer_state)); |
| 320 | buffer_size = guc_get_log_buffer_size(type); |
| 321 | read_offset = log_buf_state_local.read_ptr; |
| 322 | write_offset = log_buf_state_local.sampled_write_ptr; |
| 323 | full_cnt = log_buf_state_local.buffer_full_cnt; |
| 324 | |
| 325 | /* Bookkeeping stuff */ |
| 326 | guc->log.flush_count[type] += log_buf_state_local.flush_to_file; |
| 327 | new_overflow = guc_check_log_buf_overflow(guc, type, full_cnt); |
| 328 | |
| 329 | /* Update the state of shared log buffer */ |
| 330 | log_buf_state->read_ptr = write_offset; |
| 331 | log_buf_state->flush_to_file = 0; |
| 332 | log_buf_state++; |
| 333 | |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 334 | /* First copy the state structure in snapshot buffer */ |
| 335 | memcpy(log_buf_snapshot_state, &log_buf_state_local, |
| 336 | sizeof(struct guc_log_buffer_state)); |
| 337 | |
Sagar Arun Kamble | 2fcf068 | 2018-01-24 21:17:00 +0530 | [diff] [blame] | 338 | /* |
| 339 | * The write pointer could have been updated by GuC firmware, |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 340 | * after sending the flush interrupt to Host, for consistency |
| 341 | * set write pointer value to same value of sampled_write_ptr |
| 342 | * in the snapshot buffer. |
| 343 | */ |
| 344 | log_buf_snapshot_state->write_ptr = write_offset; |
| 345 | log_buf_snapshot_state++; |
| 346 | |
| 347 | /* Now copy the actual logs. */ |
| 348 | if (unlikely(new_overflow)) { |
| 349 | /* copy the whole buffer in case of overflow */ |
| 350 | read_offset = 0; |
| 351 | write_offset = buffer_size; |
| 352 | } else if (unlikely((read_offset > buffer_size) || |
| 353 | (write_offset > buffer_size))) { |
| 354 | DRM_ERROR("invalid log buffer state\n"); |
| 355 | /* copy whole buffer as offsets are unreliable */ |
| 356 | read_offset = 0; |
| 357 | write_offset = buffer_size; |
| 358 | } |
| 359 | |
| 360 | /* Just copy the newly written data */ |
| 361 | if (read_offset > write_offset) { |
| 362 | i915_memcpy_from_wc(dst_data, src_data, write_offset); |
| 363 | bytes_to_copy = buffer_size - read_offset; |
| 364 | } else { |
| 365 | bytes_to_copy = write_offset - read_offset; |
| 366 | } |
| 367 | i915_memcpy_from_wc(dst_data + read_offset, |
| 368 | src_data + read_offset, bytes_to_copy); |
| 369 | |
| 370 | src_data += buffer_size; |
| 371 | dst_data += buffer_size; |
| 372 | } |
| 373 | |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 374 | guc_move_to_next_buf(guc); |
| 375 | |
| 376 | mutex_unlock(&guc->log.runtime.relay_lock); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 379 | static void capture_logs_work(struct work_struct *work) |
| 380 | { |
| 381 | struct intel_guc *guc = |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 382 | container_of(work, struct intel_guc, log.runtime.flush_work); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 383 | |
| 384 | guc_log_capture_logs(guc); |
| 385 | } |
| 386 | |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 387 | static bool guc_log_has_runtime(struct intel_guc *guc) |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 388 | { |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 389 | return guc->log.runtime.buf_addr != NULL; |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 392 | static int guc_log_runtime_create(struct intel_guc *guc) |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 393 | { |
| 394 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 395 | void *vaddr; |
Chris Wilson | e22d8e3 | 2017-04-12 12:01:11 +0100 | [diff] [blame] | 396 | int ret; |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 397 | |
| 398 | lockdep_assert_held(&dev_priv->drm.struct_mutex); |
| 399 | |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 400 | GEM_BUG_ON(guc_log_has_runtime(guc)); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 401 | |
Chris Wilson | e22d8e3 | 2017-04-12 12:01:11 +0100 | [diff] [blame] | 402 | ret = i915_gem_object_set_to_wc_domain(guc->log.vma->obj, true); |
| 403 | if (ret) |
| 404 | return ret; |
| 405 | |
Sagar Arun Kamble | 2fcf068 | 2018-01-24 21:17:00 +0530 | [diff] [blame] | 406 | /* |
| 407 | * Create a WC (Uncached for read) vmalloc mapping of log |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 408 | * buffer pages, so that we can directly get the data |
| 409 | * (up-to-date) from memory. |
| 410 | */ |
| 411 | vaddr = i915_gem_object_pin_map(guc->log.vma->obj, I915_MAP_WC); |
| 412 | if (IS_ERR(vaddr)) { |
| 413 | DRM_ERROR("Couldn't map log buffer pages %d\n", ret); |
| 414 | return PTR_ERR(vaddr); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 417 | guc->log.runtime.buf_addr = vaddr; |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 418 | |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | static void guc_log_runtime_destroy(struct intel_guc *guc) |
| 423 | { |
| 424 | /* |
| 425 | * It's possible that the runtime stuff was never allocated because |
| 426 | * GuC log was disabled at the boot time. |
| 427 | */ |
| 428 | if (!guc_log_has_runtime(guc)) |
| 429 | return; |
| 430 | |
| 431 | i915_gem_object_unpin_map(guc->log.vma->obj); |
| 432 | guc->log.runtime.buf_addr = NULL; |
| 433 | } |
| 434 | |
| 435 | void intel_guc_log_init_early(struct intel_guc *guc) |
| 436 | { |
| 437 | mutex_init(&guc->log.runtime.relay_lock); |
| 438 | INIT_WORK(&guc->log.runtime.flush_work, capture_logs_work); |
| 439 | } |
| 440 | |
| 441 | int intel_guc_log_relay_create(struct intel_guc *guc) |
| 442 | { |
| 443 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 444 | struct rchan *guc_log_relay_chan; |
| 445 | size_t n_subbufs, subbuf_size; |
| 446 | int ret; |
| 447 | |
| 448 | if (!i915_modparams.guc_log_level) |
| 449 | return 0; |
| 450 | |
| 451 | mutex_lock(&guc->log.runtime.relay_lock); |
| 452 | |
| 453 | GEM_BUG_ON(guc_log_has_relay(guc)); |
| 454 | |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 455 | /* Keep the size of sub buffers same as shared log buffer */ |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 456 | subbuf_size = GUC_LOG_SIZE; |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 457 | |
Sagar Arun Kamble | 2fcf068 | 2018-01-24 21:17:00 +0530 | [diff] [blame] | 458 | /* |
| 459 | * Store up to 8 snapshots, which is large enough to buffer sufficient |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 460 | * boot time logs and provides enough leeway to User, in terms of |
| 461 | * latency, for consuming the logs from relay. Also doesn't take |
| 462 | * up too much memory. |
| 463 | */ |
| 464 | n_subbufs = 8; |
| 465 | |
Sagar Arun Kamble | 2fcf068 | 2018-01-24 21:17:00 +0530 | [diff] [blame] | 466 | /* |
| 467 | * Create a relay channel, so that we have buffers for storing |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 468 | * the GuC firmware logs, the channel will be linked with a file |
| 469 | * later on when debugfs is registered. |
| 470 | */ |
| 471 | guc_log_relay_chan = relay_open(NULL, NULL, subbuf_size, |
| 472 | n_subbufs, &relay_callbacks, dev_priv); |
| 473 | if (!guc_log_relay_chan) { |
| 474 | DRM_ERROR("Couldn't create relay chan for GuC logging\n"); |
| 475 | |
| 476 | ret = -ENOMEM; |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 477 | goto err; |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 480 | GEM_BUG_ON(guc_log_relay_chan->subbuf_size < subbuf_size); |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 481 | guc->log.runtime.relay_chan = guc_log_relay_chan; |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 482 | |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 483 | mutex_unlock(&guc->log.runtime.relay_lock); |
| 484 | |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 485 | return 0; |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 486 | |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 487 | err: |
| 488 | mutex_unlock(&guc->log.runtime.relay_lock); |
| 489 | /* logging will be off */ |
| 490 | i915_modparams.guc_log_level = 0; |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 491 | return ret; |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 492 | } |
| 493 | |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 494 | void intel_guc_log_relay_destroy(struct intel_guc *guc) |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 495 | { |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 496 | mutex_lock(&guc->log.runtime.relay_lock); |
| 497 | |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 498 | /* |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 499 | * It's possible that the relay was never allocated because |
Michal Wajdeczko | 0ed8795 | 2018-01-11 15:24:40 +0000 | [diff] [blame] | 500 | * GuC log was disabled at the boot time. |
| 501 | */ |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 502 | if (!guc_log_has_relay(guc)) |
| 503 | goto out_unlock; |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 504 | |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 505 | relay_close(guc->log.runtime.relay_chan); |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 506 | guc->log.runtime.relay_chan = NULL; |
| 507 | |
| 508 | out_unlock: |
| 509 | mutex_unlock(&guc->log.runtime.relay_lock); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | static int guc_log_late_setup(struct intel_guc *guc) |
| 513 | { |
| 514 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 515 | int ret; |
| 516 | |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 517 | if (!guc_log_has_runtime(guc)) { |
Michal Wajdeczko | 0ed8795 | 2018-01-11 15:24:40 +0000 | [diff] [blame] | 518 | /* |
| 519 | * If log was disabled at boot time, then setup needed to handle |
| 520 | * log buffer flush interrupts would not have been done yet, so |
| 521 | * do that now. |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 522 | */ |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 523 | ret = intel_guc_log_relay_create(guc); |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 524 | if (ret) |
| 525 | goto err; |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 526 | |
| 527 | mutex_lock(&dev_priv->drm.struct_mutex); |
| 528 | intel_runtime_pm_get(dev_priv); |
| 529 | ret = guc_log_runtime_create(guc); |
| 530 | intel_runtime_pm_put(dev_priv); |
| 531 | mutex_unlock(&dev_priv->drm.struct_mutex); |
| 532 | |
| 533 | if (ret) |
| 534 | goto err_relay; |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 535 | } |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 536 | |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 537 | ret = guc_log_relay_file_create(guc); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 538 | if (ret) |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 539 | goto err_runtime; |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 540 | |
| 541 | return 0; |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 542 | |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 543 | err_runtime: |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 544 | mutex_lock(&dev_priv->drm.struct_mutex); |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 545 | guc_log_runtime_destroy(guc); |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 546 | mutex_unlock(&dev_priv->drm.struct_mutex); |
| 547 | err_relay: |
| 548 | intel_guc_log_relay_destroy(guc); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 549 | err: |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 550 | /* logging will remain off */ |
Michal Wajdeczko | 0ed8795 | 2018-01-11 15:24:40 +0000 | [diff] [blame] | 551 | i915_modparams.guc_log_level = 0; |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 552 | return ret; |
| 553 | } |
| 554 | |
| 555 | static void guc_log_capture_logs(struct intel_guc *guc) |
| 556 | { |
| 557 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 558 | |
| 559 | guc_read_update_log_buffer(guc); |
| 560 | |
Sagar Arun Kamble | 2fcf068 | 2018-01-24 21:17:00 +0530 | [diff] [blame] | 561 | /* |
| 562 | * Generally device is expected to be active only at this |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 563 | * time, so get/put should be really quick. |
| 564 | */ |
| 565 | intel_runtime_pm_get(dev_priv); |
| 566 | guc_log_flush_complete(guc); |
| 567 | intel_runtime_pm_put(dev_priv); |
| 568 | } |
| 569 | |
| 570 | static void guc_flush_logs(struct intel_guc *guc) |
| 571 | { |
| 572 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
| 573 | |
Michal Wajdeczko | 0ed8795 | 2018-01-11 15:24:40 +0000 | [diff] [blame] | 574 | if (!USES_GUC_SUBMISSION(dev_priv) || !i915_modparams.guc_log_level) |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 575 | return; |
| 576 | |
| 577 | /* First disable the interrupts, will be renabled afterwards */ |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 578 | mutex_lock(&dev_priv->drm.struct_mutex); |
| 579 | intel_runtime_pm_get(dev_priv); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 580 | gen9_disable_guc_interrupts(dev_priv); |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 581 | intel_runtime_pm_put(dev_priv); |
| 582 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 583 | |
Sagar Arun Kamble | 2fcf068 | 2018-01-24 21:17:00 +0530 | [diff] [blame] | 584 | /* |
| 585 | * Before initiating the forceful flush, wait for any pending/ongoing |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 586 | * flush to complete otherwise forceful flush may not actually happen. |
| 587 | */ |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 588 | flush_work(&guc->log.runtime.flush_work); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 589 | |
| 590 | /* Ask GuC to update the log buffer state */ |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 591 | intel_runtime_pm_get(dev_priv); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 592 | guc_log_flush(guc); |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 593 | intel_runtime_pm_put(dev_priv); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 594 | |
| 595 | /* GuC would have updated log buffer by now, so capture it */ |
| 596 | guc_log_capture_logs(guc); |
| 597 | } |
| 598 | |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 599 | int intel_guc_log_create(struct intel_guc *guc) |
| 600 | { |
| 601 | struct i915_vma *vma; |
| 602 | unsigned long offset; |
Joonas Lahtinen | faf6548 | 2017-10-06 11:49:40 +0300 | [diff] [blame] | 603 | u32 flags; |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 604 | int ret; |
| 605 | |
| 606 | GEM_BUG_ON(guc->log.vma); |
| 607 | |
Sagar Arun Kamble | 2fcf068 | 2018-01-24 21:17:00 +0530 | [diff] [blame] | 608 | /* |
| 609 | * We require SSE 4.1 for fast reads from the GuC log buffer and |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 610 | * it should be present on the chipsets supporting GuC based |
| 611 | * submisssions. |
| 612 | */ |
| 613 | if (WARN_ON(!i915_has_memcpy_from_wc())) { |
| 614 | ret = -EINVAL; |
| 615 | goto err; |
| 616 | } |
| 617 | |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 618 | vma = intel_guc_allocate_vma(guc, GUC_LOG_SIZE); |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 619 | if (IS_ERR(vma)) { |
| 620 | ret = PTR_ERR(vma); |
| 621 | goto err; |
| 622 | } |
| 623 | |
| 624 | guc->log.vma = vma; |
| 625 | |
Michal Wajdeczko | 0ed8795 | 2018-01-11 15:24:40 +0000 | [diff] [blame] | 626 | if (i915_modparams.guc_log_level) { |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 627 | ret = guc_log_runtime_create(guc); |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 628 | if (ret < 0) |
| 629 | goto err_vma; |
| 630 | } |
| 631 | |
| 632 | /* each allocated unit is a page */ |
| 633 | flags = GUC_LOG_VALID | GUC_LOG_NOTIFY_ON_HALF_FULL | |
| 634 | (GUC_LOG_DPC_PAGES << GUC_LOG_DPC_SHIFT) | |
| 635 | (GUC_LOG_ISR_PAGES << GUC_LOG_ISR_SHIFT) | |
| 636 | (GUC_LOG_CRASH_PAGES << GUC_LOG_CRASH_SHIFT); |
| 637 | |
| 638 | offset = guc_ggtt_offset(vma) >> PAGE_SHIFT; /* in pages */ |
| 639 | guc->log.flags = (offset << GUC_LOG_BUF_ADDR_SHIFT) | flags; |
| 640 | |
| 641 | return 0; |
| 642 | |
| 643 | err_vma: |
| 644 | i915_vma_unpin_and_release(&guc->log.vma); |
| 645 | err: |
| 646 | /* logging will be off */ |
Michal Wajdeczko | 0ed8795 | 2018-01-11 15:24:40 +0000 | [diff] [blame] | 647 | i915_modparams.guc_log_level = 0; |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 648 | return ret; |
| 649 | } |
| 650 | |
| 651 | void intel_guc_log_destroy(struct intel_guc *guc) |
| 652 | { |
Oscar Mateo | e746547 | 2017-03-22 10:39:48 -0700 | [diff] [blame] | 653 | guc_log_runtime_destroy(guc); |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 654 | i915_vma_unpin_and_release(&guc->log.vma); |
| 655 | } |
| 656 | |
Sagar Arun Kamble | 065dd5a | 2018-01-24 21:16:59 +0530 | [diff] [blame] | 657 | int intel_guc_log_control(struct intel_guc *guc, u64 control_val) |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 658 | { |
Sagar Arun Kamble | 065dd5a | 2018-01-24 21:16:59 +0530 | [diff] [blame] | 659 | struct drm_i915_private *dev_priv = guc_to_i915(guc); |
Michal Wajdeczko | 35fe703 | 2018-01-11 15:24:41 +0000 | [diff] [blame] | 660 | bool enable_logging = control_val > 0; |
| 661 | u32 verbosity; |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 662 | int ret; |
| 663 | |
Sagar Arun Kamble | 065dd5a | 2018-01-24 21:16:59 +0530 | [diff] [blame] | 664 | if (!guc->log.vma) |
| 665 | return -ENODEV; |
| 666 | |
Michal Wajdeczko | 35fe703 | 2018-01-11 15:24:41 +0000 | [diff] [blame] | 667 | BUILD_BUG_ON(GUC_LOG_VERBOSITY_MIN); |
| 668 | if (control_val > 1 + GUC_LOG_VERBOSITY_MAX) |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 669 | return -EINVAL; |
| 670 | |
| 671 | /* This combination doesn't make sense & won't have any effect */ |
Michal Wajdeczko | 35fe703 | 2018-01-11 15:24:41 +0000 | [diff] [blame] | 672 | if (!enable_logging && !i915_modparams.guc_log_level) |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 673 | return 0; |
| 674 | |
Michal Wajdeczko | 35fe703 | 2018-01-11 15:24:41 +0000 | [diff] [blame] | 675 | verbosity = enable_logging ? control_val - 1 : 0; |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 676 | |
| 677 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
| 678 | if (ret) |
| 679 | return ret; |
| 680 | intel_runtime_pm_get(dev_priv); |
Michal Wajdeczko | 35fe703 | 2018-01-11 15:24:41 +0000 | [diff] [blame] | 681 | ret = guc_log_control(guc, enable_logging, verbosity); |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 682 | intel_runtime_pm_put(dev_priv); |
| 683 | mutex_unlock(&dev_priv->drm.struct_mutex); |
| 684 | |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 685 | if (ret < 0) { |
| 686 | DRM_DEBUG_DRIVER("guc_logging_control action failed %d\n", ret); |
| 687 | return ret; |
| 688 | } |
| 689 | |
Michal Wajdeczko | 35fe703 | 2018-01-11 15:24:41 +0000 | [diff] [blame] | 690 | if (enable_logging) { |
| 691 | i915_modparams.guc_log_level = 1 + verbosity; |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 692 | |
Michal Wajdeczko | 0ed8795 | 2018-01-11 15:24:40 +0000 | [diff] [blame] | 693 | /* |
| 694 | * If log was disabled at boot time, then the relay channel file |
| 695 | * wouldn't have been created by now and interrupts also would |
| 696 | * not have been enabled. Try again now, just in case. |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 697 | */ |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 698 | ret = guc_log_late_setup(guc); |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 699 | if (ret < 0) { |
| 700 | DRM_DEBUG_DRIVER("GuC log late setup failed %d\n", ret); |
| 701 | return ret; |
| 702 | } |
| 703 | |
| 704 | /* GuC logging is currently the only user of Guc2Host interrupts */ |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 705 | mutex_lock(&dev_priv->drm.struct_mutex); |
| 706 | intel_runtime_pm_get(dev_priv); |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 707 | gen9_enable_guc_interrupts(dev_priv); |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 708 | intel_runtime_pm_put(dev_priv); |
| 709 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 710 | } else { |
Michal Wajdeczko | 0ed8795 | 2018-01-11 15:24:40 +0000 | [diff] [blame] | 711 | /* |
| 712 | * Once logging is disabled, GuC won't generate logs & send an |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 713 | * interrupt. But there could be some data in the log buffer |
| 714 | * which is yet to be captured. So request GuC to update the log |
| 715 | * buffer state and then collect the left over logs. |
| 716 | */ |
| 717 | guc_flush_logs(guc); |
| 718 | |
| 719 | /* As logging is disabled, update log level to reflect that */ |
Michal Wajdeczko | 0ed8795 | 2018-01-11 15:24:40 +0000 | [diff] [blame] | 720 | i915_modparams.guc_log_level = 0; |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | return ret; |
| 724 | } |
| 725 | |
| 726 | void i915_guc_log_register(struct drm_i915_private *dev_priv) |
| 727 | { |
Michal Wajdeczko | 0ed8795 | 2018-01-11 15:24:40 +0000 | [diff] [blame] | 728 | if (!USES_GUC_SUBMISSION(dev_priv) || !i915_modparams.guc_log_level) |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 729 | return; |
| 730 | |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 731 | guc_log_late_setup(&dev_priv->guc); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | void i915_guc_log_unregister(struct drm_i915_private *dev_priv) |
| 735 | { |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 736 | struct intel_guc *guc = &dev_priv->guc; |
| 737 | |
Michal Wajdeczko | 93ffbe8 | 2017-12-06 13:53:12 +0000 | [diff] [blame] | 738 | if (!USES_GUC_SUBMISSION(dev_priv)) |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 739 | return; |
| 740 | |
| 741 | mutex_lock(&dev_priv->drm.struct_mutex); |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 742 | /* GuC logging is currently the only user of Guc2Host interrupts */ |
Sagar Arun Kamble | 1be333d | 2018-01-24 21:16:56 +0530 | [diff] [blame] | 743 | intel_runtime_pm_get(dev_priv); |
Oscar Mateo | 3950bf3 | 2017-03-22 10:39:46 -0700 | [diff] [blame] | 744 | gen9_disable_guc_interrupts(dev_priv); |
Sagar Arun Kamble | 1be333d | 2018-01-24 21:16:56 +0530 | [diff] [blame] | 745 | intel_runtime_pm_put(dev_priv); |
| 746 | |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 747 | guc_log_runtime_destroy(guc); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 748 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Sagar Arun Kamble | 70deead | 2018-01-24 21:16:58 +0530 | [diff] [blame] | 749 | |
| 750 | intel_guc_log_relay_destroy(guc); |
Michal Wajdeczko | f9cda04 | 2017-01-13 17:41:57 +0000 | [diff] [blame] | 751 | } |