Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/mgag200: Convert to simple KMS helper

The mgag200 supports a single pipeline with only a primary plane. It can
be converted to simple KMS helpers. This also adds support for atomic
modesetting. Wayland compositors, which use pageflip ioctls, can now be
used with mgag200.

v2:
* prepare encoder and CRTC in a separate patch
* remove suspend/resume code in a separate patch
* don't call set_format_regs() in pipe_update()

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Tested-by: John Donnelly <John.p.donnelly@oracle.com>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Acked-by: Emil Velikov <emil.velikov@collabora.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200515083233.32036-15-tzimmermann@suse.de

+168 -156
+1 -1
drivers/gpu/drm/mgag200/mgag200_drv.c
··· 140 140 } 141 141 142 142 static struct drm_driver driver = { 143 - .driver_features = DRIVER_GEM | DRIVER_MODESET, 143 + .driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET, 144 144 .fops = &mgag200_driver_fops, 145 145 .name = DRIVER_NAME, 146 146 .desc = DRIVER_DESC,
+167 -155
drivers/gpu/drm/mgag200/mgag200_mode.c
··· 11 11 #include <linux/delay.h> 12 12 #include <linux/pci.h> 13 13 14 + #include <drm/drm_atomic_helper.h> 15 + #include <drm/drm_atomic_state_helper.h> 14 16 #include <drm/drm_crtc_helper.h> 15 17 #include <drm/drm_fourcc.h> 16 18 #include <drm/drm_gem_framebuffer_helper.h> 17 19 #include <drm/drm_plane_helper.h> 20 + #include <drm/drm_print.h> 18 21 #include <drm/drm_probe_helper.h> 19 22 #include <drm/drm_simple_kms_helper.h> 20 23 ··· 33 30 { 34 31 struct drm_device *dev = crtc->dev; 35 32 struct mga_device *mdev = to_mga_device(dev); 36 - struct drm_framebuffer *fb = crtc->primary->fb; 33 + struct drm_framebuffer *fb; 37 34 u16 *r_ptr, *g_ptr, *b_ptr; 38 35 int i; 39 36 40 37 if (!crtc->enabled) 41 38 return; 39 + 40 + if (!mdev->display_pipe.plane.state) 41 + return; 42 + 43 + fb = mdev->display_pipe.plane.state->fb; 42 44 43 45 r_ptr = crtc->gamma_store; 44 46 g_ptr = r_ptr + crtc->gamma_size; ··· 877 869 WREG_ECRT(0x00, crtcext0); 878 870 } 879 871 880 - static int mga_crtc_do_set_base(struct mga_device *mdev, 881 - const struct drm_framebuffer *fb, 882 - const struct drm_framebuffer *old_fb) 883 - { 884 - struct drm_gem_vram_object *gbo; 885 - int ret; 886 - s64 gpu_addr; 887 - 888 - if (old_fb) { 889 - gbo = drm_gem_vram_of_gem(old_fb->obj[0]); 890 - drm_gem_vram_unpin(gbo); 891 - } 892 - 893 - gbo = drm_gem_vram_of_gem(fb->obj[0]); 894 - 895 - ret = drm_gem_vram_pin(gbo, DRM_GEM_VRAM_PL_FLAG_VRAM); 896 - if (ret) 897 - return ret; 898 - gpu_addr = drm_gem_vram_offset(gbo); 899 - if (gpu_addr < 0) { 900 - ret = (int)gpu_addr; 901 - goto err_drm_gem_vram_unpin; 902 - } 903 - 904 - mgag200_set_startadd(mdev, (unsigned long)gpu_addr); 905 - 906 - return 0; 907 - 908 - err_drm_gem_vram_unpin: 909 - drm_gem_vram_unpin(gbo); 910 - return ret; 911 - } 912 - 913 - static int mga_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, 914 - struct drm_framebuffer *old_fb) 915 - { 916 - struct drm_device *dev = crtc->dev; 917 - struct mga_device *mdev = dev->dev_private; 918 - struct drm_framebuffer *fb = crtc->primary->fb; 919 - unsigned int count; 920 - 921 - do { } while (RREG8(0x1fda) & 0x08); 922 - do { } while (!(RREG8(0x1fda) & 0x08)); 923 - 924 - count = RREG8(MGAREG_VCOUNT) + 2; 925 - do { } while (RREG8(MGAREG_VCOUNT) < count); 926 - 927 - return mga_crtc_do_set_base(mdev, fb, old_fb); 928 - } 929 - 930 872 static void mgag200_set_pci_regs(struct mga_device *mdev) 931 873 { 932 874 uint32_t option = 0, option2 = 0; ··· 1287 1329 WREG_ECRT(0x06, 0x00); 1288 1330 } 1289 1331 1290 - static int mga_crtc_mode_set(struct drm_crtc *crtc, 1291 - struct drm_display_mode *mode, 1292 - struct drm_display_mode *adjusted_mode, 1293 - int x, int y, struct drm_framebuffer *old_fb) 1294 - { 1295 - struct drm_device *dev = crtc->dev; 1296 - struct mga_device *mdev = to_mga_device(dev); 1297 - const struct drm_framebuffer *fb = crtc->primary->fb; 1298 - 1299 - mgag200_init_regs(mdev); 1300 - 1301 - mgag200_set_format_regs(mdev, fb); 1302 - mga_crtc_do_set_base(mdev, fb, old_fb); 1303 - mgag200_set_offset(mdev, fb); 1304 - 1305 - mgag200_set_mode_regs(mdev, mode); 1306 - 1307 - if (mdev->type == G200_ER) 1308 - mgag200_g200er_reset_tagfifo(mdev); 1309 - 1310 - if (IS_G200_SE(mdev)) 1311 - mgag200_g200se_set_hiprilvl(mdev, mode, fb); 1312 - else if (mdev->type == G200_EV) 1313 - mgag200_g200ev_set_hiprilvl(mdev); 1314 - 1315 - return 0; 1316 - } 1317 - 1318 1332 static void mga_crtc_dpms(struct drm_crtc *crtc, int mode) 1319 1333 { 1320 1334 struct drm_device *dev = crtc->dev; ··· 1369 1439 { 1370 1440 struct drm_device *dev = crtc->dev; 1371 1441 struct mga_device *mdev = to_mga_device(dev); 1372 - const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; 1373 1442 u8 tmp; 1374 1443 1375 1444 if (mdev->type == G200_WB || mdev->type == G200_EW3) ··· 1387 1458 WREG_SEQ(0x1, tmp); 1388 1459 WREG_SEQ(0, 3); 1389 1460 } 1390 - crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON); 1391 - } 1392 - 1393 - /* 1394 - * The core can pass us a set of gamma values to program. We actually only 1395 - * use this for 8-bit mode so can't perform smooth fades on deeper modes, 1396 - * but it's a requirement that we provide the function 1397 - */ 1398 - static int mga_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, 1399 - u16 *blue, uint32_t size, 1400 - struct drm_modeset_acquire_ctx *ctx) 1401 - { 1402 - mga_crtc_load_lut(crtc); 1403 - 1404 - return 0; 1405 - } 1406 - 1407 - static void mga_crtc_disable(struct drm_crtc *crtc) 1408 - { 1409 - DRM_DEBUG_KMS("\n"); 1410 - mga_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); 1411 - if (crtc->primary->fb) { 1412 - struct drm_framebuffer *fb = crtc->primary->fb; 1413 - struct drm_gem_vram_object *gbo = 1414 - drm_gem_vram_of_gem(fb->obj[0]); 1415 - drm_gem_vram_unpin(gbo); 1416 - } 1417 - crtc->primary->fb = NULL; 1418 - } 1419 - 1420 - /* These provide the minimum set of functions required to handle a CRTC */ 1421 - static const struct drm_crtc_funcs mga_crtc_funcs = { 1422 - .gamma_set = mga_crtc_gamma_set, 1423 - .set_config = drm_crtc_helper_set_config, 1424 - .destroy = drm_crtc_cleanup, 1425 - }; 1426 - 1427 - static const struct drm_crtc_helper_funcs mga_helper_funcs = { 1428 - .disable = mga_crtc_disable, 1429 - .dpms = mga_crtc_dpms, 1430 - .mode_set = mga_crtc_mode_set, 1431 - .mode_set_base = mga_crtc_mode_set_base, 1432 - .prepare = mga_crtc_prepare, 1433 - .commit = mga_crtc_commit, 1434 - }; 1435 - 1436 - /* CRTC setup */ 1437 - static void mga_crtc_init(struct mga_device *mdev) 1438 - { 1439 - struct drm_device *dev = mdev->dev; 1440 - struct drm_crtc *crtc = &mdev->display_pipe.crtc; 1441 - 1442 - drm_crtc_init(dev, crtc, &mga_crtc_funcs); 1443 - 1444 - drm_mode_crtc_set_gamma_size(crtc, MGAG200_LUT_SIZE); 1445 - 1446 - drm_crtc_helper_add(crtc, &mga_helper_funcs); 1461 + mga_crtc_dpms(crtc, DRM_MODE_DPMS_ON); 1447 1462 } 1448 1463 1449 1464 /* ··· 1521 1648 } 1522 1649 1523 1650 static const struct drm_connector_helper_funcs mga_vga_connector_helper_funcs = { 1524 - .get_modes = mga_vga_get_modes, 1651 + .get_modes = mga_vga_get_modes, 1525 1652 .mode_valid = mga_vga_mode_valid, 1526 1653 }; 1527 1654 1528 1655 static const struct drm_connector_funcs mga_vga_connector_funcs = { 1529 - .dpms = drm_helper_connector_dpms, 1530 - .fill_modes = drm_helper_probe_single_connector_modes, 1531 - .destroy = mga_connector_destroy, 1656 + .reset = drm_atomic_helper_connector_reset, 1657 + .fill_modes = drm_helper_probe_single_connector_modes, 1658 + .destroy = mga_connector_destroy, 1659 + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 1660 + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 1532 1661 }; 1533 1662 1534 1663 static int mgag200_vga_connector_init(struct mga_device *mdev) ··· 1562 1687 return ret; 1563 1688 } 1564 1689 1690 + /* 1691 + * Simple Display Pipe 1692 + */ 1693 + 1694 + static enum drm_mode_status 1695 + mgag200_simple_display_pipe_mode_valid(struct drm_simple_display_pipe *pipe, 1696 + const struct drm_display_mode *mode) 1697 + { 1698 + return MODE_OK; 1699 + } 1700 + 1701 + static void 1702 + mgag200_simple_display_pipe_enable(struct drm_simple_display_pipe *pipe, 1703 + struct drm_crtc_state *crtc_state, 1704 + struct drm_plane_state *plane_state) 1705 + { 1706 + struct drm_crtc *crtc = &pipe->crtc; 1707 + struct drm_device *dev = crtc->dev; 1708 + struct mga_device *mdev = to_mga_device(dev); 1709 + struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode; 1710 + struct drm_framebuffer *fb = plane_state->fb; 1711 + struct drm_gem_vram_object *gbo; 1712 + s64 gpu_addr; 1713 + 1714 + gbo = drm_gem_vram_of_gem(fb->obj[0]); 1715 + 1716 + gpu_addr = drm_gem_vram_offset(gbo); 1717 + if (drm_WARN_ON_ONCE(dev, gpu_addr < 0)) 1718 + return; /* BUG: BO should have been pinned to VRAM. */ 1719 + 1720 + mga_crtc_prepare(crtc); 1721 + 1722 + mgag200_set_format_regs(mdev, fb); 1723 + mgag200_set_mode_regs(mdev, adjusted_mode); 1724 + 1725 + if (mdev->type == G200_ER) 1726 + mgag200_g200er_reset_tagfifo(mdev); 1727 + 1728 + if (IS_G200_SE(mdev)) 1729 + mgag200_g200se_set_hiprilvl(mdev, adjusted_mode, fb); 1730 + else if (mdev->type == G200_EV) 1731 + mgag200_g200ev_set_hiprilvl(mdev); 1732 + 1733 + mga_crtc_commit(crtc); 1734 + } 1735 + 1736 + static void 1737 + mgag200_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe) 1738 + { 1739 + struct drm_crtc *crtc = &pipe->crtc; 1740 + 1741 + mga_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); 1742 + } 1743 + 1744 + static int 1745 + mgag200_simple_display_pipe_check(struct drm_simple_display_pipe *pipe, 1746 + struct drm_plane_state *plane_state, 1747 + struct drm_crtc_state *crtc_state) 1748 + { 1749 + struct drm_plane *plane = plane_state->plane; 1750 + struct drm_framebuffer *new_fb = plane_state->fb; 1751 + struct drm_framebuffer *fb = NULL; 1752 + 1753 + if (!new_fb) 1754 + return 0; 1755 + 1756 + if (plane->state) 1757 + fb = plane->state->fb; 1758 + 1759 + if (!fb || (fb->format != new_fb->format)) 1760 + crtc_state->mode_changed = true; /* update PLL settings */ 1761 + 1762 + return 0; 1763 + } 1764 + 1765 + static void 1766 + mgag200_simple_display_pipe_update(struct drm_simple_display_pipe *pipe, 1767 + struct drm_plane_state *old_state) 1768 + { 1769 + struct drm_plane *plane = &pipe->plane; 1770 + struct drm_device *dev = plane->dev; 1771 + struct mga_device *mdev = to_mga_device(dev); 1772 + struct drm_plane_state *state = plane->state; 1773 + struct drm_framebuffer *fb = state->fb; 1774 + struct drm_gem_vram_object *gbo; 1775 + s64 gpu_addr; 1776 + 1777 + if (!fb) 1778 + return; 1779 + 1780 + gbo = drm_gem_vram_of_gem(fb->obj[0]); 1781 + 1782 + gpu_addr = drm_gem_vram_offset(gbo); 1783 + if (drm_WARN_ON_ONCE(dev, gpu_addr < 0)) 1784 + return; /* BUG: BO should have been pinned to VRAM. */ 1785 + 1786 + mgag200_set_startadd(mdev, (unsigned long)gpu_addr); 1787 + mgag200_set_offset(mdev, fb); 1788 + } 1789 + 1790 + static const struct drm_simple_display_pipe_funcs 1791 + mgag200_simple_display_pipe_funcs = { 1792 + .mode_valid = mgag200_simple_display_pipe_mode_valid, 1793 + .enable = mgag200_simple_display_pipe_enable, 1794 + .disable = mgag200_simple_display_pipe_disable, 1795 + .check = mgag200_simple_display_pipe_check, 1796 + .update = mgag200_simple_display_pipe_update, 1797 + .prepare_fb = drm_gem_vram_simple_display_pipe_prepare_fb, 1798 + .cleanup_fb = drm_gem_vram_simple_display_pipe_cleanup_fb, 1799 + }; 1800 + 1801 + static const uint32_t mgag200_simple_display_pipe_formats[] = { 1802 + DRM_FORMAT_XRGB8888, 1803 + DRM_FORMAT_RGB565, 1804 + DRM_FORMAT_RGB888, 1805 + }; 1806 + 1807 + static const uint64_t mgag200_simple_display_pipe_fmtmods[] = { 1808 + DRM_FORMAT_MOD_LINEAR, 1809 + DRM_FORMAT_MOD_INVALID 1810 + }; 1811 + 1812 + /* 1813 + * Mode config 1814 + */ 1815 + 1565 1816 static const struct drm_mode_config_funcs mgag200_mode_config_funcs = { 1566 - .fb_create = drm_gem_fb_create 1817 + .fb_create = drm_gem_fb_create, 1818 + .mode_valid = drm_vram_helper_mode_valid, 1819 + .atomic_check = drm_atomic_helper_check, 1820 + .atomic_commit = drm_atomic_helper_commit, 1567 1821 }; 1568 1822 1569 1823 static unsigned int mgag200_preferred_depth(struct mga_device *mdev) ··· 1706 1702 int mgag200_modeset_init(struct mga_device *mdev) 1707 1703 { 1708 1704 struct drm_device *dev = mdev->dev; 1709 - struct drm_encoder *encoder = &mdev->display_pipe.encoder; 1710 1705 struct drm_connector *connector = &mdev->connector.base; 1706 + struct drm_simple_display_pipe *pipe = &mdev->display_pipe; 1707 + size_t format_count = ARRAY_SIZE(mgag200_simple_display_pipe_formats); 1711 1708 int ret; 1712 1709 1713 1710 mdev->bpp_shifts[0] = 0; 1714 1711 mdev->bpp_shifts[1] = 1; 1715 1712 mdev->bpp_shifts[2] = 0; 1716 1713 mdev->bpp_shifts[3] = 2; 1714 + 1715 + mgag200_init_regs(mdev); 1717 1716 1718 1717 ret = drmm_mode_config_init(dev); 1719 1718 if (ret) { ··· 1735 1728 1736 1729 dev->mode_config.funcs = &mgag200_mode_config_funcs; 1737 1730 1738 - mga_crtc_init(mdev); 1739 - 1740 - ret = drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_DAC); 1741 - if (ret) { 1742 - drm_err(dev, 1743 - "drm_simple_encoder_init() failed, error %d\n", 1744 - ret); 1745 - return ret; 1746 - } 1747 - encoder->possible_crtcs = 0x1; 1748 - 1749 1731 ret = mgag200_vga_connector_init(mdev); 1750 1732 if (ret) { 1751 1733 drm_err(dev, ··· 1743 1747 return ret; 1744 1748 } 1745 1749 1746 - drm_connector_attach_encoder(connector, encoder); 1750 + ret = drm_simple_display_pipe_init(dev, pipe, 1751 + &mgag200_simple_display_pipe_funcs, 1752 + mgag200_simple_display_pipe_formats, 1753 + format_count, 1754 + mgag200_simple_display_pipe_fmtmods, 1755 + connector); 1756 + if (ret) { 1757 + drm_err(dev, 1758 + "drm_simple_display_pipe_init() failed, error %d\n", 1759 + ret); 1760 + return ret; 1761 + } 1762 + 1763 + /* FIXME: legacy gamma tables; convert to CRTC state */ 1764 + drm_mode_crtc_set_gamma_size(&pipe->crtc, MGAG200_LUT_SIZE); 1765 + 1766 + drm_mode_config_reset(dev); 1747 1767 1748 1768 return 0; 1749 1769 }