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 static int i915_pipe_crc_open(struct inode
*inode
, struct file
*filep
)
41 struct pipe_crc_info
*info
= inode
->i_private
;
42 struct drm_i915_private
*dev_priv
= info
->dev_priv
;
43 struct intel_pipe_crc
*pipe_crc
= &dev_priv
->pipe_crc
[info
->pipe
];
45 if (info
->pipe
>= INTEL_INFO(dev_priv
)->num_pipes
)
48 spin_lock_irq(&pipe_crc
->lock
);
50 if (pipe_crc
->opened
) {
51 spin_unlock_irq(&pipe_crc
->lock
);
52 return -EBUSY
; /* already open */
55 pipe_crc
->opened
= true;
56 filep
->private_data
= inode
->i_private
;
58 spin_unlock_irq(&pipe_crc
->lock
);
63 static int i915_pipe_crc_release(struct inode
*inode
, struct file
*filep
)
65 struct pipe_crc_info
*info
= inode
->i_private
;
66 struct drm_i915_private
*dev_priv
= info
->dev_priv
;
67 struct intel_pipe_crc
*pipe_crc
= &dev_priv
->pipe_crc
[info
->pipe
];
69 spin_lock_irq(&pipe_crc
->lock
);
70 pipe_crc
->opened
= false;
71 spin_unlock_irq(&pipe_crc
->lock
);
76 /* (6 fields, 8 chars each, space separated (5) + '\n') */
77 #define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
78 /* account for \'0' */
79 #define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
81 static int pipe_crc_data_count(struct intel_pipe_crc
*pipe_crc
)
83 lockdep_assert_held(&pipe_crc
->lock
);
84 return CIRC_CNT(pipe_crc
->head
, pipe_crc
->tail
,
85 INTEL_PIPE_CRC_ENTRIES_NR
);
89 i915_pipe_crc_read(struct file
*filep
, char __user
*user_buf
, size_t count
,
92 struct pipe_crc_info
*info
= filep
->private_data
;
93 struct drm_i915_private
*dev_priv
= info
->dev_priv
;
94 struct intel_pipe_crc
*pipe_crc
= &dev_priv
->pipe_crc
[info
->pipe
];
95 char buf
[PIPE_CRC_BUFFER_LEN
];
100 * Don't allow user space to provide buffers not big enough to hold
103 if (count
< PIPE_CRC_LINE_LEN
)
106 if (pipe_crc
->source
== INTEL_PIPE_CRC_SOURCE_NONE
)
109 /* nothing to read */
110 spin_lock_irq(&pipe_crc
->lock
);
111 while (pipe_crc_data_count(pipe_crc
) == 0) {
114 if (filep
->f_flags
& O_NONBLOCK
) {
115 spin_unlock_irq(&pipe_crc
->lock
);
119 ret
= wait_event_interruptible_lock_irq(pipe_crc
->wq
,
120 pipe_crc_data_count(pipe_crc
), pipe_crc
->lock
);
122 spin_unlock_irq(&pipe_crc
->lock
);
127 /* We now have one or more entries to read */
128 n_entries
= count
/ PIPE_CRC_LINE_LEN
;
131 while (n_entries
> 0) {
132 struct intel_pipe_crc_entry
*entry
=
133 &pipe_crc
->entries
[pipe_crc
->tail
];
135 if (CIRC_CNT(pipe_crc
->head
, pipe_crc
->tail
,
136 INTEL_PIPE_CRC_ENTRIES_NR
) < 1)
139 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR
);
140 pipe_crc
->tail
= (pipe_crc
->tail
+ 1) &
141 (INTEL_PIPE_CRC_ENTRIES_NR
- 1);
143 bytes_read
+= snprintf(buf
, PIPE_CRC_BUFFER_LEN
,
144 "%8u %8x %8x %8x %8x %8x\n",
145 entry
->frame
, entry
->crc
[0],
146 entry
->crc
[1], entry
->crc
[2],
147 entry
->crc
[3], entry
->crc
[4]);
149 spin_unlock_irq(&pipe_crc
->lock
);
151 if (copy_to_user(user_buf
, buf
, PIPE_CRC_LINE_LEN
))
154 user_buf
+= PIPE_CRC_LINE_LEN
;
157 spin_lock_irq(&pipe_crc
->lock
);
160 spin_unlock_irq(&pipe_crc
->lock
);
165 static const struct file_operations i915_pipe_crc_fops
= {
166 .owner
= THIS_MODULE
,
167 .open
= i915_pipe_crc_open
,
168 .read
= i915_pipe_crc_read
,
169 .release
= i915_pipe_crc_release
,
172 static struct pipe_crc_info i915_pipe_crc_data
[I915_MAX_PIPES
] = {
174 .name
= "i915_pipe_A_crc",
178 .name
= "i915_pipe_B_crc",
182 .name
= "i915_pipe_C_crc",
187 static const char * const pipe_crc_sources
[] = {
200 static const char *pipe_crc_source_name(enum intel_pipe_crc_source source
)
202 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources
) != INTEL_PIPE_CRC_SOURCE_MAX
);
203 return pipe_crc_sources
[source
];
206 static int display_crc_ctl_show(struct seq_file
*m
, void *data
)
208 struct drm_i915_private
*dev_priv
= m
->private;
211 for_each_pipe(dev_priv
, pipe
)
212 seq_printf(m
, "%c %s\n", pipe_name(pipe
),
213 pipe_crc_source_name(dev_priv
->pipe_crc
[pipe
].source
));
218 static int display_crc_ctl_open(struct inode
*inode
, struct file
*file
)
220 return single_open(file
, display_crc_ctl_show
, inode
->i_private
);
223 static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source
*source
,
226 if (*source
== INTEL_PIPE_CRC_SOURCE_AUTO
)
227 *source
= INTEL_PIPE_CRC_SOURCE_PIPE
;
230 case INTEL_PIPE_CRC_SOURCE_PIPE
:
231 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_INCLUDE_BORDER_I8XX
;
233 case INTEL_PIPE_CRC_SOURCE_NONE
:
243 static int i9xx_pipe_crc_auto_source(struct drm_i915_private
*dev_priv
,
245 enum intel_pipe_crc_source
*source
)
247 struct drm_device
*dev
= &dev_priv
->drm
;
248 struct intel_encoder
*encoder
;
249 struct intel_crtc
*crtc
;
250 struct intel_digital_port
*dig_port
;
253 *source
= INTEL_PIPE_CRC_SOURCE_PIPE
;
255 drm_modeset_lock_all(dev
);
256 for_each_intel_encoder(dev
, encoder
) {
257 if (!encoder
->base
.crtc
)
260 crtc
= to_intel_crtc(encoder
->base
.crtc
);
262 if (crtc
->pipe
!= pipe
)
265 switch (encoder
->type
) {
266 case INTEL_OUTPUT_TVOUT
:
267 *source
= INTEL_PIPE_CRC_SOURCE_TV
;
269 case INTEL_OUTPUT_DP
:
270 case INTEL_OUTPUT_EDP
:
271 dig_port
= enc_to_dig_port(&encoder
->base
);
272 switch (dig_port
->base
.port
) {
274 *source
= INTEL_PIPE_CRC_SOURCE_DP_B
;
277 *source
= INTEL_PIPE_CRC_SOURCE_DP_C
;
280 *source
= INTEL_PIPE_CRC_SOURCE_DP_D
;
283 WARN(1, "nonexisting DP port %c\n",
284 port_name(dig_port
->base
.port
));
292 drm_modeset_unlock_all(dev
);
297 static int vlv_pipe_crc_ctl_reg(struct drm_i915_private
*dev_priv
,
299 enum intel_pipe_crc_source
*source
,
302 bool need_stable_symbols
= false;
304 if (*source
== INTEL_PIPE_CRC_SOURCE_AUTO
) {
305 int ret
= i9xx_pipe_crc_auto_source(dev_priv
, pipe
, source
);
311 case INTEL_PIPE_CRC_SOURCE_PIPE
:
312 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_PIPE_VLV
;
314 case INTEL_PIPE_CRC_SOURCE_DP_B
:
315 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_DP_B_VLV
;
316 need_stable_symbols
= true;
318 case INTEL_PIPE_CRC_SOURCE_DP_C
:
319 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_DP_C_VLV
;
320 need_stable_symbols
= true;
322 case INTEL_PIPE_CRC_SOURCE_DP_D
:
323 if (!IS_CHERRYVIEW(dev_priv
))
325 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_DP_D_VLV
;
326 need_stable_symbols
= true;
328 case INTEL_PIPE_CRC_SOURCE_NONE
:
336 * When the pipe CRC tap point is after the transcoders we need
337 * to tweak symbol-level features to produce a deterministic series of
338 * symbols for a given frame. We need to reset those features only once
339 * a frame (instead of every nth symbol):
340 * - DC-balance: used to ensure a better clock recovery from the data
342 * - DisplayPort scrambling: used for EMI reduction
344 if (need_stable_symbols
) {
345 uint32_t tmp
= I915_READ(PORT_DFT2_G4X
);
347 tmp
|= DC_BALANCE_RESET_VLV
;
350 tmp
|= PIPE_A_SCRAMBLE_RESET
;
353 tmp
|= PIPE_B_SCRAMBLE_RESET
;
356 tmp
|= PIPE_C_SCRAMBLE_RESET
;
361 I915_WRITE(PORT_DFT2_G4X
, tmp
);
367 static int i9xx_pipe_crc_ctl_reg(struct drm_i915_private
*dev_priv
,
369 enum intel_pipe_crc_source
*source
,
372 bool need_stable_symbols
= false;
374 if (*source
== INTEL_PIPE_CRC_SOURCE_AUTO
) {
375 int ret
= i9xx_pipe_crc_auto_source(dev_priv
, pipe
, source
);
381 case INTEL_PIPE_CRC_SOURCE_PIPE
:
382 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_PIPE_I9XX
;
384 case INTEL_PIPE_CRC_SOURCE_TV
:
385 if (!SUPPORTS_TV(dev_priv
))
387 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_TV_PRE
;
389 case INTEL_PIPE_CRC_SOURCE_DP_B
:
390 if (!IS_G4X(dev_priv
))
392 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_DP_B_G4X
;
393 need_stable_symbols
= true;
395 case INTEL_PIPE_CRC_SOURCE_DP_C
:
396 if (!IS_G4X(dev_priv
))
398 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_DP_C_G4X
;
399 need_stable_symbols
= true;
401 case INTEL_PIPE_CRC_SOURCE_DP_D
:
402 if (!IS_G4X(dev_priv
))
404 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_DP_D_G4X
;
405 need_stable_symbols
= true;
407 case INTEL_PIPE_CRC_SOURCE_NONE
:
415 * When the pipe CRC tap point is after the transcoders we need
416 * to tweak symbol-level features to produce a deterministic series of
417 * symbols for a given frame. We need to reset those features only once
418 * a frame (instead of every nth symbol):
419 * - DC-balance: used to ensure a better clock recovery from the data
421 * - DisplayPort scrambling: used for EMI reduction
423 if (need_stable_symbols
) {
424 uint32_t tmp
= I915_READ(PORT_DFT2_G4X
);
426 WARN_ON(!IS_G4X(dev_priv
));
428 I915_WRITE(PORT_DFT_I9XX
,
429 I915_READ(PORT_DFT_I9XX
) | DC_BALANCE_RESET
);
432 tmp
|= PIPE_A_SCRAMBLE_RESET
;
434 tmp
|= PIPE_B_SCRAMBLE_RESET
;
436 I915_WRITE(PORT_DFT2_G4X
, tmp
);
442 static void vlv_undo_pipe_scramble_reset(struct drm_i915_private
*dev_priv
,
445 uint32_t tmp
= I915_READ(PORT_DFT2_G4X
);
449 tmp
&= ~PIPE_A_SCRAMBLE_RESET
;
452 tmp
&= ~PIPE_B_SCRAMBLE_RESET
;
455 tmp
&= ~PIPE_C_SCRAMBLE_RESET
;
460 if (!(tmp
& PIPE_SCRAMBLE_RESET_MASK
))
461 tmp
&= ~DC_BALANCE_RESET_VLV
;
462 I915_WRITE(PORT_DFT2_G4X
, tmp
);
466 static void g4x_undo_pipe_scramble_reset(struct drm_i915_private
*dev_priv
,
469 uint32_t tmp
= I915_READ(PORT_DFT2_G4X
);
472 tmp
&= ~PIPE_A_SCRAMBLE_RESET
;
474 tmp
&= ~PIPE_B_SCRAMBLE_RESET
;
475 I915_WRITE(PORT_DFT2_G4X
, tmp
);
477 if (!(tmp
& PIPE_SCRAMBLE_RESET_MASK
)) {
478 I915_WRITE(PORT_DFT_I9XX
,
479 I915_READ(PORT_DFT_I9XX
) & ~DC_BALANCE_RESET
);
483 static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source
*source
,
486 if (*source
== INTEL_PIPE_CRC_SOURCE_AUTO
)
487 *source
= INTEL_PIPE_CRC_SOURCE_PIPE
;
490 case INTEL_PIPE_CRC_SOURCE_PLANE1
:
491 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_PRIMARY_ILK
;
493 case INTEL_PIPE_CRC_SOURCE_PLANE2
:
494 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_SPRITE_ILK
;
496 case INTEL_PIPE_CRC_SOURCE_PIPE
:
497 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_PIPE_ILK
;
499 case INTEL_PIPE_CRC_SOURCE_NONE
:
509 static void hsw_pipe_A_crc_wa(struct drm_i915_private
*dev_priv
,
512 struct drm_device
*dev
= &dev_priv
->drm
;
513 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
, PIPE_A
);
514 struct intel_crtc_state
*pipe_config
;
515 struct drm_atomic_state
*state
;
516 struct drm_modeset_acquire_ctx ctx
;
519 drm_modeset_acquire_init(&ctx
, 0);
521 state
= drm_atomic_state_alloc(dev
);
527 state
->acquire_ctx
= &ctx
;
530 pipe_config
= intel_atomic_get_crtc_state(state
, crtc
);
531 if (IS_ERR(pipe_config
)) {
532 ret
= PTR_ERR(pipe_config
);
536 if (HAS_IPS(dev_priv
)) {
538 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
539 * enabled and disabled dynamically based on package C states,
540 * user space can't make reliable use of the CRCs, so let's just
541 * completely disable it.
543 pipe_config
->ips_force_disable
= enable
;
546 if (IS_HASWELL(dev_priv
)) {
547 pipe_config
->pch_pfit
.force_thru
= enable
;
548 if (pipe_config
->cpu_transcoder
== TRANSCODER_EDP
&&
549 pipe_config
->pch_pfit
.enabled
!= enable
)
550 pipe_config
->base
.connectors_changed
= true;
553 ret
= drm_atomic_commit(state
);
556 if (ret
== -EDEADLK
) {
557 drm_atomic_state_clear(state
);
558 drm_modeset_backoff(&ctx
);
562 drm_atomic_state_put(state
);
564 WARN(ret
, "Toggling workaround to %i returns %i\n", enable
, ret
);
565 drm_modeset_drop_locks(&ctx
);
566 drm_modeset_acquire_fini(&ctx
);
569 static int ivb_pipe_crc_ctl_reg(struct drm_i915_private
*dev_priv
,
571 enum intel_pipe_crc_source
*source
,
574 if (*source
== INTEL_PIPE_CRC_SOURCE_AUTO
)
575 *source
= INTEL_PIPE_CRC_SOURCE_PF
;
578 case INTEL_PIPE_CRC_SOURCE_PLANE1
:
579 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_PRIMARY_IVB
;
581 case INTEL_PIPE_CRC_SOURCE_PLANE2
:
582 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_SPRITE_IVB
;
584 case INTEL_PIPE_CRC_SOURCE_PF
:
585 if ((IS_HASWELL(dev_priv
) ||
586 IS_BROADWELL(dev_priv
)) && pipe
== PIPE_A
)
587 hsw_pipe_A_crc_wa(dev_priv
, true);
589 *val
= PIPE_CRC_ENABLE
| PIPE_CRC_SOURCE_PF_IVB
;
591 case INTEL_PIPE_CRC_SOURCE_NONE
:
601 static int get_new_crc_ctl_reg(struct drm_i915_private
*dev_priv
,
603 enum intel_pipe_crc_source
*source
, u32
*val
)
605 if (IS_GEN2(dev_priv
))
606 return i8xx_pipe_crc_ctl_reg(source
, val
);
607 else if (INTEL_GEN(dev_priv
) < 5)
608 return i9xx_pipe_crc_ctl_reg(dev_priv
, pipe
, source
, val
);
609 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
610 return vlv_pipe_crc_ctl_reg(dev_priv
, pipe
, source
, val
);
611 else if (IS_GEN5(dev_priv
) || IS_GEN6(dev_priv
))
612 return ilk_pipe_crc_ctl_reg(source
, val
);
614 return ivb_pipe_crc_ctl_reg(dev_priv
, pipe
, source
, val
);
617 static int pipe_crc_set_source(struct drm_i915_private
*dev_priv
,
619 enum intel_pipe_crc_source source
)
621 struct intel_pipe_crc
*pipe_crc
= &dev_priv
->pipe_crc
[pipe
];
622 enum intel_display_power_domain power_domain
;
623 u32 val
= 0; /* shut up gcc */
626 if (pipe_crc
->source
== source
)
629 /* forbid changing the source without going back to 'none' */
630 if (pipe_crc
->source
&& source
)
633 power_domain
= POWER_DOMAIN_PIPE(pipe
);
634 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
635 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
639 ret
= get_new_crc_ctl_reg(dev_priv
, pipe
, &source
, &val
);
643 /* none -> real source transition */
645 struct intel_pipe_crc_entry
*entries
;
647 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
648 pipe_name(pipe
), pipe_crc_source_name(source
));
650 entries
= kcalloc(INTEL_PIPE_CRC_ENTRIES_NR
,
651 sizeof(pipe_crc
->entries
[0]),
658 spin_lock_irq(&pipe_crc
->lock
);
659 kfree(pipe_crc
->entries
);
660 pipe_crc
->entries
= entries
;
663 spin_unlock_irq(&pipe_crc
->lock
);
666 pipe_crc
->source
= source
;
668 I915_WRITE(PIPE_CRC_CTL(pipe
), val
);
669 POSTING_READ(PIPE_CRC_CTL(pipe
));
671 /* real source -> none transition */
673 struct intel_pipe_crc_entry
*entries
;
674 struct intel_crtc
*crtc
= intel_get_crtc_for_pipe(dev_priv
,
677 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
680 drm_modeset_lock(&crtc
->base
.mutex
, NULL
);
681 if (crtc
->base
.state
->active
)
682 intel_wait_for_vblank(dev_priv
, pipe
);
683 drm_modeset_unlock(&crtc
->base
.mutex
);
685 spin_lock_irq(&pipe_crc
->lock
);
686 entries
= pipe_crc
->entries
;
687 pipe_crc
->entries
= NULL
;
690 spin_unlock_irq(&pipe_crc
->lock
);
694 if (IS_G4X(dev_priv
))
695 g4x_undo_pipe_scramble_reset(dev_priv
, pipe
);
696 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
697 vlv_undo_pipe_scramble_reset(dev_priv
, pipe
);
698 else if ((IS_HASWELL(dev_priv
) ||
699 IS_BROADWELL(dev_priv
)) && pipe
== PIPE_A
)
700 hsw_pipe_A_crc_wa(dev_priv
, false);
706 intel_display_power_put(dev_priv
, power_domain
);
712 * Parse pipe CRC command strings:
713 * command: wsp* object wsp+ name wsp+ source wsp*
716 * source: (none | plane1 | plane2 | pf)
717 * wsp: (#0x20 | #0x9 | #0xA)+
720 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
721 * "pipe A none" -> Stop CRC
723 static int display_crc_ctl_tokenize(char *buf
, char *words
[], int max_words
)
730 /* skip leading white space */
731 buf
= skip_spaces(buf
);
733 break; /* end of buffer */
735 /* find end of word */
736 for (end
= buf
; *end
&& !isspace(*end
); end
++)
739 if (n_words
== max_words
) {
740 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
742 return -EINVAL
; /* ran out of words[] before bytes */
747 words
[n_words
++] = buf
;
754 enum intel_pipe_crc_object
{
755 PIPE_CRC_OBJECT_PIPE
,
758 static const char * const pipe_crc_objects
[] = {
763 display_crc_ctl_parse_object(const char *buf
, enum intel_pipe_crc_object
*o
)
767 for (i
= 0; i
< ARRAY_SIZE(pipe_crc_objects
); i
++)
768 if (!strcmp(buf
, pipe_crc_objects
[i
])) {
776 static int display_crc_ctl_parse_pipe(struct drm_i915_private
*dev_priv
,
777 const char *buf
, enum pipe
*pipe
)
779 const char name
= buf
[0];
781 if (name
< 'A' || name
>= pipe_name(INTEL_INFO(dev_priv
)->num_pipes
))
790 display_crc_ctl_parse_source(const char *buf
, enum intel_pipe_crc_source
*s
)
795 *s
= INTEL_PIPE_CRC_SOURCE_NONE
;
799 for (i
= 0; i
< ARRAY_SIZE(pipe_crc_sources
); i
++)
800 if (!strcmp(buf
, pipe_crc_sources
[i
])) {
808 static int display_crc_ctl_parse(struct drm_i915_private
*dev_priv
,
809 char *buf
, size_t len
)
813 char *words
[N_WORDS
];
815 enum intel_pipe_crc_object object
;
816 enum intel_pipe_crc_source source
;
818 n_words
= display_crc_ctl_tokenize(buf
, words
, N_WORDS
);
819 if (n_words
!= N_WORDS
) {
820 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
825 if (display_crc_ctl_parse_object(words
[0], &object
) < 0) {
826 DRM_DEBUG_DRIVER("unknown object %s\n", words
[0]);
830 if (display_crc_ctl_parse_pipe(dev_priv
, words
[1], &pipe
) < 0) {
831 DRM_DEBUG_DRIVER("unknown pipe %s\n", words
[1]);
835 if (display_crc_ctl_parse_source(words
[2], &source
) < 0) {
836 DRM_DEBUG_DRIVER("unknown source %s\n", words
[2]);
840 return pipe_crc_set_source(dev_priv
, pipe
, source
);
843 static ssize_t
display_crc_ctl_write(struct file
*file
, const char __user
*ubuf
,
844 size_t len
, loff_t
*offp
)
846 struct seq_file
*m
= file
->private_data
;
847 struct drm_i915_private
*dev_priv
= m
->private;
854 if (len
> PAGE_SIZE
- 1) {
855 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
860 tmpbuf
= memdup_user_nul(ubuf
, len
);
862 return PTR_ERR(tmpbuf
);
864 ret
= display_crc_ctl_parse(dev_priv
, tmpbuf
, len
);
874 const struct file_operations i915_display_crc_ctl_fops
= {
875 .owner
= THIS_MODULE
,
876 .open
= display_crc_ctl_open
,
879 .release
= single_release
,
880 .write
= display_crc_ctl_write
883 void intel_display_crc_init(struct drm_i915_private
*dev_priv
)
887 for_each_pipe(dev_priv
, pipe
) {
888 struct intel_pipe_crc
*pipe_crc
= &dev_priv
->pipe_crc
[pipe
];
890 pipe_crc
->opened
= false;
891 spin_lock_init(&pipe_crc
->lock
);
892 init_waitqueue_head(&pipe_crc
->wq
);
896 int intel_pipe_crc_create(struct drm_minor
*minor
)
898 struct drm_i915_private
*dev_priv
= to_i915(minor
->dev
);
902 for (i
= 0; i
< ARRAY_SIZE(i915_pipe_crc_data
); i
++) {
903 struct pipe_crc_info
*info
= &i915_pipe_crc_data
[i
];
905 info
->dev_priv
= dev_priv
;
906 ent
= debugfs_create_file(info
->name
, S_IRUGO
,
907 minor
->debugfs_root
, info
,
908 &i915_pipe_crc_fops
);
916 int intel_crtc_set_crc_source(struct drm_crtc
*crtc
, const char *source_name
,
919 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
920 struct intel_pipe_crc
*pipe_crc
= &dev_priv
->pipe_crc
[crtc
->index
];
921 enum intel_display_power_domain power_domain
;
922 enum intel_pipe_crc_source source
;
923 u32 val
= 0; /* shut up gcc */
926 if (display_crc_ctl_parse_source(source_name
, &source
) < 0) {
927 DRM_DEBUG_DRIVER("unknown source %s\n", source_name
);
931 power_domain
= POWER_DOMAIN_PIPE(crtc
->index
);
932 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
)) {
933 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
937 ret
= get_new_crc_ctl_reg(dev_priv
, crtc
->index
, &source
, &val
);
941 I915_WRITE(PIPE_CRC_CTL(crtc
->index
), val
);
942 POSTING_READ(PIPE_CRC_CTL(crtc
->index
));
945 if (IS_G4X(dev_priv
))
946 g4x_undo_pipe_scramble_reset(dev_priv
, crtc
->index
);
947 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
948 vlv_undo_pipe_scramble_reset(dev_priv
, crtc
->index
);
949 else if ((IS_HASWELL(dev_priv
) ||
950 IS_BROADWELL(dev_priv
)) && crtc
->index
== PIPE_A
)
951 hsw_pipe_A_crc_wa(dev_priv
, false);
954 pipe_crc
->skipped
= 0;
958 intel_display_power_put(dev_priv
, power_domain
);