|
30 | 30 | #include <nvhw/class/cl507e.h>
|
31 | 31 | #include <nvhw/class/clc37e.h>
|
32 | 32 |
|
| 33 | +#include <linux/iosys-map.h> |
| 34 | + |
33 | 35 | #include <drm/drm_atomic.h>
|
34 | 36 | #include <drm/drm_atomic_helper.h>
|
35 | 37 | #include <drm/drm_blend.h>
|
36 |
| -#include <drm/drm_gem_atomic_helper.h> |
37 | 38 | #include <drm/drm_fourcc.h>
|
| 39 | +#include <drm/drm_framebuffer.h> |
| 40 | +#include <drm/drm_gem_atomic_helper.h> |
| 41 | +#include <drm/drm_panic.h> |
| 42 | +#include <drm/ttm/ttm_bo.h> |
38 | 43 |
|
39 | 44 | #include "nouveau_bo.h"
|
40 | 45 | #include "nouveau_gem.h"
|
| 46 | +#include "tile.h" |
41 | 47 |
|
42 | 48 | static void
|
43 | 49 | nv50_wndw_ctxdma_del(struct nv50_wndw_ctxdma *ctxdma)
|
@@ -577,13 +583,129 @@ nv50_wndw_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state)
|
577 | 583 | return 0;
|
578 | 584 | }
|
579 | 585 |
|
| 586 | +/* Only used by drm_panic get_scanout_buffer() and set_pixel(), so it is |
| 587 | + * protected by the drm panic spinlock |
| 588 | + */ |
| 589 | +static u32 nv50_panic_blk_h; |
| 590 | + |
| 591 | +/* Return the framebuffer offset of the start of the block where pixel(x,y) is */ |
| 592 | +static u32 |
| 593 | +nv50_get_block_off(unsigned int x, unsigned int y, unsigned int pitch) |
| 594 | +{ |
| 595 | + u32 blk_x, blk_y, blk_columns; |
| 596 | + |
| 597 | + blk_columns = nouveau_get_width_in_blocks(pitch); |
| 598 | + blk_x = (x * 4) / NV_TILE_GOB_WIDTH_BYTES; |
| 599 | + blk_y = y / nv50_panic_blk_h; |
| 600 | + |
| 601 | + return ((blk_y * blk_columns) + blk_x) * NV_TILE_GOB_WIDTH_BYTES * nv50_panic_blk_h; |
| 602 | +} |
| 603 | + |
| 604 | +/* Turing and later have 2 level of tiles inside the block */ |
| 605 | +static void |
| 606 | +nv50_set_pixel_swizzle(struct drm_scanout_buffer *sb, unsigned int x, |
| 607 | + unsigned int y, u32 color) |
| 608 | +{ |
| 609 | + u32 blk_off, off, swizzle; |
| 610 | + |
| 611 | + blk_off = nv50_get_block_off(x, y, sb->pitch[0]); |
| 612 | + |
| 613 | + y = y % nv50_panic_blk_h; |
| 614 | + |
| 615 | + /* Inside the block, use the fast address swizzle to compute the offset |
| 616 | + * For nvidia blocklinear, bit order is yn..y3 x3 y2 x2 y1 y0 x1 x0 |
| 617 | + */ |
| 618 | + swizzle = (x & 3) | (y & 3) << 2 | (x & 4) << 2 | (y & 4) << 3; |
| 619 | + swizzle |= (x & 8) << 3 | (y >> 3) << 7; |
| 620 | + off = blk_off + swizzle * 4; |
| 621 | + |
| 622 | + iosys_map_wr(&sb->map[0], off, u32, color); |
| 623 | +} |
| 624 | + |
| 625 | +static void |
| 626 | +nv50_set_pixel(struct drm_scanout_buffer *sb, unsigned int x, unsigned int y, |
| 627 | + u32 color) |
| 628 | +{ |
| 629 | + u32 blk_off, off; |
| 630 | + |
| 631 | + blk_off = nv50_get_block_off(x, y, sb->width); |
| 632 | + |
| 633 | + x = x % (NV_TILE_GOB_WIDTH_BYTES / 4); |
| 634 | + y = y % nv50_panic_blk_h; |
| 635 | + off = blk_off + x * 4 + y * NV_TILE_GOB_WIDTH_BYTES; |
| 636 | + |
| 637 | + iosys_map_wr(&sb->map[0], off, u32, color); |
| 638 | +} |
| 639 | + |
| 640 | +static int |
| 641 | +nv50_wndw_get_scanout_buffer(struct drm_plane *plane, struct drm_scanout_buffer *sb) |
| 642 | +{ |
| 643 | + struct drm_framebuffer *fb; |
| 644 | + struct nouveau_bo *nvbo; |
| 645 | + struct nouveau_drm *drm = nouveau_drm(plane->dev); |
| 646 | + u16 chipset = drm->client.device.info.chipset; |
| 647 | + u8 family = drm->client.device.info.family; |
| 648 | + u32 tile_mode; |
| 649 | + u8 kind; |
| 650 | + |
| 651 | + if (!plane->state || !plane->state->fb) |
| 652 | + return -EINVAL; |
| 653 | + |
| 654 | + fb = plane->state->fb; |
| 655 | + nvbo = nouveau_gem_object(fb->obj[0]); |
| 656 | + |
| 657 | + /* Don't support compressed format, or multiplane yet. */ |
| 658 | + if (nvbo->comp || fb->format->num_planes != 1) |
| 659 | + return -EOPNOTSUPP; |
| 660 | + |
| 661 | + if (nouveau_bo_map(nvbo)) { |
| 662 | + drm_warn(plane->dev, "nouveau bo map failed, panic won't be displayed\n"); |
| 663 | + return -ENOMEM; |
| 664 | + } |
| 665 | + |
| 666 | + if (nvbo->kmap.bo_kmap_type & TTM_BO_MAP_IOMEM_MASK) |
| 667 | + iosys_map_set_vaddr_iomem(&sb->map[0], (void __iomem *)nvbo->kmap.virtual); |
| 668 | + else |
| 669 | + iosys_map_set_vaddr(&sb->map[0], nvbo->kmap.virtual); |
| 670 | + |
| 671 | + sb->height = fb->height; |
| 672 | + sb->width = fb->width; |
| 673 | + sb->pitch[0] = fb->pitches[0]; |
| 674 | + sb->format = fb->format; |
| 675 | + |
| 676 | + nouveau_framebuffer_get_layout(fb, &tile_mode, &kind); |
| 677 | + if (kind) { |
| 678 | + /* If tiling is enabled, use set_pixel() to display correctly. |
| 679 | + * Only handle 32bits format for now. |
| 680 | + */ |
| 681 | + if (fb->format->cpp[0] != 4) |
| 682 | + return -EOPNOTSUPP; |
| 683 | + nv50_panic_blk_h = nouveau_get_gob_height(family) * |
| 684 | + nouveau_get_gobs_in_block(tile_mode, chipset); |
| 685 | + |
| 686 | + if (chipset >= 0x160) |
| 687 | + sb->set_pixel = nv50_set_pixel_swizzle; |
| 688 | + else |
| 689 | + sb->set_pixel = nv50_set_pixel; |
| 690 | + } |
| 691 | + return 0; |
| 692 | +} |
| 693 | + |
580 | 694 | static const struct drm_plane_helper_funcs
|
581 | 695 | nv50_wndw_helper = {
|
582 | 696 | .prepare_fb = nv50_wndw_prepare_fb,
|
583 | 697 | .cleanup_fb = nv50_wndw_cleanup_fb,
|
584 | 698 | .atomic_check = nv50_wndw_atomic_check,
|
585 | 699 | };
|
586 | 700 |
|
| 701 | +static const struct drm_plane_helper_funcs |
| 702 | +nv50_wndw_primary_helper = { |
| 703 | + .prepare_fb = nv50_wndw_prepare_fb, |
| 704 | + .cleanup_fb = nv50_wndw_cleanup_fb, |
| 705 | + .atomic_check = nv50_wndw_atomic_check, |
| 706 | + .get_scanout_buffer = nv50_wndw_get_scanout_buffer, |
| 707 | +}; |
| 708 | + |
587 | 709 | static void
|
588 | 710 | nv50_wndw_atomic_destroy_state(struct drm_plane *plane,
|
589 | 711 | struct drm_plane_state *state)
|
@@ -732,7 +854,10 @@ nv50_wndw_new_(const struct nv50_wndw_func *func, struct drm_device *dev,
|
732 | 854 | return ret;
|
733 | 855 | }
|
734 | 856 |
|
735 |
| - drm_plane_helper_add(&wndw->plane, &nv50_wndw_helper); |
| 857 | + if (type == DRM_PLANE_TYPE_PRIMARY) |
| 858 | + drm_plane_helper_add(&wndw->plane, &nv50_wndw_primary_helper); |
| 859 | + else |
| 860 | + drm_plane_helper_add(&wndw->plane, &nv50_wndw_helper); |
736 | 861 |
|
737 | 862 | if (wndw->func->ilut) {
|
738 | 863 | ret = nv50_lut_init(disp, mmu, &wndw->ilut);
|
|
0 commit comments