2 * Copyright © 2013 Intel Corporation
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:
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
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
23 * Author: Damien Lespiau <damien.lespiau@intel.com>
27 #include <linux/seq_file.h>
28 #include <linux/circ_buf.h>
29 #include <linux/ctype.h>
30 #include <linux/debugfs.h>
31 #include "intel_drv.h"
33 struct pipe_crc_info
{
35 struct drm_i915_private
*dev_priv
;
39 /* As the drm_debugfs_init() routines are called before dev->dev_private is
40 * allocated we need to hook into the minor for release.
42 static int drm_add_fake_info_node(struct drm_minor
*minor
,
43 struct dentry
*ent
, const void *key
)
45 struct drm_info_node
*node
;
47 node
= kmalloc(sizeof(*node
), GFP_KERNEL
);
55 node
->info_ent
= (void *) key
;
57 mutex_lock(&minor
->debugfs_lock
);
58 list_add(&node
->list
, &minor
->debugfs_list
);
59 mutex_unlock(&minor
->debugfs_lock
);
64 static int i915_pipe_crc_open(struct inode
*inode
, struct file
*filep
)
66 struct pipe_crc_info
*info
= inode
->i_private
;
67 struct drm_i915_private
*dev_priv
= info
->dev_priv
;
68 struct intel_pipe_crc
*pipe_crc
= &dev_priv
->pipe_crc
[info
->pipe
];
70 if (info
->pipe
>= INTEL_INFO(dev_priv
)->num_pipes
)
73 spin_lock_irq(&pipe_crc
->lock
);
75 if (pipe_crc
->opened
) {
76 spin_unlock_irq(&pipe_crc
->lock
);
77 return -EBUSY
; /* already open */
80 pipe_crc
->opened
= true;
81 filep
->private_data
= inode
->i_private
;
83 spin_unlock_irq(&pipe_crc
->lock
);
88 static int i915_pipe_crc_release(struct inode
*inode
, struct file
*filep
)
90 struct pipe_crc_info
*info
= inode
->i_private
;
91 struct drm_i915_private
*dev_priv
= info
->dev_priv
;
92 struct intel_pipe_crc
*pipe_crc
= &dev_priv
->pipe_crc
[info
->pipe
];
94 spin_lock_irq(&pipe_crc
->lock
);
95 pipe_crc
->opened
= false;
96 spin_unlock_irq(&pipe_crc
->lock
);
101 /* (6 fields, 8 chars each, space separated (5) + '\n') */
102 #define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
103 /* account for \'0' */
104 #define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
106 static int pipe_crc_data_count(struct intel_pipe_crc
*pipe_crc
)
108 assert_spin_locked(&pipe_crc
->lock
);
109 return CIRC_CNT(pipe_crc
->head
, pipe_crc
->tail
,
110 INTEL_PIPE_CRC_ENTRIES_NR
);
114 i915_pipe_crc_read(struct file
*filep
, char __user
*user_buf
, size_t count
,
117 struct pipe_crc_info
*info
= filep
->private_data
;
118 struct drm_i915_private
*dev_priv
= info
->dev_priv
;
119 struct intel_pipe_crc
*pipe_crc
= &dev_priv
->pipe_crc
[info
->pipe
];
120 char buf
[PIPE_CRC_BUFFER_LEN
];
125 * Don't allow user space to provide buffers not big enough to hold
128 if (count
< PIPE_CRC_LINE_LEN
)
131 if (pipe_crc
->source
== INTEL_PIPE_CRC_SOURCE_NONE
)
134 /* nothing to read */
135 spin_lock_irq(&pipe_crc
->lock
);
136 while (pipe_crc_data_count(pipe_crc
) == 0) {
139 if (filep
->f_flags
& O_NONBLOCK
) {
140 spin_unlock_irq(&pipe_crc
->lock
);
144 ret
= wait_event_interruptible_lock_irq(pipe_crc
->wq
,
145 pipe_crc_data_count(pipe_crc
), pipe_crc
->lock
);
147 spin_unlock_irq(&pipe_crc
->lock
);
152 /* We now have one or more entries to read */
153 n_entries
= count
/ PIPE_CRC_LINE_LEN
;
156 while (n_entries
> 0) {
157 struct intel_pipe_crc_entry
*entry
=
158 &pipe_crc
->entries
[pipe_crc
->tail
];
160 if (CIRC_CNT(pipe_crc
->head
, pipe_crc
->tail
,
161 INTEL_PIPE_CRC_ENTRIES_NR
) < 1)
164 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR
);
165 pipe_crc
->tail
= (pipe_crc
->tail
+ 1) &
166 (INTEL_PIPE_CRC_ENTRIES_NR
- 1);
168 bytes_read
+= snprintf(buf
, PIPE_CRC_BUFFER_LEN
,
169 "%8u %8x %8x %8x %8x %8x\n",
170 entry
->frame
, entry
->crc
[0],
171 entry
->crc
[1], entry
->crc
[2],
172 entry
->crc
[3], entry
->crc
[4]);
174 spin_unlock_irq(&pipe_crc
->lock
);
176 if (copy_to_user(user_buf
, buf
, PIPE_CRC_LINE_LEN
))
179 user_buf
+= PIPE_CRC_LINE_LEN
;
182 spin_lock_irq(&pipe_crc
->lock
);
185 spin_unlock_irq(&pipe_crc
->lock
);
190 static const struct file_operations i915_pipe_crc_fops
= {
191 .owner
= THIS_MODULE
,
192 .open
= i915_pipe_crc_open
,
193 .read
= i915_pipe_crc_read
,
194 .release
= i915_pipe_crc_release
,
197 static struct pipe_crc_info i915_pipe_crc_data
[I915_MAX_PIPES
] = {
199 .name
= "i915_pipe_A_crc",
203 .name
= "i915_pipe_B_crc",
207 .name
= "i915_pipe_C_crc",
212 static int i915_pipe_crc_create(struct dentry
*root
, struct drm_minor
*minor
,
215 struct drm_i915_private
*dev_priv
= to_i915(minor
->dev
);
217 struct pipe_crc_info
*info
= &i915_pipe_crc_data
[pipe
];
219 info
->dev_priv
= dev_priv
;
220 ent
= debugfs_create_file(info
->name
, S_IRUGO
, root
, info
,
221 &i915_pipe_crc_fops
);
225 return drm_add_fake_info_node(minor
, ent
, info
);
228 static const char * const pipe_crc_sources
[] = {
241 static const char *pipe_crc_source_name(enum intel_pipe_crc_source source
)
243 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources
) != INTEL_PIPE_CRC_SOURCE_MAX
);
244 return pipe_crc_sources
[source
];
247 static int display_crc_ctl_show(struct seq_file
*m
, void *data
)
249 struct drm_i915_private
*dev_priv
= m
->private;
252 for (i
= 0; i
< I915_MAX_PIPES
; i
++)
253 seq_printf(m
, "%c %s\n", pipe_name(i
),
254 pipe_crc_source_name(dev_priv
->pipe_crc
[i
].source
));
259 static int display_crc_ctl_open(struct inode
*inode
, struct file
*file
)
261 return single_open(file
, display_crc_ctl_show
, inode
->i_private
);
264 static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source
*source
,
267 if (*source
== INTEL_PIPE_CRC_SOURCE_AUTO
)
268 *source
= INTEL_PIPE_CRC_SOURCE_PIPE
;
271 case INTEL_PIPE_CRC_SOURCE_PIPE
:
272 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_INCLUDE_BORDER_I8XX
;
274 case INTEL_PIPE_CRC_SOURCE_NONE
:
284 static int i9xx_pipe_crc_auto_source(struct drm_i915_private
*dev_priv
,
286 enum intel_pipe_crc_source
*source
)
288 struct drm_device
*dev
= &dev_priv
->drm
;
289 struct intel_encoder
*encoder
;
290 struct intel_crtc
*crtc
;
291 struct intel_digital_port
*dig_port
;
294 *source
= INTEL_PIPE_CRC_SOURCE_PIPE
;
296 drm_modeset_lock_all(dev
);
297 for_each_intel_encoder(dev
, encoder
) {
298 if (!encoder
->base
.crtc
)
301 crtc
= to_intel_crtc(encoder
->base
.crtc
);
303 if (crtc
->pipe
!= pipe
)
306 switch (encoder
->type
) {
307 case INTEL_OUTPUT_TVOUT
:
308 *source
= INTEL_PIPE_CRC_SOURCE_TV
;
310 case INTEL_OUTPUT_DP
:
311 case INTEL_OUTPUT_EDP
:
312 dig_port
= enc_to_dig_port(&encoder
->base
);
313 switch (dig_port
->port
) {
315 *source
= INTEL_PIPE_CRC_SOURCE_DP_B
;
318 *source
= INTEL_PIPE_CRC_SOURCE_DP_C
;
321 *source
= INTEL_PIPE_CRC_SOURCE_DP_D
;
324 WARN(1, "nonexisting DP port %c\n",
325 port_name(dig_port
->port
));
333 drm_modeset_unlock_all(dev
);
338 static int vlv_pipe_crc_ctl_reg(struct drm_i915_private
*dev_priv
,
340 enum intel_pipe_crc_source
*source
,
343 bool need_stable_symbols
= false;
345 if (*source
== INTEL_PIPE_CRC_SOURCE_AUTO
) {
346 int ret
= i9xx_pipe_crc_auto_source(dev_priv
, pipe
, source
);
352 case INTEL_PIPE_CRC_SOURCE_PIPE
:
353 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_PIPE_VLV
;
355 case INTEL_PIPE_CRC_SOURCE_DP_B
:
356 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_DP_B_VLV
;
357 need_stable_symbols
= true;
359 case INTEL_PIPE_CRC_SOURCE_DP_C
:
360 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_DP_C_VLV
;
361 need_stable_symbols
= true;
363 case INTEL_PIPE_CRC_SOURCE_DP_D
:
364 if (!IS_CHERRYVIEW(dev_priv
))
366 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_DP_D_VLV
;
367 need_stable_symbols
= true;
369 case INTEL_PIPE_CRC_SOURCE_NONE
:
377 * When the pipe CRC tap point is after the transcoders we need
378 * to tweak symbol-level features to produce a deterministic series of
379 * symbols for a given frame. We need to reset those features only once
380 * a frame (instead of every nth symbol):
381 * - DC-balance: used to ensure a better clock recovery from the data
383 * - DisplayPort scrambling: used for EMI reduction
385 if (need_stable_symbols
) {
386 uint32_t tmp
= I915_READ(PORT_DFT2_G4X
);
388 tmp
|= DC_BALANCE_RESET_VLV
;
391 tmp
|= PIPE_A_SCRAMBLE_RESET
;
394 tmp
|= PIPE_B_SCRAMBLE_RESET
;
397 tmp
|= PIPE_C_SCRAMBLE_RESET
;
402 I915_WRITE(PORT_DFT2_G4X
, tmp
);
408 static int i9xx_pipe_crc_ctl_reg(struct drm_i915_private
*dev_priv
,
410 enum intel_pipe_crc_source
*source
,
413 bool need_stable_symbols
= false;
415 if (*source
== INTEL_PIPE_CRC_SOURCE_AUTO
) {
416 int ret
= i9xx_pipe_crc_auto_source(dev_priv
, pipe
, source
);
422 case INTEL_PIPE_CRC_SOURCE_PIPE
:
423 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_PIPE_I9XX
;
425 case INTEL_PIPE_CRC_SOURCE_TV
:
426 if (!SUPPORTS_TV(dev_priv
))
428 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_TV_PRE
;
430 case INTEL_PIPE_CRC_SOURCE_DP_B
:
431 if (!IS_G4X(dev_priv
))
433 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_DP_B_G4X
;
434 need_stable_symbols
= true;
436 case INTEL_PIPE_CRC_SOURCE_DP_C
:
437 if (!IS_G4X(dev_priv
))
439 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_DP_C_G4X
;
440 need_stable_symbols
= true;
442 case INTEL_PIPE_CRC_SOURCE_DP_D
:
443 if (!IS_G4X(dev_priv
))
445 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_DP_D_G4X
;
446 need_stable_symbols
= true;
448 case INTEL_PIPE_CRC_SOURCE_NONE
:
456 * When the pipe CRC tap point is after the transcoders we need
457 * to tweak symbol-level features to produce a deterministic series of
458 * symbols for a given frame. We need to reset those features only once
459 * a frame (instead of every nth symbol):
460 * - DC-balance: used to ensure a better clock recovery from the data
462 * - DisplayPort scrambling: used for EMI reduction
464 if (need_stable_symbols
) {
465 uint32_t tmp
= I915_READ(PORT_DFT2_G4X
);
467 WARN_ON(!IS_G4X(dev_priv
));
469 I915_WRITE(PORT_DFT_I9XX
,
470 I915_READ(PORT_DFT_I9XX
) | DC_BALANCE_RESET
);
473 tmp
|= PIPE_A_SCRAMBLE_RESET
;
475 tmp
|= PIPE_B_SCRAMBLE_RESET
;
477 I915_WRITE(PORT_DFT2_G4X
, tmp
);
483 static void vlv_undo_pipe_scramble_reset(struct drm_i915_private
*dev_priv
,
486 uint32_t tmp
= I915_READ(PORT_DFT2_G4X
);
490 tmp
&= ~PIPE_A_SCRAMBLE_RESET
;
493 tmp
&= ~PIPE_B_SCRAMBLE_RESET
;
496 tmp
&= ~PIPE_C_SCRAMBLE_RESET
;
501 if (!(tmp
& PIPE_SCRAMBLE_RESET_MASK
))
502 tmp
&= ~DC_BALANCE_RESET_VLV
;
503 I915_WRITE(PORT_DFT2_G4X
, tmp
);
507 static void g4x_undo_pipe_scramble_reset(struct drm_i915_private
*dev_priv
,
510 uint32_t tmp
= I915_READ(PORT_DFT2_G4X
);
513 tmp
&= ~PIPE_A_SCRAMBLE_RESET
;
515 tmp
&= ~PIPE_B_SCRAMBLE_RESET
;
516 I915_WRITE(PORT_DFT2_G4X
, tmp
);
518 if (!(tmp
& PIPE_SCRAMBLE_RESET_MASK
)) {
519 I915_WRITE(PORT_DFT_I9XX
,
520 I915_READ(PORT_DFT_I9XX
) & ~DC_BALANCE_RESET
);
524 static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source
*source
,
527 if (*source
== INTEL_PIPE_CRC_SOURCE_AUTO
)
528 *source
= INTEL_PIPE_CRC_SOURCE_PIPE
;
531 case INTEL_PIPE_CRC_SOURCE_PLANE1
:
532 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_PRIMARY_ILK
;
534 case INTEL_PIPE_CRC_SOURCE_PLANE2
:
535 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_SPRITE_ILK
;
537 case INTEL_PIPE_CRC_SOURCE_PIPE
:
538 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_PIPE_ILK
;
540 case INTEL_PIPE_CRC_SOURCE_NONE
:
550 static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private
*dev_priv
,
553 struct drm_device
*dev
= &dev_priv
->drm
;
554 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, PIPE_A
);
555 struct intel_crtc_state
*pipe_config
;
556 struct drm_atomic_state
*state
;
559 drm_modeset_lock_all(dev
);
560 state
= drm_atomic_state_alloc(dev
);
566 state
->acquire_ctx
= drm_modeset_legacy_acquire_ctx(&crtc
->base
);
567 pipe_config
= intel_atomic_get_crtc_state(state
, crtc
);
568 if (IS_ERR(pipe_config
)) {
569 ret
= PTR_ERR(pipe_config
);
573 pipe_config
->pch_pfit
.force_thru
= enable
;
574 if (pipe_config
->cpu_transcoder
== TRANSCODER_EDP
&&
575 pipe_config
->pch_pfit
.enabled
!= enable
)
576 pipe_config
->base
.connectors_changed
= true;
578 ret
= drm_atomic_commit(state
);
581 drm_atomic_state_put(state
);
583 WARN(ret
, "Toggling workaround to %i returns %i\n", enable
, ret
);
584 drm_modeset_unlock_all(dev
);
587 static int ivb_pipe_crc_ctl_reg(struct drm_i915_private
*dev_priv
,
589 enum intel_pipe_crc_source
*source
,
592 if (*source
== INTEL_PIPE_CRC_SOURCE_AUTO
)
593 *source
= INTEL_PIPE_CRC_SOURCE_PF
;
596 case INTEL_PIPE_CRC_SOURCE_PLANE1
:
597 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_PRIMARY_IVB
;
599 case INTEL_PIPE_CRC_SOURCE_PLANE2
:
600 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_SPRITE_IVB
;
602 case INTEL_PIPE_CRC_SOURCE_PF
:
603 if (IS_HASWELL(dev_priv
) && pipe
== PIPE_A
)
604 hsw_trans_edp_pipe_A_crc_wa(dev_priv
, true);
606 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_PF_IVB
;
608 case INTEL_PIPE_CRC_SOURCE_NONE
:
618 static int get_new_crc_ctl_reg(struct drm_i915_private
*dev_priv
,
620 enum intel_pipe_crc_source
*source
, u32
*val
)
622 if (IS_GEN2(dev_priv
))
623 return i8xx_pipe_crc_ctl_reg(source
, val
);
624 else if (INTEL_GEN(dev_priv
) < 5)
625 return i9xx_pipe_crc_ctl_reg(dev_priv
, pipe
, source
, val
);
626 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
627 return vlv_pipe_crc_ctl_reg(dev_priv
, pipe
, source
, val
);
628 else if (IS_GEN5(dev_priv
) || IS_GEN6(dev_priv
))
629 return ilk_pipe_crc_ctl_reg(source
, val
);
631 return ivb_pipe_crc_ctl_reg(dev_priv
, pipe
, source
, val
);
634 static int pipe_crc_set_source(struct drm_i915_private
*dev_priv
,
636 enum intel_pipe_crc_source source
)
638 struct intel_pipe_crc
*pipe_crc
= &dev_priv
->pipe_crc
[pipe
];
639 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, pipe
);
640 enum intel_display_power_domain power_domain
;
641 u32 val
= 0; /* shut up gcc */
644 if (pipe_crc
->source
== source
)
647 /* forbid changing the source without going back to 'none' */
648 if (pipe_crc
->source
&& source
)
651 power_domain
= POWER_DOMAIN_PIPE(pipe
);
652 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
653 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
657 ret
= get_new_crc_ctl_reg(dev_priv
, pipe
, &source
, &val
);
661 /* none -> real source transition */
663 struct intel_pipe_crc_entry
*entries
;
665 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
666 pipe_name(pipe
), pipe_crc_source_name(source
));
668 entries
= kcalloc(INTEL_PIPE_CRC_ENTRIES_NR
,
669 sizeof(pipe_crc
->entries
[0]),
677 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
678 * enabled and disabled dynamically based on package C states,
679 * user space can't make reliable use of the CRCs, so let's just
680 * completely disable it.
682 hsw_disable_ips(crtc
);
684 spin_lock_irq(&pipe_crc
->lock
);
685 kfree(pipe_crc
->entries
);
686 pipe_crc
->entries
= entries
;
689 spin_unlock_irq(&pipe_crc
->lock
);
692 pipe_crc
->source
= source
;
694 I915_WRITE(PIPE_CRC_CTL(pipe
), val
);
695 POSTING_READ(PIPE_CRC_CTL(pipe
));
697 /* real source -> none transition */
699 struct intel_pipe_crc_entry
*entries
;
700 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
,
703 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
706 drm_modeset_lock(&crtc
->base
.mutex
, NULL
);
707 if (crtc
->base
.state
->active
)
708 intel_wait_for_vblank(dev_priv
, pipe
);
709 drm_modeset_unlock(&crtc
->base
.mutex
);
711 spin_lock_irq(&pipe_crc
->lock
);
712 entries
= pipe_crc
->entries
;
713 pipe_crc
->entries
= NULL
;
716 spin_unlock_irq(&pipe_crc
->lock
);
720 if (IS_G4X(dev_priv
))
721 g4x_undo_pipe_scramble_reset(dev_priv
, pipe
);
722 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
723 vlv_undo_pipe_scramble_reset(dev_priv
, pipe
);
724 else if (IS_HASWELL(dev_priv
) && pipe
== PIPE_A
)
725 hsw_trans_edp_pipe_A_crc_wa(dev_priv
, false);
727 hsw_enable_ips(crtc
);
733 intel_display_power_put(dev_priv
, power_domain
);
739 * Parse pipe CRC command strings:
740 * command: wsp* object wsp+ name wsp+ source wsp*
743 * source: (none | plane1 | plane2 | pf)
744 * wsp: (#0x20 | #0x9 | #0xA)+
747 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
748 * "pipe A none" -> Stop CRC
750 static int display_crc_ctl_tokenize(char *buf
, char *words
[], int max_words
)
757 /* skip leading white space */
758 buf
= skip_spaces(buf
);
760 break; /* end of buffer */
762 /* find end of word */
763 for (end
= buf
; *end
&& !isspace(*end
); end
++)
766 if (n_words
== max_words
) {
767 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
769 return -EINVAL
; /* ran out of words[] before bytes */
774 words
[n_words
++] = buf
;
781 enum intel_pipe_crc_object
{
782 PIPE_CRC_OBJECT_PIPE
,
785 static const char * const pipe_crc_objects
[] = {
790 display_crc_ctl_parse_object(const char *buf
, enum intel_pipe_crc_object
*o
)
794 for (i
= 0; i
< ARRAY_SIZE(pipe_crc_objects
); i
++)
795 if (!strcmp(buf
, pipe_crc_objects
[i
])) {
803 static int display_crc_ctl_parse_pipe(const char *buf
, enum pipe
*pipe
)
805 const char name
= buf
[0];
807 if (name
< 'A' || name
>= pipe_name(I915_MAX_PIPES
))
816 display_crc_ctl_parse_source(const char *buf
, enum intel_pipe_crc_source
*s
)
821 *s
= INTEL_PIPE_CRC_SOURCE_NONE
;
825 for (i
= 0; i
< ARRAY_SIZE(pipe_crc_sources
); i
++)
826 if (!strcmp(buf
, pipe_crc_sources
[i
])) {
834 static int display_crc_ctl_parse(struct drm_i915_private
*dev_priv
,
835 char *buf
, size_t len
)
839 char *words
[N_WORDS
];
841 enum intel_pipe_crc_object object
;
842 enum intel_pipe_crc_source source
;
844 n_words
= display_crc_ctl_tokenize(buf
, words
, N_WORDS
);
845 if (n_words
!= N_WORDS
) {
846 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
851 if (display_crc_ctl_parse_object(words
[0], &object
) < 0) {
852 DRM_DEBUG_DRIVER("unknown object %s\n", words
[0]);
856 if (display_crc_ctl_parse_pipe(words
[1], &pipe
) < 0) {
857 DRM_DEBUG_DRIVER("unknown pipe %s\n", words
[1]);
861 if (display_crc_ctl_parse_source(words
[2], &source
) < 0) {
862 DRM_DEBUG_DRIVER("unknown source %s\n", words
[2]);
866 return pipe_crc_set_source(dev_priv
, pipe
, source
);
869 static ssize_t
display_crc_ctl_write(struct file
*file
, const char __user
*ubuf
,
870 size_t len
, loff_t
*offp
)
872 struct seq_file
*m
= file
->private_data
;
873 struct drm_i915_private
*dev_priv
= m
->private;
880 if (len
> PAGE_SIZE
- 1) {
881 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
886 tmpbuf
= kmalloc(len
+ 1, GFP_KERNEL
);
890 if (copy_from_user(tmpbuf
, ubuf
, len
)) {
896 ret
= display_crc_ctl_parse(dev_priv
, tmpbuf
, len
);
907 const struct file_operations i915_display_crc_ctl_fops
= {
908 .owner
= THIS_MODULE
,
909 .open
= display_crc_ctl_open
,
912 .release
= single_release
,
913 .write
= display_crc_ctl_write
916 void intel_display_crc_init(struct drm_i915_private
*dev_priv
)
920 for_each_pipe(dev_priv
, pipe
) {
921 struct intel_pipe_crc
*pipe_crc
= &dev_priv
->pipe_crc
[pipe
];
923 pipe_crc
->opened
= false;
924 spin_lock_init(&pipe_crc
->lock
);
925 init_waitqueue_head(&pipe_crc
->wq
);
929 int intel_pipe_crc_create(struct drm_minor
*minor
)
933 for (i
= 0; i
< ARRAY_SIZE(i915_pipe_crc_data
); i
++) {
934 ret
= i915_pipe_crc_create(minor
->debugfs_root
, minor
, i
);
942 void intel_pipe_crc_cleanup(struct drm_minor
*minor
)
946 for (i
= 0; i
< ARRAY_SIZE(i915_pipe_crc_data
); i
++) {
947 struct drm_info_list
*info_list
=
948 (struct drm_info_list
*)&i915_pipe_crc_data
[i
];
950 drm_debugfs_remove_files(info_list
, 1, minor
);
954 int intel_crtc_set_crc_source(struct drm_crtc
*crtc
, const char *source_name
,
957 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
958 struct intel_pipe_crc
*pipe_crc
= &dev_priv
->pipe_crc
[crtc
->index
];
959 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
960 enum intel_display_power_domain power_domain
;
961 enum intel_pipe_crc_source source
;
962 u32 val
= 0; /* shut up gcc */
965 if (display_crc_ctl_parse_source(source_name
, &source
) < 0) {
966 DRM_DEBUG_DRIVER("unknown source %s\n", source_name
);
970 power_domain
= POWER_DOMAIN_PIPE(crtc
->index
);
971 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
972 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
976 ret
= get_new_crc_ctl_reg(dev_priv
, crtc
->index
, &source
, &val
);
982 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
983 * enabled and disabled dynamically based on package C states,
984 * user space can't make reliable use of the CRCs, so let's just
985 * completely disable it.
987 hsw_disable_ips(intel_crtc
);
990 I915_WRITE(PIPE_CRC_CTL(crtc
->index
), val
);
991 POSTING_READ(PIPE_CRC_CTL(crtc
->index
));
994 if (IS_G4X(dev_priv
))
995 g4x_undo_pipe_scramble_reset(dev_priv
, crtc
->index
);
996 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
997 vlv_undo_pipe_scramble_reset(dev_priv
, crtc
->index
);
998 else if (IS_HASWELL(dev_priv
) && crtc
->index
== PIPE_A
)
999 hsw_trans_edp_pipe_A_crc_wa(dev_priv
, false);
1001 hsw_enable_ips(intel_crtc
);
1004 pipe_crc
->skipped
= 0;
1008 intel_display_power_put(dev_priv
, power_domain
);