Skip to contentSkip to conversation

Atari DRM driver

PATCH In review Geert Uytterhoeven 5 participants 19 messages Nov 25, 2022 – May 30, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Atari DRM driver

Hi all,

This RFC patch series adds a DRM driver for the good old Atari ST/TT/Falcon hardware. It was developed and tested (only) on the ARAnyM emulator.

Supported formats:
- C[1248],
- RG16 (both standard DRM (little-endian) and native (big-endian)),
- XR24.

Patch overview:
1. The first patch adds two new helper functions for chunky-to-planar conversion,
2. The second patch, posted by Thomas Zimmermann a long time ago, introduces a mode_fixup simple kms helper function (more helpers from his fbdev conversion helper function series have been included (partially) in the Atari DRM driver itself),
3. The third patch is the actual Atari DRM driver. The patch was created with "git format-patch -C", to avoid spamming you with code that is identical to the existing Atari fbdev driver.

The driver is definitely not yet ready for upstream inclusion. While mode switching usually works, it is far from optimal, and may suffer from hick-ups. Hence the main objective for posting this preliminary version is to receive feedback about the (wrong) helper functions and callbacks I am using, and about what/how to improve.

Dependencies:
- drm-next
- Patch series [1] and [2],
- For running modetest, you want to apply patch series [3], [4], and

    [5] to libdrm.

For your testing convenience, I have pushed this series and its dependencies to [6].

Thanks for your comments!

P.S. If you are more interested in the journey than in the destination,
perhaps you are interested in the presentation I gave at last ELC-E?[7]

[1] "[PATCH resend v2] drm/fourcc: Add missing big-endian XRGB1555 and

    RGB565 formats"
    https://lore.kernel.org/r/3ee1f8144feb96c28742b22384189f1f83bcfc1a.1669221671.git.geert@linux-m68k.org
[2] "[PATCH v3 0/2] drm/modes: Command line mode selection improvements"
    https://lore.kernel.org/r/[email protected]

[3] "[PATCH libdrm v2 00/10] Add support for low-color frame buffer

    formats"
    https://lore.kernel.org/r/[email protected]
[4] "[PATCH libdrm v2 00/10] Big-endian fixes"
    https://lore.kernel.org/r/[email protected]

[5] "[PATCH libdrm] modetest: Add support for named modes containing
dashes"
[6] https://git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git/log/?h=atari-drm-wip-v1
[7] https://osseu2022.sched.com/event/15z6T/trading-fbdev-for-drm-no-returns-accepted-geert-uytterhoeven-glider-bv

Geert Uytterhoeven (2):
video: fbdev: c2p: Add transp2() and transp2x()
drm: atari: Add a DRM driver for Atari graphics hardware

Thomas Zimmermann (1):
drm/simple-kms-helper: Add mode_fixup() to simple display pipe

 drivers/gpu/drm/drm_simple_kms_helper.c       |   15 +
 drivers/gpu/drm/tiny/Kconfig                  |    8 +
 drivers/gpu/drm/tiny/Makefile                 |    1 +
 .../atafb.c => gpu/drm/tiny/atari_drm.c}      | 2536 +++++++++++++----
 drivers/video/fbdev/c2p_core.h                |   38 +
 include/drm/drm_simple_kms_helper.h           |   43 +
 6 files changed, 2113 insertions(+), 528 deletions(-)
 copy drivers/{video/fbdev/atafb.c => gpu/drm/tiny/atari_drm.c} (57%)
Signature · 12 lines
2.25.1

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds
#1 lore raw

PATCH 1/3 video: fbdev: c2p: Add transp2() and transp2x()

Add transpose operations on two 32-bit words, using normal or reverse order.

To be used by the Atari DRM driver.

---
 drivers/video/fbdev/c2p_core.h | 38 ++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
drivers/video/fbdev/c2p_core.h +38 -0
index cf5f1ebce65e6afd..480bd80fb31b57c0 100644
@@ -142,6 +142,44 @@ static __always_inline void transp4x(u32 d[], unsigned int n, unsigned int m)
 }
 
 
+    /*
+     *  Transpose operations on 2 32-bit words
+     */
+
+static __always_inline void transp2(u32 d[], unsigned int n, unsigned int m)
+{
+	u32 mask = get_mask(n);
+
+	switch (m) {
+	case 1:
+		/* Single n x 1 block */
+		_transp(d, 0, 1, n, mask);
+		return;
+	}
+
+	BUILD_BUG();
+}
+
+
+    /*
+     *  Transpose operations on 2 32-bit words (reverse order)
+     */
+
+static __always_inline void transp2x(u32 d[], unsigned int n, unsigned int m)
+{
+	u32 mask = get_mask(n);
+
+	switch (m) {
+	case 1:
+		/* Single n x 1 block */
+		_transp(d, 1, 0, n, mask);
+		return;
+	}
+
+	BUILD_BUG();
+}
+
+
     /*
      *  Compose two values, using a bitmask as decision value
      *  This is equivalent to (a & mask) | (b & ~mask)
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/3 drm/simple-kms-helper: Add mode_fixup() to simple display pipe

In reply to Geert Uytterhoeven

From: Thomas Zimmermann <[email protected]>

The mode fix-up function for simple display helpers is equivalent to the regular pipeline's CRTC mode fix-up function. It's called to adjust the CRTC's display mode for the encoder. Add this function for DRM fbconv helpers.

---
 drivers/gpu/drm/drm_simple_kms_helper.c | 15 +++++++++
 include/drm/drm_simple_kms_helper.h     | 43 +++++++++++++++++++++++++
 2 files changed, 58 insertions(+)
drivers/gpu/drm/drm_simple_kms_helper.c +15 -0
index 3ef420ec4534aab5..3d7f859ac9de6814 100644
@@ -96,6 +96,20 @@ drm_simple_kms_crtc_mode_valid(struct drm_crtc *crtc,
 	return pipe->funcs->mode_valid(pipe, mode);
 }
 
+static bool
+drm_simple_kms_crtc_mode_fixup(struct drm_crtc *crtc,
+			       const struct drm_display_mode *mode,
+			       struct drm_display_mode *adjusted_mode)
+{
+	struct drm_simple_display_pipe *pipe;
+
+	pipe = container_of(crtc, struct drm_simple_display_pipe, crtc);
+	if (!pipe->funcs || !pipe->funcs->mode_fixup)
+		return true;
+
+	return pipe->funcs->mode_fixup(crtc, mode, adjusted_mode);
+}
+
 static int drm_simple_kms_crtc_check(struct drm_crtc *crtc,
 				     struct drm_atomic_state *state)
 {
@@ -141,6 +155,7 @@ static void drm_simple_kms_crtc_disable(struct drm_crtc *crtc,
 
 static const struct drm_crtc_helper_funcs drm_simple_kms_crtc_helper_funcs = {
 	.mode_valid = drm_simple_kms_crtc_mode_valid,
+	.mode_fixup = drm_simple_kms_crtc_mode_fixup,
 	.atomic_check = drm_simple_kms_crtc_check,
 	.atomic_enable = drm_simple_kms_crtc_enable,
 	.atomic_disable = drm_simple_kms_crtc_disable,
include/drm/drm_simple_kms_helper.h +43 -0

49 lines not on this page · raw message

Signature · 1 line
2.25.1
#3 lore raw

Re: [PATCH/RFC 2/3] drm/simple-kms-helper: Add mode_fixup() to simple display pipe

Hi,

Quoted 9 lines · Geert Uytterhoeven

From: Thomas Zimmermann <[email protected]>

The mode fix-up function for simple display helpers is equivalent to the regular pipeline's CRTC mode fix-up function. It's called to adjust the CRTC's display mode for the encoder. Add this function for DRM fbconv helpers.

It's not clear to me why you'd need a mode_fixup in the first place. Like said in the documentation you added, atomic_check is usually the better option for the atomic modesetting drivers.

So, why is it needed?

Maxime

#4 lore raw

PATCH 3/3 drm: atari: Add a DRM driver for Atari graphics hardware

In reply to Geert Uytterhoeven

Supported formats:
- C[1248],
- RG16 (both standard DRM (little-endian) and native (big-endian)),
- XR24.

RG16 and XR24 are only supported with the underlying RGB565 hardware mode on Falcon, and are subject to hardware restrictions (limited to e.g. "qvga" and "hvga" modes).

All formats use a shadow buffer (TODO: BE RG16 buffers from ST-RAM). Initial mode setting works, later mode changes sometimes fail.

Developed and tested on ARAnyM.

Probably this should not be under /tiny ;-)

root@atari:~# modetest -M atari_drm
Encoders:
id	crtc	type	possible crtcs	possible clones
35	34	none	0x00000001	0x00000001

Connectors:
id encoder status name size (mm) modes encoders
31 35 connected VGA-1 0x0 9 35
modes:
index name refresh (Hz) hdisp hss hse htot vdisp vss vse vtot
#0 vga70 70.72 640 658 758 800 400 411 414 445 25176 flags: nhsync, pvsync, pcsync; type: preferred, driver #1 tt-mid 60.33 640 740 880 1000 480 496 526 534 32216 flags: nhsync, nvsync, ncsync; type: driver #2 vga 59.94 640 658 758 800 480 491 494 525 25176 flags: nhsync, nvsync, ncsync; type: driver #3 st-high 78.51 640 640 768 896 400 414 418 458 32216 flags: nhsync, nvsync, ncsync; type: driver #4 tt-low 88.72 320 420 560 680 480 496 526 534 32216 flags: nhsync, nvsync, ncsync; type: driver #5 hvga 59.94 320 329 379 400 480 491 494 525 12588 flags: nhsync, nvsync, ncsync; type: driver #6 st-mid 165.03 640 656 752 784 200 214 218 249 32216 flags: nhsync, nvsync, ncsync; type: driver #7 qvga 60.06 320 329 379 400 240 245 247 262 12588 flags: nhsync, nvsync, dblscan, ncsync; type: driver #8 st-low 278.84 320 336 432 464 200 214 218 249 32216 flags: nhsync, nvsync, ncsync; type: driver props:

	1 EDID:
		flags: immutable blob
		blobs:

		value:
	2 DPMS:
		flags: enum
		enums: On=0 Standby=1 Suspend=2 Off=3
		value: 0
	5 link-status:
		flags: enum
		enums: Good=0 Bad=1
		value: 0
	6 non-desktop:
		flags: immutable range
		values: 0 1
		value: 0
	4 TILE:
		flags: immutable blob
		blobs:

		value:

CRTCs:
id fb pos size
34 36 (0,0) (320x240)
#0 qvga 60.06 320 329 379 400 240 245 247 262 12588 flags: nhsync, nvsync, dblscan, ncsync; type: driver props:

	24 VRR_ENABLED:
		flags: range
		values: 0 1
		value: 0
	28 GAMMA_LUT:
		flags: blob
		blobs:

		value:
			000000000000000000000000aaaa0000
			0000aaaa000000000000aaaaaaaa0000
			aaaa000000000000aaaa0000aaaa0000
			aaaa555500000000aaaaaaaaaaaa0000
			555555555555000055555555ffff0000
			5555ffff555500005555ffffffff0000
			ffff555555550000ffff5555ffff0000
			ffffffff55550000ffffffffffff0000
			10001000100000001100110011000000
			12001200120000001300130013000000
			14001400140000001500150015000000
			16001600160000001700170017000000
			18001800180000001900190019000000
			1a001a001a0000001b001b001b000000
			1c001c001c0000001d001d001d000000
			1e001e001e0000001f001f001f000000
			20002000200000002100210021000000
			22002200220000002300230023000000
			24002400240000002500250025000000
			26002600260000002700270027000000
			28002800280000002900290029000000
			2a002a002a0000002b002b002b000000
			2c002c002c0000002d002d002d000000
			2e002e002e0000002f002f002f000000
			30003000300000003100310031000000
			32003200320000003300330033000000
			34003400340000003500350035000000
			36003600360000003700370037000000
			38003800380000003900390039000000
			3a003a003a0000003b003b003b000000
			3c003c003c0000003d003d003d000000
			3e003e003e0000003f003f003f000000
			40004000400000004100410041000000
			42004200420000004300430043000000
			44004400440000004500450045000000
			46004600460000004700470047000000
			48004800480000004900490049000000
			4a004a004a0000004b004b004b000000
			4c004c004c0000004d004d004d000000
			4e004e004e0000004f004f004f000000
			50005000500000005100510051000000
			52005200520000005300530053000000
			54005400540000005500550055000000
			56005600560000005700570057000000
			58005800580000005900590059000000
			5a005a005a0000005b005b005b000000
			5c005c005c0000005d005d005d000000
			5e005e005e0000005f005f005f000000
			60006000600000006100610061000000
			62006200620000006300630063000000
			64006400640000006500650065000000
			66006600660000006700670067000000
			68006800680000006900690069000000
			6a006a006a0000006b006b006b000000
			6c006c006c0000006d006d006d000000
			6e006e006e0000006f006f006f000000
			70007000700000007100710071000000
			72007200720000007300730073000000
			74007400740000007500750075000000
			76007600760000007700770077000000
			78007800780000007900790079000000
			7a007a007a0000007b007b007b000000
			7c007c007c0000007d007d007d000000
			7e007e007e0000007f007f007f000000
			80008000800000008100810081000000
			82008200820000008300830083000000
			84008400840000008500850085000000
			86008600860000008700870087000000
			88008800880000008900890089000000
			8a008a008a0000008b008b008b000000
			8c008c008c0000008d008d008d000000
			8e008e008e0000008f008f008f000000
			90009000900000009100910091000000
			92009200920000009300930093000000
			94009400940000009500950095000000
			96009600960000009700970097000000
			98009800980000009900990099000000
			9a009a009a0000009b009b009b000000
			9c009c009c0000009d009d009d000000
			9e009e009e0000009f009f009f000000
			a000a000a0000000a100a100a1000000
			a200a200a2000000a300a300a3000000
			a400a400a4000000a500a500a5000000
			a600a600a6000000a700a700a7000000
			a800a800a8000000a900a900a9000000
			aa00aa00aa000000ab00ab00ab000000
			ac00ac00ac000000ad00ad00ad000000
			ae00ae00ae000000af00af00af000000
			b000b000b0000000b100b100b1000000
			b200b200b2000000b300b300b3000000
			b400b400b4000000b500b500b5000000
			b600b600b6000000b700b700b7000000
			b800b800b8000000b900b900b9000000
			ba00ba00ba000000bb00bb00bb000000
			bc00bc00bc000000bd00bd00bd000000
			be00be00be000000bf00bf00bf000000
			c000c000c0000000c100c100c1000000
			c200c200c2000000c300c300c3000000
			c400c400c4000000c500c500c5000000
			c600c600c6000000c700c700c7000000
			c800c800c8000000c900c900c9000000
			ca00ca00ca000000cb00cb00cb000000
			cc00cc00cc000000cd00cd00cd000000
			ce00ce00ce000000cf00cf00cf000000
			d000d000d0000000d100d100d1000000
			d200d200d2000000d300d300d3000000
			d400d400d4000000d500d500d5000000
			d600d600d6000000d700d700d7000000
			d800d800d8000000d900d900d9000000
			da00da00da000000db00db00db000000
			dc00dc00dc000000dd00dd00dd000000
			de00de00de000000df00df00df000000
			e000e000e0000000e100e100e1000000
			e200e200e2000000e300e300e3000000
			e400e400e4000000e500e500e5000000
			e600e600e6000000e700e700e7000000
			e800e800e8000000e900e900e9000000
			ea00ea00ea000000eb00eb00eb000000
			ec00ec00ec000000ed00ed00ed000000
			ee00ee00ee000000ef00ef00ef000000
			f000f000f0000000f100f100f1000000
			f200f200f2000000f300f300f3000000
			f400f400f4000000f500f500f5000000
			f600f600f6000000f700f700f7000000
			f800f800f8000000f900f900f9000000
			fa00fa00fa000000fb00fb00fb000000
			fc00fc00fc000000fd00fd00fd000000
			fe00fe00fe000000ff00ff00ff000000
	29 GAMMA_LUT_SIZE:
		flags: immutable range
		values: 0 4294967295
		value: 256

Planes:
id crtc fb CRTC x,y x,y gamma size possible crtcs
32 34 36 0,0 0,0 0 0x00000001
formats: C1 C2 C4 C8 RG16 RG16be XR24
props:
8 type:
flags: immutable enum
enums: Overlay=0 Primary=1 Cursor=2
value: 1
30 IN_FORMATS:
flags: immutable blob blobs:

value:
00000001000000000000000700000018 00000001000000382020314320203243 202034432020384336314752b6314752 3432525800000000000000000000007f 00000000000000000000000000000000
in_formats blob decoded:
C1 : LINEAR
C2 : LINEAR
C4 : LINEAR
C8 : LINEAR
RG16: LINEAR
RG16be: LINEAR
XR24: LINEAR

Frame buffers:
id size pitch

root@atari:~#

---
 drivers/gpu/drm/tiny/Kconfig                  |    8 +
 drivers/gpu/drm/tiny/Makefile                 |    1 +
 .../atafb.c => gpu/drm/tiny/atari_drm.c}      | 2536 +++++++++++++----
 3 files changed, 2017 insertions(+), 528 deletions(-)
 copy drivers/{video/fbdev/atafb.c => gpu/drm/tiny/atari_drm.c} (57%)
drivers/gpu/drm/tiny/Kconfig +8 -0
index f6889f649bc18217..177ccf40f05a2b99 100644
@@ -10,6 +10,14 @@ config DRM_ARCPGU
 
 	  If M is selected the module will be called arcpgu.
 
+config DRM_ATARI
+	tristate "DRM support for Atari native chipset"
+	depends on DRM && ATARI
+	select DRM_KMS_HELPER
+	select DRM_GEM_SHMEM_HELPER
+	help
+	 This is a KMS driver for the builtin graphics chipset found in Ataris.
+
 config DRM_BOCHS
 	tristate "DRM Support for bochs dispi vga interface (qemu stdvga)"
 	depends on DRM && PCI && MMU
drivers/gpu/drm/tiny/Makefile +1 -0
index 76dde89a044b7ddd..1f54bdfee1623083 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
 obj-$(CONFIG_DRM_ARCPGU)		+= arcpgu.o
+obj-$(CONFIG_DRM_ATARI)			+= atari_drm.o
 obj-$(CONFIG_DRM_BOCHS)			+= bochs.o
 obj-$(CONFIG_DRM_CIRRUS_QEMU)		+= cirrus.o
 obj-$(CONFIG_DRM_GM12U320)		+= gm12u320.o
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +2008 -528

2,860 lines not on this page · raw message

Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH/RFC 3/3] drm: atari: Add a DRM driver for Atari graphics hardware

Hi,

that's an interesting driver. I left a few comments below.

Am 25.11.22 um 21:31 schrieb Geert Uytterhoeven:

Quoted 252 lines

Supported formats:
- C[1248],
- RG16 (both standard DRM (little-endian) and native (big-endian)),
- XR24.

RG16 and XR24 are only supported with the underlying RGB565 hardware mode on Falcon, and are subject to hardware restrictions (limited to e.g. "qvga" and "hvga" modes).

All formats use a shadow buffer (TODO: BE RG16 buffers from ST-RAM). Initial mode setting works, later mode changes sometimes fail.

Developed and tested on ARAnyM.

Probably this should not be under /tiny ;-)

root@atari:~# modetest -M atari_drm
Encoders:
id	crtc	type	possible crtcs	possible clones
35	34	none	0x00000001	0x00000001

Connectors:
id encoder status name size (mm) modes encoders
31 35 connected VGA-1 0x0 9 35
modes:
index name refresh (Hz) hdisp hss hse htot vdisp vss vse vtot
#0 vga70 70.72 640 658 758 800 400 411 414 445 25176 flags: nhsync, pvsync, pcsync; type: preferred, driver #1 tt-mid 60.33 640 740 880 1000 480 496 526 534 32216 flags: nhsync, nvsync, ncsync; type: driver #2 vga 59.94 640 658 758 800 480 491 494 525 25176 flags: nhsync, nvsync, ncsync; type: driver #3 st-high 78.51 640 640 768 896 400 414 418 458 32216 flags: nhsync, nvsync, ncsync; type: driver #4 tt-low 88.72 320 420 560 680 480 496 526 534 32216 flags: nhsync, nvsync, ncsync; type: driver #5 hvga 59.94 320 329 379 400 480 491 494 525 12588 flags: nhsync, nvsync, ncsync; type: driver #6 st-mid 165.03 640 656 752 784 200 214 218 249 32216 flags: nhsync, nvsync, ncsync; type: driver #7 qvga 60.06 320 329 379 400 240 245 247 262 12588 flags: nhsync, nvsync, dblscan, ncsync; type: driver #8 st-low 278.84 320 336 432 464 200 214 218 249 32216 flags: nhsync, nvsync, ncsync; type: driver props:

	1 EDID:
		flags: immutable blob
		blobs:

		value:
	2 DPMS:
		flags: enum
		enums: On=0 Standby=1 Suspend=2 Off=3
		value: 0
	5 link-status:
		flags: enum
		enums: Good=0 Bad=1
		value: 0
	6 non-desktop:
		flags: immutable range
		values: 0 1
		value: 0
	4 TILE:
		flags: immutable blob
		blobs:

		value:

CRTCs:
id fb pos size
34 36 (0,0) (320x240)
#0 qvga 60.06 320 329 379 400 240 245 247 262 12588 flags: nhsync, nvsync, dblscan, ncsync; type: driver props:

	24 VRR_ENABLED:
		flags: range
		values: 0 1
		value: 0
	28 GAMMA_LUT:
		flags: blob
		blobs:

		value:
			000000000000000000000000aaaa0000
			0000aaaa000000000000aaaaaaaa0000
			aaaa000000000000aaaa0000aaaa0000
			aaaa555500000000aaaaaaaaaaaa0000
			555555555555000055555555ffff0000
			5555ffff555500005555ffffffff0000
			ffff555555550000ffff5555ffff0000
			ffffffff55550000ffffffffffff0000
			10001000100000001100110011000000
			12001200120000001300130013000000
			14001400140000001500150015000000
			16001600160000001700170017000000
			18001800180000001900190019000000
			1a001a001a0000001b001b001b000000
			1c001c001c0000001d001d001d000000
			1e001e001e0000001f001f001f000000
			20002000200000002100210021000000
			22002200220000002300230023000000
			24002400240000002500250025000000
			26002600260000002700270027000000
			28002800280000002900290029000000
			2a002a002a0000002b002b002b000000
			2c002c002c0000002d002d002d000000
			2e002e002e0000002f002f002f000000
			30003000300000003100310031000000
			32003200320000003300330033000000
			34003400340000003500350035000000
			36003600360000003700370037000000
			38003800380000003900390039000000
			3a003a003a0000003b003b003b000000
			3c003c003c0000003d003d003d000000
			3e003e003e0000003f003f003f000000
			40004000400000004100410041000000
			42004200420000004300430043000000
			44004400440000004500450045000000
			46004600460000004700470047000000
			48004800480000004900490049000000
			4a004a004a0000004b004b004b000000
			4c004c004c0000004d004d004d000000
			4e004e004e0000004f004f004f000000
			50005000500000005100510051000000
			52005200520000005300530053000000
			54005400540000005500550055000000
			56005600560000005700570057000000
			58005800580000005900590059000000
			5a005a005a0000005b005b005b000000
			5c005c005c0000005d005d005d000000
			5e005e005e0000005f005f005f000000
			60006000600000006100610061000000
			62006200620000006300630063000000
			64006400640000006500650065000000
			66006600660000006700670067000000
			68006800680000006900690069000000
			6a006a006a0000006b006b006b000000
			6c006c006c0000006d006d006d000000
			6e006e006e0000006f006f006f000000
			70007000700000007100710071000000
			72007200720000007300730073000000
			74007400740000007500750075000000
			76007600760000007700770077000000
			78007800780000007900790079000000
			7a007a007a0000007b007b007b000000
			7c007c007c0000007d007d007d000000
			7e007e007e0000007f007f007f000000
			80008000800000008100810081000000
			82008200820000008300830083000000
			84008400840000008500850085000000
			86008600860000008700870087000000
			88008800880000008900890089000000
			8a008a008a0000008b008b008b000000
			8c008c008c0000008d008d008d000000
			8e008e008e0000008f008f008f000000
			90009000900000009100910091000000
			92009200920000009300930093000000
			94009400940000009500950095000000
			96009600960000009700970097000000
			98009800980000009900990099000000
			9a009a009a0000009b009b009b000000
			9c009c009c0000009d009d009d000000
			9e009e009e0000009f009f009f000000
			a000a000a0000000a100a100a1000000
			a200a200a2000000a300a300a3000000
			a400a400a4000000a500a500a5000000
			a600a600a6000000a700a700a7000000
			a800a800a8000000a900a900a9000000
			aa00aa00aa000000ab00ab00ab000000
			ac00ac00ac000000ad00ad00ad000000
			ae00ae00ae000000af00af00af000000
			b000b000b0000000b100b100b1000000
			b200b200b2000000b300b300b3000000
			b400b400b4000000b500b500b5000000
			b600b600b6000000b700b700b7000000
			b800b800b8000000b900b900b9000000
			ba00ba00ba000000bb00bb00bb000000
			bc00bc00bc000000bd00bd00bd000000
			be00be00be000000bf00bf00bf000000
			c000c000c0000000c100c100c1000000
			c200c200c2000000c300c300c3000000
			c400c400c4000000c500c500c5000000
			c600c600c6000000c700c700c7000000
			c800c800c8000000c900c900c9000000
			ca00ca00ca000000cb00cb00cb000000
			cc00cc00cc000000cd00cd00cd000000
			ce00ce00ce000000cf00cf00cf000000
			d000d000d0000000d100d100d1000000
			d200d200d2000000d300d300d3000000
			d400d400d4000000d500d500d5000000
			d600d600d6000000d700d700d7000000
			d800d800d8000000d900d900d9000000
			da00da00da000000db00db00db000000
			dc00dc00dc000000dd00dd00dd000000
			de00de00de000000df00df00df000000
			e000e000e0000000e100e100e1000000
			e200e200e2000000e300e300e3000000
			e400e400e4000000e500e500e5000000
			e600e600e6000000e700e700e7000000
			e800e800e8000000e900e900e9000000
			ea00ea00ea000000eb00eb00eb000000
			ec00ec00ec000000ed00ed00ed000000
			ee00ee00ee000000ef00ef00ef000000
			f000f000f0000000f100f100f1000000
			f200f200f2000000f300f300f3000000
			f400f400f4000000f500f500f5000000
			f600f600f6000000f700f700f7000000
			f800f800f8000000f900f900f9000000
			fa00fa00fa000000fb00fb00fb000000
			fc00fc00fc000000fd00fd00fd000000
			fe00fe00fe000000ff00ff00ff000000
	29 GAMMA_LUT_SIZE:
		flags: immutable range
		values: 0 4294967295
		value: 256

Planes:
id crtc fb CRTC x,y x,y gamma size possible crtcs
32 34 36 0,0 0,0 0 0x00000001
formats: C1 C2 C4 C8 RG16 RG16be XR24
props:
8 type:
flags: immutable enum
enums: Overlay=0 Primary=1 Cursor=2
value: 1
30 IN_FORMATS:
flags: immutable blob blobs:

value:
00000001000000000000000700000018 00000001000000382020314320203243 202034432020384336314752b6314752 3432525800000000000000000000007f 00000000000000000000000000000000
in_formats blob decoded:
C1 : LINEAR
C2 : LINEAR
C4 : LINEAR
C8 : LINEAR
RG16: LINEAR
RG16be: LINEAR
XR24: LINEAR

Frame buffers:
id size pitch

root@atari:~#

---
  drivers/gpu/drm/tiny/Kconfig                  |    8 +
  drivers/gpu/drm/tiny/Makefile                 |    1 +
  .../atafb.c => gpu/drm/tiny/atari_drm.c}      | 2536 +++++++++++++----
  3 files changed, 2017 insertions(+), 528 deletions(-)

copy drivers/{video/fbdev/atafb.c => gpu/drm/tiny/atari_drm.c} (57%)

drivers/gpu/drm/tiny/Kconfig +0 -0
index f6889f649bc18217..177ccf40f05a2b99 100644

drivers/gpu/drm/tiny/Kconfig config DRM_ARCPGU · line 17

Quoted 8 lines
drivers/gpu/drm/tiny/Kconfig +5 -0
@@ -10,6 +10,14 @@ config DRM_ARCPGU
 
  	  If M is selected the module will be called arcpgu.
 
+config DRM_ATARI
+	tristate "DRM support for Atari native chipset"
+	depends on DRM && ATARI
+	select DRM_KMS_HELPER
+	select DRM_GEM_SHMEM_HELPER

Alphabetical sorting of the select statements.

Quoted 122 lines
drivers/gpu/drm/tiny/Kconfig +3 -0
+	help
+	 This is a KMS driver for the builtin graphics chipset found in Ataris.
+
  config DRM_BOCHS
  	tristate "DRM Support for bochs dispi vga interface (qemu stdvga)"
  	depends on DRM && PCI && MMU
drivers/gpu/drm/tiny/Makefile +1 -0
index 76dde89a044b7ddd..1f54bdfee1623083 100644
@@ -1,6 +1,7 @@
  # SPDX-License-Identifier: GPL-2.0-only
 
  obj-$(CONFIG_DRM_ARCPGU)		+= arcpgu.o
+obj-$(CONFIG_DRM_ATARI)			+= atari_drm.o
  obj-$(CONFIG_DRM_BOCHS)			+= bochs.o
  obj-$(CONFIG_DRM_CIRRUS_QEMU)		+= cirrus.o
  obj-$(CONFIG_DRM_GM12U320)		+= gm12u320.o
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +27 -56
similarity index 57%
copy from drivers/video/fbdev/atafb.c
copy to drivers/gpu/drm/tiny/atari_drm.c
index 2bc4089865e60ac2..d26e0fddd3bea1be 100644
@@ -1,81 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0
  /*
- * linux/drivers/video/atafb.c -- Atari builtin chipset frame buffer device
- *
- *  Copyright (C) 1994 Martin Schaller & Roman Hodek
- *
- * This file is subject to the terms and conditions of the GNU General Public
- * License.  See the file COPYING in the main directory of this archive
- * for more details.
- *
- * History:
- *   - 03 Jan 95: Original version by Martin Schaller: The TT driver and
- *                all the device independent stuff
- *   - 09 Jan 95: Roman: I've added the hardware abstraction (hw_switch)
- *                and wrote the Falcon, ST(E), and External drivers
- *                based on the original TT driver.
- *   - 07 May 95: Martin: Added colormap operations for the external driver
- *   - 21 May 95: Martin: Added support for overscan
- *		  Andreas: some bug fixes for this
- *   -    Jul 95: Guenther Kelleter <[email protected]>:
- *                Programmable Falcon video modes
- *                (thanks to Christian Cartus for documentation
- *                of VIDEL registers).
- *   - 27 Dec 95: Guenther: Implemented user definable video modes "user[0-7]"
- *                on minor 24...31. "user0" may be set on commandline by
- *                "R<x>;<y>;<depth>". (Makes sense only on Falcon)
- *                Video mode switch on Falcon now done at next VBL interrupt
- *                to avoid the annoying right shift of the screen.
- *   - 23 Sep 97: Juergen: added xres_virtual for cards like ProMST
- *                The external-part is legacy, therefore hardware-specific
- *                functions like panning/hardwarescrolling/blanking isn't
- *				  supported.
- *   - 29 Sep 97: Juergen: added Romans suggestion for pan_display
- *				  (var->xoffset was changed even if no set_screen_base avail.)
- *	 - 05 Oct 97: Juergen: extfb (PACKED_PIXEL) is FB_PSEUDOCOLOR 'cause
- *				  we know how to set the colors
- *				  ext_*palette: read from ext_colors (former MV300_colors)
- *							    write to ext_colors and RAMDAC
- *
- * To do:
- *   - For the Falcon it is not possible to set random video modes on
- *     SM124 and SC/TV, only the bootup resolution is supported.
+ * Copyright 2020-2022 Glider bv
   *
+ * Based on drivers/video/atafb.c
+ * Copyright (C) 1994 Martin Schaller & Roman Hodek
   */
 
-#define ATAFB_TT
-#define ATAFB_STE
-#define ATAFB_EXT
-#define ATAFB_FALCON
-
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/string.h>
-#include <linux/mm.h>
+#include <linux/console.h>
  #include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/fb.h>
  #include <linux/init.h>
  #include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/module.h>
  #include <linux/platform_device.h>
-
-#include <asm/setup.h>
+#include <linux/string.h>
  #include <linux/uaccess.h>
-#include <asm/irq.h>
-#include <asm/io.h>
 
  #include <asm/atarihw.h>
  #include <asm/atariints.h>
-#include <asm/atari_stram.h>
-
-#include <linux/fb.h>
  #include <asm/atarikb.h>
+#include <asm/atari_stram.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/setup.h>
+#include <asm/unaligned.h>
+
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_atomic_state_helper.h>
+#include <drm/drm_connector.h>
+#include <drm/drm_damage_helper.h>
+#include <drm/drm_drv.h>
+#include <drm/drm_fb_helper.h>
+#include <drm/drm_fbdev_generic.h>
+#include <drm/drm_file.h>
+#include <drm/drm_format_helper.h>
+#include <drm/drm_fourcc.h>

drivers/gpu/drm/tiny/atari_drm.c line 50

Quoted 10 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +10 -0
+#include <drm/drm_framebuffer.h>
+#include <drm/drm_gem_atomic_helper.h>
+#include <drm/drm_gem_framebuffer_helper.h>
+#include <drm/drm_gem_shmem_helper.h>
+#include <drm/drm_ioctl.h>
+#include <drm/drm_managed.h>
+#include <drm/drm_modeset_helper_vtables.h>
+#include <drm/drm_modes.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_simple_kms_helper.h>

I'd prefer to not add new simple-KMS drivers to DRM. I found that these helpers add little value and require additional code in other places of DRM. But using regular atomic helpers is not a requirement.

drivers/gpu/drm/tiny/atari_drm.c line 54

Quoted 4 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +4 -0
+#include <drm/drm_vblank.h>
+
+#include "../../../video/fbdev/c2p.h"
+#include "../../../video/fbdev/c2p_core.h"

These include statements are probably not a good idea. I suggest to move the headers and code into drivers/video and share it among the various drivers.

AFAIU the code is about format conversion. So in the long term, we may want to have DRM format conversion helpers for this.

Quoted 538 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +161 -151
-#include "c2p.h"
-#include "atafb.h"
+#define ATAFB_TT
+#define ATAFB_STE
+#define ATAFB_EXT
+#define ATAFB_FALCON
 
  #define SWITCH_ACIA 0x01		/* modes for switch on OverScan */
  #define SWITCH_SND6 0x40
  #define SWITCH_SND7 0x80
  #define SWITCH_NONE 0x00
 
+#define DRIVER_NAME "atari_drm"
+
+// FIXME Without rounding						With rounding
+// FIXME 12588 kHz => 79440 ps						12588 kHz => 79441 ps
+// FIXME falcon_encode_var changed pixclock from 79440 to 79442		... from 79441 to 79442
+// FIXME 79442 ps => 12587 kHz						79442 ps => 12588 kHz
+// FIXME 12587 kHz => 79447 ps => FAIL
+#undef PICOS2KHZ
+#undef KHZ2PICOS
+#define PICOS2KHZ(a) DIV_ROUND_CLOSEST(1000000000UL, (a))
+#define KHZ2PICOS(a) DIV_ROUND_CLOSEST(1000000000UL, (a))
 
  static int default_par;		/* default resolution (0=none) */
 
@@ -123,7 +121,6 @@ static struct atafb_par {
  			short mono;
  			short ste_mode;
  			short bpp;
-			u32 pseudo_palette[16];
  		} falcon;
  #endif
  		/* Nothing needed for external mode */
@@ -236,64 +233,24 @@ static int *MV300_reg = MV300_reg_8bit;
  #endif /* ATAFB_EXT */
 
 
-/*
- * struct fb_ops {
- *	* open/release and usage marking
- *	struct module *owner;
- *	int (*fb_open)(struct fb_info *info, int user);
- *	int (*fb_release)(struct fb_info *info, int user);
- *
- *	* For framebuffers with strange non linear layouts or that do not
- *	* work with normal memory mapped access
- *	ssize_t (*fb_read)(struct file *file, char __user *buf, size_t count, loff_t *ppos);
- *	ssize_t (*fb_write)(struct file *file, const char __user *buf, size_t count, loff_t *ppos);
- *
- *	* checks var and eventually tweaks it to something supported,
- *	* DOES NOT MODIFY PAR *
- *	int (*fb_check_var)(struct fb_var_screeninfo *var, struct fb_info *info);
- *
- *	* set the video mode according to info->var *
- *	int (*fb_set_par)(struct fb_info *info);
- *
- *	* set color register *
- *	int (*fb_setcolreg)(unsigned int regno, unsigned int red, unsigned int green,
- *			    unsigned int blue, unsigned int transp, struct fb_info *info);
- *
- *	* set color registers in batch *
- *	int (*fb_setcmap)(struct fb_cmap *cmap, struct fb_info *info);
- *
- *	* blank display *
- *	int (*fb_blank)(int blank, struct fb_info *info);
- *
- *	* pan display *
- *	int (*fb_pan_display)(struct fb_var_screeninfo *var, struct fb_info *info);
- *
- *	*** The meat of the drawing engine ***
- *	* Draws a rectangle *
- *	void (*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect);
- *	* Copy data from area to another *
- *	void (*fb_copyarea) (struct fb_info *info, const struct fb_copyarea *region);
- *	* Draws a image to the display *
- *	void (*fb_imageblit) (struct fb_info *info, const struct fb_image *image);
- *
- *	* Draws cursor *
- *	int (*fb_cursor) (struct fb_info *info, struct fb_cursor *cursor);
- *
- *	* wait for blit idle, optional *
- *	int (*fb_sync)(struct fb_info *info);
- *
- *	* perform fb specific ioctl (optional) *
- *	int (*fb_ioctl)(struct fb_info *info, unsigned int cmd,
- *			unsigned long arg);
- *
- *	* Handle 32bit compat ioctl (optional) *
- *	int (*fb_compat_ioctl)(struct fb_info *info, unsigned int cmd,
- *			unsigned long arg);
- *
- *	* perform fb specific mmap *
- *	int (*fb_mmap)(struct fb_info *info, struct vm_area_struct *vma);
- * } ;
- */
+struct atari_drm_device {
+	struct drm_device dev;
+	struct drm_simple_display_pipe pipe;
+	struct drm_connector conn;
+	unsigned int bpp;
+	unsigned int pitch;
+	unsigned int defmode;
+	// FIXME global fields
+	unsigned int next_bpp;
+};
+
+// FIXME pass atari_drm to all functions that use atari_drm_from_dev()?
+#define atari_drm_from_dev(_dev)	\
+	container_of(_dev, struct atari_drm_device, dev)
+#define atari_drm_from_pipe(_pipe)	\
+	container_of(_pipe, struct atari_drm_device, pipe)
+#define atari_drm_from_conn(_conn)	\
+	container_of(_conn, struct atari_drm_device, conn)
 
 
  /* ++roman: This structure abstracts from the underlying hardware (ST(e),
@@ -311,6 +268,9 @@ static int *MV300_reg = MV300_reg_8bit;
   *   values in the 'par' structure.
   * !!! Obsolete, perhaps !!!
   *
+ * int (*config_init)(struct atari_drm_device *atari_drm)
+ *   FIXME
+
   * int (*decode_var)(struct fb_var_screeninfo *var,
   *                   struct atafb_par *par)
   *   Get the video params out of 'var'. If a value doesn't fit, round
@@ -348,6 +308,7 @@ static struct fb_hwswitch {
  	int (*detect)(void);
  	int (*encode_fix)(struct fb_fix_screeninfo *fix,
  			  struct atafb_par *par);
+	int (*config_init)(struct atari_drm_device *atari_drm);
  	int (*decode_var)(struct fb_var_screeninfo *var,
  			  struct atafb_par *par);
  	int (*encode_var)(struct fb_var_screeninfo *var,
@@ -355,6 +316,8 @@ static struct fb_hwswitch {
  	void (*get_par)(struct atafb_par *par);
  	void (*set_par)(struct atafb_par *par);
  	void (*set_screen_base)(void *s_base);
+	void (*set_col_reg)(unsigned int regno, unsigned int red,
+			    unsigned int green, unsigned int blue);
  	int (*blank)(int blank_mode);
  	int (*pan_display)(struct fb_var_screeninfo *var,
  			   struct fb_info *info);
@@ -451,70 +414,35 @@ static struct fb_var_screeninfo atafb_predefined[] = {
 
  static int num_atafb_predefined = ARRAY_SIZE(atafb_predefined);
 
-static struct fb_videomode atafb_modedb[] __initdata = {
-	/*
-	 *  Atari Video Modes
-	 *
-	 *  If you change these, make sure to update DEFMODE_* as well!
-	 */
-
-	/*
-	 *  ST/TT Video Modes
-	 */
-
-	{
-		/* 320x200, 15 kHz, 60 Hz (ST low) */
-		"st-low", 60, 320, 200, 32000, 32, 16, 31, 14, 96, 4,
-		0, FB_VMODE_NONINTERLACED
-	}, {
-		/* 640x200, 15 kHz, 60 Hz (ST medium) */
-		"st-mid", 60, 640, 200, 32000, 32, 16, 31, 14, 96, 4,
-		0, FB_VMODE_NONINTERLACED
-	}, {
-		/* 640x400, 30.25 kHz, 63.5 Hz (ST high) */
-		"st-high", 63, 640, 400, 32000, 128, 0, 40, 14, 128, 4,
-		0, FB_VMODE_NONINTERLACED
-	}, {
-		/* 320x480, 15 kHz, 60 Hz (TT low) */
-		"tt-low", 60, 320, 480, 31041, 120, 100, 8, 16, 140, 30,
-		0, FB_VMODE_NONINTERLACED
-	}, {
-		/* 640x480, 29 kHz, 57 Hz (TT medium) */
-		"tt-mid", 60, 640, 480, 31041, 120, 100, 8, 16, 140, 30,
-		0, FB_VMODE_NONINTERLACED
-	}, {
-		/* 1280x960, 72 kHz, 72 Hz (TT high) */
-		"tt-high", 72, 1280, 960, 7760, 260, 60, 36, 4, 192, 4,
-		0, FB_VMODE_NONINTERLACED
-	},
-
-	/*
-	 *  VGA Video Modes
-	 */
-
-	{
-		/* 640x480, 31 kHz, 60 Hz (VGA) */
-		"vga", 60, 640, 480, 39721, 42, 18, 31, 11, 100, 3,
-		0, FB_VMODE_NONINTERLACED
-	}, {
-		/* 640x400, 31 kHz, 70 Hz (VGA) */
-		"vga70", 70, 640, 400, 39721, 42, 18, 31, 11, 100, 3,
-		FB_SYNC_VERT_HIGH_ACT | FB_SYNC_COMP_HIGH_ACT, FB_VMODE_NONINTERLACED
-	},
-
-	/*
-	 *  Falcon HiRes Video Modes
-	 */
-
-	{
-		/* 896x608, 31 kHz, 60 Hz (Falcon High) */
-		"falh", 60, 896, 608, 32000, 18, 42, 31, 1, 96,3,
-		0, FB_VMODE_NONINTERLACED
-	},
+// FIXME 32.215905 MHz NTSC
+// FIXME 32.084988 MHz PAL
+static const struct drm_display_mode atari_drm_modes[] = {
+	{ DRM_MODE("st-low", DRM_MODE_TYPE_DRIVER, 32216, 320, 336, 432, 464, 0, 200, 214, 218, 249, 0,
+		 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NCSYNC) },
+	{ DRM_MODE("st-mid", DRM_MODE_TYPE_DRIVER, 32216, 640, 656, 752, 784, 0, 200, 214, 218, 249, 0,
+		 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NCSYNC) },
+	{ DRM_MODE("st-high", DRM_MODE_TYPE_DRIVER, 32216, 640, 640, 768, 896, 0, 400, 414, 418, 458, 0,
+		 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NCSYNC) },
+	{ DRM_MODE("tt-low", DRM_MODE_TYPE_DRIVER, 32216, 320, 420, 560, 680, 0, 480, 496, 526, 534, 0,
+		 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NCSYNC) },
+	{ DRM_MODE("tt-mid", DRM_MODE_TYPE_DRIVER, 32216, 640, 740, 880, 1000, 0, 480, 496, 526, 534, 0,
+		 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NCSYNC) },
+	// Not using tt-high mode: VIRTUAL_X
+	{ DRM_MODE("tt-high", DRM_MODE_TYPE_DRIVER, 128864, 1280, 1340, 1532, 1792, 0, 960, 964, 968, 1004, 0,
+		 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NCSYNC) },
+	{ DRM_MODE("vga", DRM_MODE_TYPE_DRIVER, 25176, 640, 658, 758, 800, 0, 480, 491, 494, 525, 0,
+		 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NCSYNC) },
+	{ DRM_MODE("vga70", DRM_MODE_TYPE_DRIVER, 25176, 640, 658, 758, 800, 0, 400, 411, 414, 445, 0,
+		 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_PCSYNC) },
+        { DRM_MODE("qvga", DRM_MODE_TYPE_DRIVER, 12588, 320, 329, 379, 400, 0, 240, 245, 247, 262, 0,
+		 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_DBLSCAN | DRM_MODE_FLAG_NCSYNC) },
+	{ DRM_MODE("hvga", DRM_MODE_TYPE_DRIVER, 12588, 320, 329, 379, 400, 0, 480, 491, 494, 525, 0,
+		 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NCSYNC) },
+	// Not using falh mode: VIRTUAL_X
+	{ DRM_MODE("falh", DRM_MODE_TYPE_DRIVER, 31250, 896, 938, 1034, 1052, 0, 608, 609, 612, 643, 0,
+		 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NCSYNC) },
  };
 
-#define NUM_TOTAL_MODES  ARRAY_SIZE(atafb_modedb)
-
  static char *mode_option __initdata = NULL;
 
   /* default modes */
@@ -546,7 +474,6 @@ static int get_video_mode(char *vname)
  }
 
 
-
  /* ------------------- TT specific functions ---------------------- */
 
  #ifdef ATAFB_TT
@@ -576,6 +503,26 @@ static int tt_encode_fix(struct fb_fix_screeninfo *fix, struct atafb_par *par)
  	return 0;
  }
 
+static int tt_config_init(struct atari_drm_device *atari_drm)
+{
+	struct drm_device *dev = &atari_drm->dev;
+
+	if (mono_moni) {
+		dev->mode_config.min_width = 0;
+		dev->mode_config.min_height = 0;
+		dev->mode_config.max_width = sttt_xres * 2;
+		dev->mode_config.max_height = tt_yres * 2;
+		dev->mode_config.preferred_depth = 1;
+	} else {
+		dev->mode_config.min_width = 0;
+		dev->mode_config.min_height = 0;
+		dev->mode_config.max_width = sttt_xres;
+		dev->mode_config.max_height = tt_yres;
+		dev->mode_config.preferred_depth = 4;
+	}
+	return 0;
+}
+
  static int tt_decode_var(struct fb_var_screeninfo *var, struct atafb_par *par)
  {
  	int xres = var->xres;
@@ -766,20 +713,18 @@ static void tt_set_par(struct atafb_par *par)
  		fbhw->set_screen_base(par->screen_base);
  }
 
-static int tt_setcolreg(unsigned int regno, unsigned int red,
-			unsigned int green, unsigned int blue,
-			unsigned int transp, struct fb_info *info)
+static void tt_set_col_reg(unsigned int regno, unsigned int red,
+			   unsigned int green, unsigned int blue)
  {
  	if ((shifter_tt.tt_shiftmode & TT_SHIFTER_MODEMASK) == TT_SHIFTER_STHIGH)
  		regno += 254;
  	if (regno > 255)
-		return 1;
+		return;
  	tt_palette[regno] = (((red >> 12) << 8) | ((green >> 12) << 4) |
  			     (blue >> 12));
  	if ((shifter_tt.tt_shiftmode & TT_SHIFTER_MODEMASK) ==
  	    TT_SHIFTER_STHIGH && regno == 254)
  		tt_palette[0] = 0;
-	return 0;
  }
 
  static int tt_detect(void)
@@ -877,6 +822,18 @@ static int falcon_encode_fix(struct fb_fix_screeninfo *fix,
  	return 0;
  }
 
+static int falcon_config_init(struct atari_drm_device *atari_drm)
+{
+	struct drm_device *dev = &atari_drm->dev;
+
+	dev->mode_config.min_width = 320;
+	dev->mode_config.min_height = 200;
+	dev->mode_config.max_width = 640;	// FIXME 896;
+	dev->mode_config.max_height = 480;	// FIXME 608;
+	dev->mode_config.preferred_depth = 4;
+	return 0;
+}
+
  static int falcon_decode_var(struct fb_var_screeninfo *var,
  			     struct atafb_par *par)
  {
@@ -1253,6 +1210,9 @@ static int falcon_decode_var(struct fb_var_screeninfo *var,
  		goto again;
  	}
  	if (hfreq > fb_info.monspecs.hfmax || hfreq < fb_info.monspecs.hfmin)
+// FIXME atari_drm_pipe_mode_fixup: "hvga": 63 12588 320 341 391 400 480 496 498 503 0x40 0x10a
+// FIXME falcon_decode_var:1316: hfreq 20000 out-of-range
+// FIXME 320x480 virt 320x1945 off 0,0 bpp 4 gray 0 red 0/4/0 green 0/4/0 blue 0/4/0 transp 0/0/0 nonstd 0 act 0 0x0mm accel_flags 0x0 pixclock 79447 margins 9/21/5/16 sync 50/2/0 vmode 0 rotate 0 colorspace 0x0
  		return -EINVAL;
 
  	/* Vxx-registers */
@@ -1571,9 +1531,12 @@ static void falcon_set_par(struct atafb_par *par)
  	f_change_mode = 1;
  }
 
-static irqreturn_t falcon_vbl_switcher(int irq, void *dummy)
+static int f_vblank_enabled;	// FIXME
+
+static irqreturn_t falcon_vbl_switcher(int irq, void *dev)
  {
  	struct falcon_hw *hw = &f_new_mode;
+	struct drm_crtc *crtc = dev;
 
  	if (f_change_mode) {
  		f_change_mode = 0;
@@ -1626,6 +1589,14 @@ static irqreturn_t falcon_vbl_switcher(int irq, void *dummy)
  		videl.xoffset = current_par.hw.falcon.xoffset;
  		shifter_f030.off_next = current_par.hw.falcon.line_offset;
  	}
+
+	if (f_vblank_enabled)
+		drm_crtc_handle_vblank(crtc);
+	if (crtc->state && crtc->state->event) {
+		drm_crtc_send_vblank_event(crtc, crtc->state->event);
+		crtc->state->event = NULL;
+	}
+
  	return IRQ_HANDLED;
  }
 
@@ -1661,12 +1632,12 @@ static int falcon_pan_display(struct fb_var_screeninfo *var,
  	return 0;
  }
 
-static int falcon_setcolreg(unsigned int regno, unsigned int red,
-			    unsigned int green, unsigned int blue,
-			    unsigned int transp, struct fb_info *info)
+static void falcon_set_col_reg(unsigned int regno, unsigned int red,
+			       unsigned int green, unsigned int blue)
  {
  	if (regno > 255)
-		return 1;
+		return;
+
  	f030_col[regno] = (((red & 0xfc00) << 16) |
  			   ((green & 0xfc00) << 8) |
  			   ((blue & 0xfc00) >> 8));
@@ -1675,11 +1646,7 @@ static int falcon_setcolreg(unsigned int regno, unsigned int red,
  			((((red & 0xe000) >> 13)   | ((red & 0x1000) >> 12)) << 8)   |
  			((((green & 0xe000) >> 13) | ((green & 0x1000) >> 12)) << 4) |
  			   ((blue & 0xe000) >> 13) | ((blue & 0x1000) >> 12);
-		((u32 *)info->pseudo_palette)[regno] = ((red & 0xf800) |
-						       ((green & 0xfc00) >> 5) |
-						       ((blue & 0xf800) >> 11));
  	}
-	return 0;
  }
 
  static int falcon_blank(int blank_mode)
@@ -1795,6 +1762,18 @@ static int stste_encode_fix(struct fb_fix_screeninfo *fix,
  	return 0;
  }
 
+static int stste_config_init(struct atari_drm_device *atari_drm)
+{
+	struct drm_device *dev = &atari_drm->dev;
+
+	dev->mode_config.min_width = 0;
+	dev->mode_config.min_height = 0;
+	dev->mode_config.max_width = sttt_xres;
+	dev->mode_config.max_height = st_yres;
+	dev->mode_config.preferred_depth = mono_moni ? 1 : 4;
+	return 0;
+}
+
  static int stste_decode_var(struct fb_var_screeninfo *var,
  			    struct atafb_par *par)
  {
@@ -1949,12 +1928,11 @@ static void stste_set_par(struct atafb_par *par)
  		fbhw->set_screen_base(par->screen_base);
  }
 
-static int stste_setcolreg(unsigned int regno, unsigned int red,
-			   unsigned int green, unsigned int blue,
-			   unsigned int transp, struct fb_info *info)
+static void stste_set_col_reg(unsigned int regno, unsigned int red,
+			      unsigned int green, unsigned int blue)
  {
  	if (regno > 15)
-		return 1;
+		return;
  	red >>= 12;
  	blue >>= 12;
  	green >>= 12;
@@ -1968,7 +1946,6 @@ static int stste_setcolreg(unsigned int regno, unsigned int red,
  			((red & 0xe) << 7) |
  			((green & 0xe) << 3) |
  			((blue & 0xe) >> 1);
-	return 0;
  }
 
  static int stste_detect(void)
@@ -2112,6 +2089,19 @@ static int ext_encode_fix(struct fb_fix_screeninfo *fix, struct atafb_par *par)
  	return 0;
  }
 
+static int ext_config_init(struct atari_drm_device *atari_drm)
+{
+	struct fb_var_screeninfo *myvar = &atafb_predefined[0];
+	struct drm_device *dev = &atari_drm->dev;
+
+	dev->mode_config.min_width = 0;
+	dev->mode_config.min_height = 0;
+	dev->mode_config.max_width = myvar->xres;
+	dev->mode_config.max_height = myvar->yres;
+	dev->mode_config.preferred_depth = myvar->bits_per_pixel;
+	return 0;
+}
+
  static int ext_decode_var(struct fb_var_screeninfo *var, struct atafb_par *par)
  {
  	struct fb_var_screeninfo *myvar = &atafb_predefined[0];
@@ -2187,17 +2177,16 @@ static void ext_set_par(struct atafb_par *par)
  		tmp = INB(0x3da);			\
  	} while (0)
 
-static int ext_setcolreg(unsigned int regno, unsigned int red,
-			 unsigned int green, unsigned int blue,
-			 unsigned int transp, struct fb_info *info)
+static void ext_set_col_reg(unsigned int regno, unsigned int red,
+			    unsigned int green, unsigned int blue)
  {
  	unsigned char colmask = (1 << external_bitspercol) - 1;
 
  	if (!external_vgaiobase)
-		return 1;
+		return;
 
  	if (regno > 255)
-		return 1;
+		return;
 
  	red >>= 8;
  	green >>= 8;
@@ -2213,16 +2202,16 @@ static int ext_setcolreg(unsigned int regno, unsigned int red,
  		DACDelay;
  		OUTB(0x3c9, blue & colmask);
  		DACDelay;
-		return 0;
+		return;
 
  	case IS_MV300:
  		OUTB((MV300_reg[regno] << 2) + 1, red);
  		OUTB((MV300_reg[regno] << 2) + 1, green);
  		OUTB((MV300_reg[regno] << 2) + 1, blue);
-		return 0;
+		return;
 
  	default:
-		return 1;
+		return;
  	}
  }
 
@@ -2275,11 +2264,13 @@ static int pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  static struct fb_hwswitch tt_switch = {
  	.detect		= tt_detect,
  	.encode_fix	= tt_encode_fix,
+	.config_init	= tt_config_init,
  	.decode_var	= tt_decode_var,
  	.encode_var	= tt_encode_var,
  	.get_par	= tt_get_par,
  	.set_par	= tt_set_par,
  	.set_screen_base = set_screen_base,
+	.set_col_reg	= tt_set_col_reg,
  	.pan_display	= pan_display,
  };
  #endif
@@ -2288,11 +2279,13 @@ static struct fb_hwswitch tt_switch = {
  static struct fb_hwswitch falcon_switch = {
  	.detect		= falcon_detect,
  	.encode_fix	= falcon_encode_fix,
+	.config_init	= falcon_config_init,
  	.decode_var	= falcon_decode_var,
  	.encode_var	= falcon_encode_var,
  	.get_par	= falcon_get_par,
  	.set_par	= falcon_set_par,
  	.set_screen_base = set_screen_base,
+	.set_col_reg	= falcon_set_col_reg,
  	.blank		= falcon_blank,
  	.pan_display	= falcon_pan_display,
  };
@@ -2302,11 +2295,13 @@ static struct fb_hwswitch falcon_switch = {
  static struct fb_hwswitch st_switch = {
  	.detect		= stste_detect,
  	.encode_fix	= stste_encode_fix,
+	.config_init	= stste_config_init,
  	.decode_var	= stste_decode_var,
  	.encode_var	= stste_encode_var,
  	.get_par	= stste_get_par,
  	.set_par	= stste_set_par,
  	.set_screen_base = stste_set_screen_base,
+	.set_col_reg	= stste_set_col_reg,
  	.pan_display	= pan_display
  };
  #endif
@@ -2315,10 +2310,12 @@ static struct fb_hwswitch st_switch = {
  static struct fb_hwswitch ext_switch = {

drivers/gpu/drm/tiny/atari_drm.c static struct fb_hwswitch st_switch = { · line 2320

Quoted 10 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +2 -0
  	.detect		= ext_detect,
  	.encode_fix	= ext_encode_fix,
+	.config_init	= ext_config_init,
  	.decode_var	= ext_decode_var,
  	.encode_var	= ext_encode_var,
  	.get_par	= ext_get_par,
  	.set_par	= ext_set_par,
+	.set_col_reg	= ext_set_col_reg,
  };
  #endif

This design is problematic. It recreates fbdev interfaces within DRM and makes it very hard to convert the driver to good DRM code. I suggest to branch at the outer-most point for each supported model. So each model effectively receives it's own mode-config pipeline. Common code can still be shared.

For a good example, I'd refer to the latest mgag200 driver, which implements this pattern for the variety of revisions of its hardware.

Quoted 1,224 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +882 -283
@@ -2386,9 +2383,6 @@ static int atafb_get_var(struct fb_var_screeninfo *var, struct fb_info *info)
  	return 0;
  }
 
-// No longer called by fbcon!
-// Still called by set_var internally
-
  static void atafb_set_disp(struct fb_info *info)
  {
  	atafb_get_var(&info->var, info);
@@ -2408,189 +2402,6 @@ atafb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  	return fbhw->pan_display(var, info);
  }
 
-/*
- * generic drawing routines; imageblit needs updating for image depth > 1
- */
-
-static void atafb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
-{
-	struct atafb_par *par = info->par;
-	int x2, y2;
-	u32 width, height;
-
-	if (!rect->width || !rect->height)
-		return;
-
-#ifdef ATAFB_FALCON
-	if (info->var.bits_per_pixel == 16) {
-		cfb_fillrect(info, rect);
-		return;
-	}
-#endif
-
-	/*
-	 * We could use hardware clipping but on many cards you get around
-	 * hardware clipping by writing to framebuffer directly.
-	 * */
-	x2 = rect->dx + rect->width;
-	y2 = rect->dy + rect->height;
-	x2 = x2 < info->var.xres_virtual ? x2 : info->var.xres_virtual;
-	y2 = y2 < info->var.yres_virtual ? y2 : info->var.yres_virtual;
-	width = x2 - rect->dx;
-	height = y2 - rect->dy;
-
-	if (info->var.bits_per_pixel == 1)
-		atafb_mfb_fillrect(info, par->next_line, rect->color,
-				   rect->dy, rect->dx, height, width);
-	else if (info->var.bits_per_pixel == 2)
-		atafb_iplan2p2_fillrect(info, par->next_line, rect->color,
-					rect->dy, rect->dx, height, width);
-	else if (info->var.bits_per_pixel == 4)
-		atafb_iplan2p4_fillrect(info, par->next_line, rect->color,
-					rect->dy, rect->dx, height, width);
-	else
-		atafb_iplan2p8_fillrect(info, par->next_line, rect->color,
-					rect->dy, rect->dx, height, width);
-
-	return;
-}
-
-static void atafb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
-{
-	struct atafb_par *par = info->par;
-	int x2, y2;
-	u32 dx, dy, sx, sy, width, height;
-	int rev_copy = 0;
-
-#ifdef ATAFB_FALCON
-	if (info->var.bits_per_pixel == 16) {
-		cfb_copyarea(info, area);
-		return;
-	}
-#endif
-
-	/* clip the destination */
-	x2 = area->dx + area->width;
-	y2 = area->dy + area->height;
-	dx = area->dx > 0 ? area->dx : 0;
-	dy = area->dy > 0 ? area->dy : 0;
-	x2 = x2 < info->var.xres_virtual ? x2 : info->var.xres_virtual;
-	y2 = y2 < info->var.yres_virtual ? y2 : info->var.yres_virtual;
-	width = x2 - dx;
-	height = y2 - dy;
-
-	if (area->sx + dx < area->dx || area->sy + dy < area->dy)
-		return;
-
-	/* update sx,sy */
-	sx = area->sx + (dx - area->dx);
-	sy = area->sy + (dy - area->dy);
-
-	/* the source must be completely inside the virtual screen */
-	if (sx + width > info->var.xres_virtual ||
-			sy + height > info->var.yres_virtual)
-		return;
-
-	if (dy > sy || (dy == sy && dx > sx)) {
-		dy += height;
-		sy += height;
-		rev_copy = 1;
-	}
-
-	if (info->var.bits_per_pixel == 1)
-		atafb_mfb_copyarea(info, par->next_line, sy, sx, dy, dx, height, width);
-	else if (info->var.bits_per_pixel == 2)
-		atafb_iplan2p2_copyarea(info, par->next_line, sy, sx, dy, dx, height, width);
-	else if (info->var.bits_per_pixel == 4)
-		atafb_iplan2p4_copyarea(info, par->next_line, sy, sx, dy, dx, height, width);
-	else
-		atafb_iplan2p8_copyarea(info, par->next_line, sy, sx, dy, dx, height, width);
-
-	return;
-}
-
-static void atafb_imageblit(struct fb_info *info, const struct fb_image *image)
-{
-	struct atafb_par *par = info->par;
-	int x2, y2;
-	const char *src;
-	u32 dx, dy, width, height, pitch;
-
-#ifdef ATAFB_FALCON
-	if (info->var.bits_per_pixel == 16) {
-		cfb_imageblit(info, image);
-		return;
-	}
-#endif
-
-	/*
-	 * We could use hardware clipping but on many cards you get around
-	 * hardware clipping by writing to framebuffer directly like we are
-	 * doing here.
-	 */
-	x2 = image->dx + image->width;
-	y2 = image->dy + image->height;
-	dx = image->dx;
-	dy = image->dy;
-	x2 = x2 < info->var.xres_virtual ? x2 : info->var.xres_virtual;
-	y2 = y2 < info->var.yres_virtual ? y2 : info->var.yres_virtual;
-	width = x2 - dx;
-	height = y2 - dy;
-
-	if (image->depth == 1) {
-		// used for font data
-		src = image->data;
-		pitch = (image->width + 7) / 8;
-		while (height--) {
-
-			if (info->var.bits_per_pixel == 1)
-				atafb_mfb_linefill(info, par->next_line,
-						   dy, dx, width, src,
-						   image->bg_color, image->fg_color);
-			else if (info->var.bits_per_pixel == 2)
-				atafb_iplan2p2_linefill(info, par->next_line,
-							dy, dx, width, src,
-							image->bg_color, image->fg_color);
-			else if (info->var.bits_per_pixel == 4)
-				atafb_iplan2p4_linefill(info, par->next_line,
-							dy, dx, width, src,
-							image->bg_color, image->fg_color);
-			else
-				atafb_iplan2p8_linefill(info, par->next_line,
-							dy, dx, width, src,
-							image->bg_color, image->fg_color);
-			dy++;
-			src += pitch;
-		}
-	} else {
-		c2p_iplan2(info->screen_base, image->data, dx, dy, width,
-			   height, par->next_line, image->width,
-			   info->var.bits_per_pixel);
-	}
-}
-
-static int
-atafb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
-{
-	switch (cmd) {
-#ifdef FBCMD_GET_CURRENTPAR
-	case FBCMD_GET_CURRENTPAR:
-		if (copy_to_user((void *)arg, &current_par,
-				 sizeof(struct atafb_par)))
-			return -EFAULT;
-		return 0;
-#endif
-#ifdef FBCMD_SET_CURRENTPAR
-	case FBCMD_SET_CURRENTPAR:
-		if (copy_from_user(&current_par, (void *)arg,
-				   sizeof(struct atafb_par)))
-			return -EFAULT;
-		ata_set_par(&current_par);
-		return 0;
-#endif
-	}
-	return -EINVAL;
-}
 
  /* (un)blank/poweroff
   * 0 = unblank
@@ -2601,27 +2412,20 @@ atafb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
   */
  static int atafb_blank(int blank, struct fb_info *info)
  {
-	unsigned short black[16];
-	struct fb_cmap cmap;
+	unsigned int i;
+
  	if (fbhw->blank && !fbhw->blank(blank))
  		return 1;
+
  	if (blank) {
-		memset(black, 0, 16 * sizeof(unsigned short));
-		cmap.red = black;
-		cmap.green = black;
-		cmap.blue = black;
-		cmap.transp = NULL;
-		cmap.start = 0;
-		cmap.len = 16;
-		fb_set_cmap(&cmap, info);
+		// FIXME What if bpp > 4?
+		for (i = 0; i < 16; i++)
+			fbhw->set_col_reg(i, 0, 0, 0);
  	}
-#if 0
-	else
-		do_install_cmap(info);
-#endif
  	return 0;
  }
 
+
  	/*
  	 * New fbcon interface ...
  	 */
@@ -2669,10 +2473,6 @@ static struct fb_ops atafb_ops = {
  	.fb_set_par	= atafb_set_par,
  	.fb_blank =	atafb_blank,
  	.fb_pan_display	= atafb_pan_display,
-	.fb_fillrect	= atafb_fillrect,
-	.fb_copyarea	= atafb_copyarea,
-	.fb_imageblit	= atafb_imageblit,
-	.fb_ioctl =	atafb_ioctl,
  };
 
  static void check_default_par(int detected_mode)
@@ -2716,7 +2516,7 @@ static void check_default_par(int detected_mode)
  }
 
  #ifdef ATAFB_EXT
-static void __init atafb_setup_ext(char *spec)
+static void atafb_setup_ext(char *spec)
  {
  	int xres, xres_virtual, yres, depth, planes;
  	unsigned long addr, len;
@@ -2948,9 +2748,7 @@ static int __init atafb_setup(char *options)
  		if ((temp = get_video_mode(this_opt))) {
  			default_par = temp;
  			mode_option = this_opt;
-		} else if (!strcmp(this_opt, "inverse"))
-			fb_invert_cmaps();
-		else if (!strncmp(this_opt, "hwscroll_", 9)) {
+		} else if (!strncmp(this_opt, "hwscroll_", 9)) {
  			hwscroll = simple_strtoul(this_opt + 9, NULL, 10);
  			if (hwscroll < 0)
  				hwscroll = 0;
@@ -2983,86 +2781,1728 @@ static int __init atafb_setup(char *options)
  	return 0;
  }
 
-static int __init atafb_probe(struct platform_device *pdev)
+
+/* ------------------------------------------------------------------ */
+/*
+ * The meat of this driver. The core passes us a mode and we have to program
+ * it. The modesetting here is the bare minimum required to satisfy the qemu
+ * emulation of this hardware, and running this against a real device is
+ * likely to result in an inadequately programmed mode. We've already had
+ * the opportunity to modify the mode, so whatever we receive here should
+ * be something that can be correctly programmed and displayed
+ */
+
+static void atari_drm_set_start_address(struct atari_drm_device *atari_drm,
+					u32 offset)
  {
-	int pad, detected_mode, error;
-	unsigned int defmode = 0;
-	unsigned long mem_req;
-	char *option = NULL;
+	int idx;
 
-	if (fb_get_options("atafb", &option))
-		return -ENODEV;
-	atafb_setup(option);
-	dev_dbg(&pdev->dev, "%s: start\n", __func__);
+	if (!drm_dev_enter(&atari_drm->dev, &idx))
+		return;
 
-	do {
-#ifdef ATAFB_EXT
-		if (external_addr) {
-			dev_dbg(&pdev->dev, "initializing external hw\n");
-			fbhw = &ext_switch;
-			atafb_ops.fb_setcolreg = &ext_setcolreg;
-			defmode = DEFMODE_EXT;
-			break;
-		}
-#endif
-#ifdef ATAFB_TT
-		if (ATARIHW_PRESENT(TT_SHIFTER)) {
-			dev_dbg(&pdev->dev, "initializing TT hw\n");
-			fbhw = &tt_switch;
-			atafb_ops.fb_setcolreg = &tt_setcolreg;
-			defmode = DEFMODE_TT;
-			break;
-		}
-#endif
-#ifdef ATAFB_FALCON
-		if (ATARIHW_PRESENT(VIDEL_SHIFTER)) {
-			dev_dbg(&pdev->dev, "initializing Falcon hw\n");
-			fbhw = &falcon_switch;
-			atafb_ops.fb_setcolreg = &falcon_setcolreg;
-			error = request_irq(IRQ_AUTO_4, falcon_vbl_switcher, 0,
-					    "framebuffer:modeswitch",
-					    falcon_vbl_switcher);
-			if (error)
-				return error;
-			defmode = DEFMODE_F30;
-			break;
-		}
-#endif
-#ifdef ATAFB_STE
-		if (ATARIHW_PRESENT(STND_SHIFTER) ||
-		    ATARIHW_PRESENT(EXTD_SHIFTER)) {
-			dev_dbg(&pdev->dev, "initializing ST/E hw\n");
-			fbhw = &st_switch;
-			atafb_ops.fb_setcolreg = &stste_setcolreg;
-			defmode = DEFMODE_STE;
-			break;
-		}
-		fbhw = &st_switch;
-		atafb_ops.fb_setcolreg = &stste_setcolreg;
-		dev_warn(&pdev->dev,
-			 "Cannot determine video hardware; defaulting to ST(e)\n");
-#else /* ATAFB_STE */
-		/* no default driver included */
-		/* Nobody will ever see this message :-) */
-		panic("Cannot initialize video hardware");
-#endif
-	} while (0);
+	if (fbhw->set_screen_base)
+		fbhw->set_screen_base(screen_base + offset);
 
-	/* Multisync monitor capabilities */
-	/* Atari-TOS defaults if no boot option present */
-	if (fb_info.monspecs.hfmin == 0) {
-		fb_info.monspecs.hfmin = 31000;
-		fb_info.monspecs.hfmax = 32000;
-		fb_info.monspecs.vfmin = 58;
-		fb_info.monspecs.vfmax = 62;
-	}
+	drm_dev_exit(idx);
+}
 
-	detected_mode = fbhw->detect();
-	check_default_par(detected_mode);
-#ifdef ATAFB_EXT
-	if (!external_addr) {
-#endif /* ATAFB_EXT */
-		mem_req = default_mem_req + ovsc_offset + ovsc_addlen;
+static int atari_drm_mode_set(struct atari_drm_device *atari_drm,
+			      struct drm_display_mode *mode,
+			      struct drm_framebuffer *fb)
+{
+	int idx;
+
+	if (!drm_dev_enter(&atari_drm->dev, &idx))
+		return -1;
+
+	switch (fb->format->format) {
+	case DRM_FORMAT_C1:
+	case DRM_FORMAT_C2:
+	case DRM_FORMAT_C4:
+		break;
+
+	case DRM_FORMAT_C8:
+		// FIXME TT & Falcon only
+		break;
+
+	case DRM_FORMAT_RGB565:
+	case DRM_FORMAT_RGB565 | DRM_FORMAT_BIG_ENDIAN:
+	case DRM_FORMAT_XRGB8888:
+		// FIXME Falcon only
+		break;
+
+		// FIXME
+		break;
+
+	default:
+		drm_dev_exit(idx);
+		return -1;
+	}
+
+	// FIXME switch mode
+	atari_drm->bpp = fb_info.var.bits_per_pixel;
+
+	/* Program the pitch */
+	atari_drm->pitch = current_par.next_line;
+
+	atari_drm_set_start_address(atari_drm, 0);
+
+	/* Unblank (needed on S3 resume, vgabios doesn't do it then) */
+	// FIXME
+
+	drm_dev_exit(idx);
+	return 0;
+}
+
+// FIXME plain copy
+static void atari_drm_fb_c1_to_iplan2p1(const void *vaddr,
+					const struct drm_framebuffer *fb,
+					const struct drm_rect *rect)
+{
+	struct atari_drm_device *atari_drm = atari_drm_from_dev(fb->dev);
+	unsigned int bytes, lines, x1;
+	void *dst = screen_base;
+
+	bytes = DIV_ROUND_UP(drm_rect_width(rect) + rect->x1 % 8, 8);
+	x1 = rect->x1 & -8;
+	lines = drm_rect_height(rect);
+
+	dst += rect->y1 * atari_drm->pitch + x1 / 8;
+	vaddr += rect->y1 * fb->pitches[0] + x1 / 8;
+
+	while (lines--) {
+		memcpy(dst, vaddr, bytes);
+		vaddr += fb->pitches[0];
+		dst += atari_drm->pitch;
+	}
+}
+
+static void atari_drm_fb_c2_to_iplan2p2_line(char *dst, const char *vaddr,
+					     unsigned int words)
+{
+	union {
+		u8 pixels[4];
+		u32 words[2];
+	} c2p;
+
+	while (words--) {
+		/*
+		 * Load 16 chunky 2-bit pixels
+		 */
+		memcpy(c2p.pixels, vaddr, sizeof(c2p.pixels));
+		vaddr += 4;
+
+		/*
+		 * Perform a full C2P step on 2 32-bit words
+		 */
+		transp2x(c2p.words, 1, 1);
+		transp2(c2p.words, 16, 1);
+		transp2(c2p.words, 8, 1);
+		transp2(c2p.words, 4, 1);
+		transp2(c2p.words, 2, 1);
+		transp2(c2p.words, 1, 1);
+
+		/*
+		 * Store planar data (2 planes per 32-bit word)
+		 * Second word only!
+		 */
+		memcpy(dst, &c2p.words[1], sizeof(c2p.words[1]));
+		dst += 4;
+	}
+}
+
+static void atari_drm_fb_c2_to_iplan2p2(const void *vaddr,
+					const struct drm_framebuffer *fb,
+					const struct drm_rect *rect)
+{
+	struct atari_drm_device *atari_drm = atari_drm_from_dev(fb->dev);
+	unsigned int words, lines, x1;
+	void *dst = screen_base;
+
+	words = DIV_ROUND_UP(drm_rect_width(rect) + rect->x1 % 16, 16);
+	x1 = rect->x1 & -16;
+	lines = drm_rect_height(rect);
+
+	dst += rect->y1 * atari_drm->pitch + x1 / 4;
+	vaddr += rect->y1 * fb->pitches[0] + x1 / 4;
+
+	while (lines--) {
+		atari_drm_fb_c2_to_iplan2p2_line(dst, vaddr, words);
+		vaddr += fb->pitches[0];
+		dst += atari_drm->pitch;
+	}
+}
+
+static void atari_drm_fb_c4_to_iplan2p4_line(char *dst, const char *vaddr,
+					     unsigned int words)
+{
+	union {
+		u8 pixels[8];
+		u32 words[2];
+	} c2p;
+
+	while (words--) {
+		/*
+		 * Load 16 chunky 4-bit pixels
+		 */
+		memcpy(c2p.pixels, vaddr, sizeof(c2p.pixels));
+		vaddr += 8;
+
+		/*
+		 * Perform a full C2P step on 2 32-bit words
+		 */
+		transp2(c2p.words, 8, 1);
+		transp2(c2p.words, 2, 1);
+		transp2x(c2p.words, 1, 1);
+		transp2(c2p.words, 16, 1);
+		transp2(c2p.words, 4, 1);
+		transp2(c2p.words, 1, 1);
+
+		/*
+		 * Store planar data (2 planes per 32-bit word)
+		 */
+		memcpy(dst, c2p.words, sizeof(c2p.words));
+		dst += 8;
+	}
+}
+
+static void atari_drm_fb_c4_to_iplan2p4(const void *vaddr,
+					const struct drm_framebuffer *fb,
+					const struct drm_rect *rect)
+{
+	struct atari_drm_device *atari_drm = atari_drm_from_dev(fb->dev);
+	unsigned int words, lines, x1;
+	void *dst = screen_base;
+
+	words = DIV_ROUND_UP(drm_rect_width(rect) + rect->x1 % 16, 16);
+	x1 = rect->x1 & -16;
+	lines = drm_rect_height(rect);
+
+	dst += rect->y1 * atari_drm->pitch + x1 / 2;
+	vaddr += rect->y1 * fb->pitches[0] + x1 / 2;
+
+	while (lines--) {
+		atari_drm_fb_c4_to_iplan2p4_line(dst, vaddr, words);
+		vaddr += fb->pitches[0];
+		dst += atari_drm->pitch;
+	}
+}
+
+static void atari_drm_fb_c8_to_iplan2p8_line(void *dst, const void *vaddr,
+					     unsigned int words)
+{
+	// FIXME Get rid of pixels and union
+	// FIXME Use get_unaligned_be32() and store directly in words
+	// FIXME Is it more efficient to work on 16-bit words?
+	// FIXME aranym/src/hostscreen.cpp:HostScreen::bitplaneToChunky()
+	// FIXME Check asm output!!!!
+	union {
+		u8 pixels[16];
+		u32 words[4];
+	} c2p;
+
+	while (words--) {
+		/*
+		 * Load 16 chunky 8-bit pixels
+		 */
+		memcpy(c2p.pixels, vaddr, sizeof(c2p.pixels));
+		vaddr += 16;
+
+		/*
+		 * Perform a full C2P step on 4 32-bit words
+		 */
+		transp4(c2p.words, 8, 2);
+		transp4(c2p.words, 1, 2);
+		transp4x(c2p.words, 16, 2);
+		transp4x(c2p.words, 2, 2);
+		transp4(c2p.words, 4, 1);
+
+		/*
+		 * Store permutated planar data (2 planes per 32-bit word)
+		 */
+		put_unaligned_be32(c2p.words[1], dst);
+		dst += 4;
+		put_unaligned_be32(c2p.words[3], dst);
+		dst += 4;
+		put_unaligned_be32(c2p.words[0], dst);
+		dst += 4;
+		put_unaligned_be32(c2p.words[2], dst);
+		dst += 4;
+	}
+}
+
+static void atari_drm_fb_c8_to_iplan2p8(const void *vaddr,
+					const struct drm_framebuffer *fb,
+					const struct drm_rect *rect)
+{
+	struct atari_drm_device *atari_drm = atari_drm_from_dev(fb->dev);
+	unsigned int words, lines, x1;
+	void *dst = screen_base;
+
+	words = DIV_ROUND_UP(drm_rect_width(rect) + rect->x1 % 16, 16);
+	x1 = rect->x1 & -16;
+	lines = drm_rect_height(rect);
+
+	dst += rect->y1 * atari_drm->pitch + x1;
+	vaddr += rect->y1 * fb->pitches[0] + x1;
+
+	while (lines--) {
+		atari_drm_fb_c8_to_iplan2p8_line(dst, vaddr, words);
+		vaddr += fb->pitches[0];
+		dst += atari_drm->pitch;
+	}
+}
+
+static void atari_drm_load_clut332(void)
+{
+	unsigned int i;
+
+	for (i = 0; i < 256; i++) {
+		u16 r = ((i >> 5) & 7) * 0x1fff;
+		u16 g = ((i >> 2) & 7) * 0x1fff;
+		u16 b = (i & 3) * 0x3fff;
+		fbhw->set_col_reg(i, r, g, b);
+	}
+}
+
+//#define EMULATE_LESSER_FORMATS
+
+#ifdef EMULATE_LESSER_FORMATS
+static void atari_drm_fb_c1_to_iplan2pX_line(char *dst, const char *vaddr,
+					     unsigned int words,
+					     unsigned int bpp)
+{
+	while (words--) {
+		put_unaligned_be16(get_unaligned_be16(vaddr), dst);
+		dst += 2;
+		vaddr += 2;
+
+		memset(dst, 0, (bpp - 1) * 2);
+		dst += (bpp - 1) * 2;
+	}
+}
+
+static void atari_drm_fb_c1_to_iplan2pX(const void *vaddr,
+					const struct drm_framebuffer *fb,
+					const struct drm_rect *rect)
+{
+	struct atari_drm_device *atari_drm = atari_drm_from_dev(fb->dev);
+	unsigned int words, lines, x1, bpp = atari_drm->bpp;
+	void *dst = screen_base;
+
+	words = DIV_ROUND_UP(drm_rect_width(rect) + rect->x1 % 16, 16);
+	x1 = rect->x1 & -16;
+	lines = drm_rect_height(rect);
+
+	dst += rect->y1 * atari_drm->pitch + x1 * bpp / 8;
+	vaddr += rect->y1 * fb->pitches[0] + x1 / 8;
+
+	while (lines--) {
+		atari_drm_fb_c1_to_iplan2pX_line(dst, vaddr, words, bpp);
+		vaddr += fb->pitches[0];
+		dst += atari_drm->pitch;
+	}
+}
+
+static void atari_drm_fb_c2_to_iplan2pX_line(char *dst, const char *vaddr,
+					     unsigned int words,
+					     unsigned int bpp)
+{
+	union {
+		u8 pixels[4];
+		u32 words[2];
+	} c2p;
+
+	while (words--) {
+		/*
+		 * Load 16 chunky 2-bit pixels
+		 */
+		memcpy(c2p.pixels, vaddr, sizeof(c2p.pixels));
+		vaddr += 4;
+
+		/*
+		 * Perform a full C2P step on 2 32-bit words
+		 */
+		transp2x(c2p.words, 1, 1);
+		transp2(c2p.words, 16, 1);
+		transp2(c2p.words, 8, 1);
+		transp2(c2p.words, 4, 1);
+		transp2(c2p.words, 2, 1);
+		transp2(c2p.words, 1, 1);
+
+		/*
+		 * Store planar data (2 planes per 32-bit word)
+		 * Second word only!
+		 */
+		memcpy(dst, &c2p.words[1], sizeof(c2p.words[1]));
+		dst += 4;
+		memset(dst, 0, (bpp - 2) * 2);
+		dst += (bpp - 2) * 2;
+	}
+}
+
+static void atari_drm_fb_c2_to_iplan2pX(const void *vaddr,
+					const struct drm_framebuffer *fb,
+					const struct drm_rect *rect)
+{
+	struct atari_drm_device *atari_drm = atari_drm_from_dev(fb->dev);
+	unsigned int words, lines, x1, bpp = atari_drm->bpp;
+	void *dst = screen_base;
+
+	words = DIV_ROUND_UP(drm_rect_width(rect) + rect->x1 % 16, 16);
+	x1 = rect->x1 & -16;
+	lines = drm_rect_height(rect);
+
+	dst += rect->y1 * atari_drm->pitch + x1 * bpp / 8;
+	vaddr += rect->y1 * fb->pitches[0] + x1 / 4;
+
+	while (lines--) {
+		atari_drm_fb_c2_to_iplan2pX_line(dst, vaddr, words, bpp);
+		vaddr += fb->pitches[0];
+		dst += atari_drm->pitch;
+	}
+}
+
+static void atari_drm_fb_c4_to_iplan2pX_line(char *dst, const char *vaddr,
+					     unsigned int words,
+					     unsigned int bpp)
+{
+	union {
+		u8 pixels[8];
+		u32 words[2];
+	} c2p;
+
+	while (words--) {
+		/*
+		 * Load 16 chunky 4-bit pixels
+		 */
+		memcpy(c2p.pixels, vaddr, sizeof(c2p.pixels));
+		vaddr += 8;
+
+		/*
+		 * Perform a full C2P step on 2 32-bit words
+		 */
+		transp2(c2p.words, 8, 1);
+		transp2(c2p.words, 2, 1);
+		transp2x(c2p.words, 1, 1);
+		transp2(c2p.words, 16, 1);
+		transp2(c2p.words, 4, 1);
+		transp2(c2p.words, 1, 1);
+
+		/*
+		 * Store planar data (2 planes per 32-bit word)
+		 */
+		memcpy(dst, c2p.words, sizeof(c2p.words));
+		dst += 8;
+		memset(dst, 0, (bpp - 4) * 2);
+		dst += (bpp - 4) * 2;
+	}
+}
+
+static void atari_drm_fb_c4_to_iplan2pX(const void *vaddr,
+					const struct drm_framebuffer *fb,
+					const struct drm_rect *rect)
+{
+	struct atari_drm_device *atari_drm = atari_drm_from_dev(fb->dev);
+	unsigned int words, lines, x1, bpp = atari_drm->bpp;
+	void *dst = screen_base;
+
+	words = DIV_ROUND_UP(drm_rect_width(rect) + rect->x1 % 16, 16);
+	x1 = rect->x1 & -16;
+	lines = drm_rect_height(rect);
+
+	dst += rect->y1 * atari_drm->pitch + x1 * bpp / 8;
+	vaddr += rect->y1 * fb->pitches[0] + x1 / 2;
+
+	while (lines--) {
+		atari_drm_fb_c4_to_iplan2pX_line(dst, vaddr, words, bpp);
+		vaddr += fb->pitches[0];
+		dst += atari_drm->pitch;
+	}
+}
+
+static void drm_fb_rgb565_to_rgb332_line(u8 *dbuf, const __le16 *sbuf,
+					 unsigned int pixels)
+{
+	unsigned int x;
+	u16 pix;
+
+	for (x = 0; x < pixels; x++) {
+		pix = le16_to_cpu(sbuf[x]);
+		dbuf[x] = ((pix & 0xe000) >> 8) |
+			  ((pix & 0x0700) >> 6) |
+			  ((pix & 0x001c) >> 3);
+	}
+}
+
+static void atari_drm_fb_rgb565_to_rgb332(const void *vaddr,
+					  const struct drm_framebuffer *fb,
+					  const struct drm_rect *rect)
+{
+	struct atari_drm_device *atari_drm = atari_drm_from_dev(fb->dev);
+	unsigned int words, pixels, lines, x1;
+	void *dst = screen_base;
+	void *buf;
+
+	// FIXME Just for testing
+	// FIXME RGB565 should only be used with RGB565 (Falcon or ARAnyM)
+	atari_drm_load_clut332();
+
+	words = DIV_ROUND_UP(drm_rect_width(rect) + rect->x1 % 16, 16);
+	x1 = rect->x1 & -16;
+	pixels = words * 16;
+	lines = drm_rect_height(rect);
+
+	buf = kmalloc(pixels, GFP_KERNEL);
+	if (!buf)
+		return;
+
+	dst += rect->y1 * atari_drm->pitch + x1;
+	vaddr += rect->y1 * fb->pitches[0] + x1 * fb->format->cpp[0];
+
+	while (lines--) {
+		drm_fb_rgb565_to_rgb332_line(buf, vaddr, pixels);
+		atari_drm_fb_c8_to_iplan2p8_line(dst, buf, words);
+		vaddr += fb->pitches[0];
+		dst += atari_drm->pitch;
+	}
+
+	kfree(buf);
+}
+
+static void drm_fb_rgb565be_to_rgb332_line(u8 *dbuf, const __be16 *sbuf,
+					   unsigned int pixels)
+{
+	unsigned int x;
+	u16 pix;
+
+	for (x = 0; x < pixels; x++) {
+		pix = be16_to_cpu(sbuf[x]);
+		dbuf[x] = ((pix & 0xe000) >> 8) |
+			  ((pix & 0x0700) >> 6) |
+			  ((pix & 0x001c) >> 3);
+	}
+}
+
+static void atari_drm_fb_rgb565be_to_rgb332(const void *vaddr,
+					    const struct drm_framebuffer *fb,
+					    const struct drm_rect *rect)
+{
+	struct atari_drm_device *atari_drm = atari_drm_from_dev(fb->dev);
+	unsigned int words, pixels, lines, x1;
+	void *dst = screen_base;
+	void *buf;
+
+	// FIXME Just for testing
+	// FIXME RGB565 should only be used with RGB565 (Falcon or ARAnyM)
+	atari_drm_load_clut332();
+
+	words = DIV_ROUND_UP(drm_rect_width(rect) + rect->x1 % 16, 16);
+	x1 = rect->x1 & -16;
+	pixels = words * 16;
+	lines = drm_rect_height(rect);
+
+	buf = kmalloc(pixels, GFP_KERNEL);
+	if (!buf)
+		return;
+
+	dst += rect->y1 * atari_drm->pitch + x1;
+	vaddr += rect->y1 * fb->pitches[0] + x1 * fb->format->cpp[0];
+
+	while (lines--) {
+		drm_fb_rgb565be_to_rgb332_line(buf, vaddr, pixels);
+		atari_drm_fb_c8_to_iplan2p8_line(dst, buf, words);
+		vaddr += fb->pitches[0];
+		dst += atari_drm->pitch;
+	}
+
+	kfree(buf);
+}
+#endif // EMULATE_LESSER_FORMATS
+
+// FIXME Export in drivers/gpu/drm/drm_format_helper.c?
+static void drm_fb_xrgb8888_to_rgb332_line(u8 *dbuf, const __le32 *sbuf,
+					   unsigned int pixels)
+{
+	unsigned int x;
+	u32 pix;
+
+	for (x = 0; x < pixels; x++) {
+		pix = le32_to_cpu(sbuf[x]);
+		dbuf[x] = ((pix & 0x00e00000) >> 16) |
+			  ((pix & 0x0000e000) >> 11) |
+			  ((pix & 0x000000c0) >> 6);
+	}
+}
+
+static void atari_drm_fb_xrgb8888_to_rgb332(const void *vaddr,
+					    const struct drm_framebuffer *fb,
+					    const struct drm_rect *rect)
+{
+	struct atari_drm_device *atari_drm = atari_drm_from_dev(fb->dev);
+	unsigned int words, pixels, lines, x1;
+	void *dst = screen_base;
+	void *buf;
+
+	// FIXME Just for testing
+	// FIXME XRGB8888 should only be used with RGB565 (Falcon or ARAnyM)
+	atari_drm_load_clut332();
+
+	words = DIV_ROUND_UP(drm_rect_width(rect) + rect->x1 % 16, 16);
+	x1 = rect->x1 & -16;
+	pixels = words * 16;
+	lines = drm_rect_height(rect);
+
+	buf = kmalloc(pixels, GFP_KERNEL);
+	if (!buf)
+		return;
+
+	dst += rect->y1 * atari_drm->pitch + x1;
+	vaddr += rect->y1 * fb->pitches[0] + x1 * fb->format->cpp[0];
+
+	while (lines--) {
+		drm_fb_xrgb8888_to_rgb332_line(buf, vaddr, pixels);
+		atari_drm_fb_c8_to_iplan2p8_line(dst, buf, words);
+		vaddr += fb->pitches[0];
+		dst += atari_drm->pitch;
+	}
+
+	kfree(buf);
+}
+
+static int atari_drm_fb_blit_rect(const struct drm_framebuffer *fb,
+				  const struct iosys_map *map,
+				  struct drm_rect *rect)
+{
+	struct atari_drm_device *atari_drm = atari_drm_from_dev(fb->dev);
+	void *vmap = map->vaddr; /* TODO: Use mapping abstraction properly */
+	struct iosys_map dst = IOSYS_MAP_INIT_VADDR(screen_base);
+	int idx;
+
+	if (!drm_dev_enter(&atari_drm->dev, &idx))
+		return -ENODEV;
+
+	// FIXME Do we need to support conversion from Cn to Cm?
+	// FIXME Only up (n < m)?
+	// FIXME Also down (n > m)?
+	// FIXME No, just for testing
+	switch (fb->format->format) {
+	case DRM_FORMAT_C1:
+#ifdef EMULATE_LESSER_FORMATS
+		if (atari_drm->bpp > 1 && atari_drm->bpp <= 8) {
+			// FIXME For testing only
+			atari_drm_fb_c1_to_iplan2pX(vmap, fb, rect);
+			break;
+		}
+#endif // EMULATE_LESSER_FORMATS
+
+		if (atari_drm->bpp != 1)
+			goto unsupported;
+
+		// FIXME like bpp=16 after aligning rect with pixel grid
+		atari_drm_fb_c1_to_iplan2p1(vmap, fb, rect);
+		break;
+
+	case DRM_FORMAT_C2:
+#ifdef EMULATE_LESSER_FORMATS
+		if (atari_drm->bpp > 2 && atari_drm->bpp <= 8) {
+			// FIXME For testing only
+			atari_drm_fb_c2_to_iplan2pX(vmap, fb, rect);
+			break;
+		}
+#endif // EMULATE_LESSER_FORMATS
+
+		if (atari_drm->bpp != 2)
+			goto unsupported;
+
+		atari_drm_fb_c2_to_iplan2p2(vmap, fb, rect);
+		break;
+
+	case DRM_FORMAT_C4:
+#ifdef EMULATE_LESSER_FORMATS
+		if (atari_drm->bpp > 4 && atari_drm->bpp <= 8) {
+			// FIXME For testing only
+			atari_drm_fb_c4_to_iplan2pX(vmap, fb, rect);
+			break;
+		}
+#endif // EMULATE_LESSER_FORMATS
+
+		if (atari_drm->bpp != 4)
+			goto unsupported;
+
+		atari_drm_fb_c4_to_iplan2p4(vmap, fb, rect);
+		break;
+
+	case DRM_FORMAT_C8:
+		if (atari_drm->bpp != 8)
+			goto unsupported;
+
+		atari_drm_fb_c8_to_iplan2p8(vmap, fb, rect);
+		break;
+
+	case DRM_FORMAT_RGB565:
+		switch (atari_drm->bpp) {
+#ifdef EMULATE_LESSER_FORMATS
+		case 8:
+			// FIXME For testing only
+			atari_drm_fb_rgb565_to_rgb332(vmap, fb, rect);
+			break;
+#endif // EMULATE_LESSER_FORMATS
+
+		case 16:
+			iosys_map_incr(&dst,
+				       drm_fb_clip_offset(atari_drm->pitch,
+							  fb->format, rect));
+			drm_fb_swab(&dst, &atari_drm->pitch, map, fb, rect,
+				    true);
+			break;
+
+		default:
+			goto unsupported;
+		}
+		break;
+
+	case DRM_FORMAT_RGB565 | DRM_FORMAT_BIG_ENDIAN:
+		switch (atari_drm->bpp) {
+#ifdef EMULATE_LESSER_FORMATS
+		case 8:
+			// FIXME For testing only
+			atari_drm_fb_rgb565be_to_rgb332(vmap, fb, rect);
+			break;
+#endif // EMULATE_LESSER_FORMATS
+
+		case 16:
+			iosys_map_incr(&dst,
+				       drm_fb_clip_offset(atari_drm->pitch,
+							  fb->format, rect));
+			drm_fb_memcpy(&dst, &atari_drm->pitch, map, fb, rect);
+			break;
+
+		default:
+			goto unsupported;
+		}
+		break;
+
+	case DRM_FORMAT_XRGB8888:
+		switch (atari_drm->bpp) {
+		case 8:
+			atari_drm_fb_xrgb8888_to_rgb332(vmap, fb, rect);
+			break;
+
+		case 16:
+			iosys_map_incr(&dst,
+				       drm_fb_clip_offset(atari_drm->pitch,
+							  fb->format, rect));
+			drm_fb_xrgb8888_to_rgb565(&dst, &atari_drm->pitch, map,
+						  fb, rect, false);
+			break;
+
+		default:
+			goto unsupported;
+		}
+		break;
+
+	default:
+		drm_WARN_ONCE(fb->dev, 1, "Format %p4cc not supported\n",
+			      fb->format);
+		goto unsupported;
+	}
+
+unsupported:
+	drm_dev_exit(idx);
+	return 0;
+}
+
+static int atari_drm_fb_blit_fullscreen(struct drm_framebuffer *fb,
+					const struct iosys_map *map)
+{
+	struct drm_rect fullscreen = {
+		.x1 = 0,
+		.x2 = fb->width,
+		.y1 = 0,
+		.y2 = fb->height,
+	};
+	return atari_drm_fb_blit_rect(fb, map, &fullscreen);
+}
+
+static int atari_drm_check_size(int width, int height,
+				struct drm_framebuffer *fb)
+{
+	int pitch = width;
+
+	if (fb)
+		pitch = fb->pitches[0];
+
+	if (fb && width > fb->dev->mode_config.max_width)
+		return -EINVAL;
+
+	if (pitch * height > screen_len)
+		{} //FIXME return -EINVAL;
+
+	return 0;
+}
+
+/* ------------------------------------------------------------------ */
+/* atari_drm connector						      */
+
+static int atari_drm_conn_get_modes(struct drm_connector *conn)
+{
+	struct atari_drm_device *atari_drm = atari_drm_from_conn(conn);
+	struct drm_device *dev = conn->dev;
+	struct drm_display_mode *mode;
+	unsigned int i = 0;
+
+	for (i = 0; i < ARRAY_SIZE(atari_drm_modes); i++) {
+		mode = drm_mode_duplicate(dev, &atari_drm_modes[i]);
+		if (!mode)
+			break;
+
+		if (i == atari_drm->defmode)
+			mode->type |= DRM_MODE_TYPE_PREFERRED;
+
+		drm_mode_probed_add(conn, mode);
+	}
+
+	return i;
+}
+
+/**
+ * atari_drm_conn_mode_valid
+ *
+ * Callback to validate a mode for a connector, irrespective of the
+ * specific display configuration.
+ *
+ * This callback is used by the probe helpers to filter the mode list
+ * (which is usually derived from the EDID data block from the sink).
+ * See e.g. drm_helper_probe_single_connector_modes().
+ *
+ * This function is optional.
+ *
+ * NOTE:
+ *
+ * This only filters the mode list supplied to userspace in the
+ * GETCONNECTOR IOCTL. Compared to &drm_encoder_helper_funcs.mode_valid,
+ * &drm_crtc_helper_funcs.mode_valid and &drm_bridge_funcs.mode_valid,
+ * which are also called by the atomic helpers from
+ * drm_atomic_helper_check_modeset(). This allows userspace to force and
+ * ignore sink constraint (like the pixel clock limits in the screen's
+ * EDID), which is useful for e.g. testing, or working around a broken
+ * EDID. Any source hardware constraint (which always need to be
+ * enforced) therefore should be checked in one of the above callbacks,
+ * and not this one here.
+ *
+ * To avoid races with concurrent connector state updates, the helper
+ * libraries always call this with the &drm_mode_config.connection_mutex
+ * held. Because of this it's safe to inspect &drm_connector->state.
+ *
+ * RETURNS:
+ *
+ * Either &drm_mode_status.MODE_OK or one of the failure reasons in &enum
+ * drm_mode_status.
+ */
+static enum drm_mode_status atari_drm_conn_mode_valid(
+	struct drm_connector *conn, struct drm_display_mode *mode)
+{
+	// FIXME
+	return MODE_OK;
+}
+
+static const struct drm_connector_helper_funcs atari_drm_conn_helper_funcs = {
+	.get_modes = atari_drm_conn_get_modes,
+	.mode_valid = atari_drm_conn_mode_valid,
+};
+
+static const struct drm_connector_funcs atari_drm_conn_funcs = {
+	.fill_modes = drm_helper_probe_single_connector_modes,
+	.destroy = drm_connector_cleanup,
+	.reset = drm_atomic_helper_connector_reset,
+	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
+	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
+};
+
+// FIXME create dynamically from atari_drm_modes[]?
+static const struct drm_named_mode atari_drm_named_modes[] =
+{
+	{ .name = "st-low" },
+	{ .name = "st-mid" },
+	{ .name = "st-high" },
+	{ .name = "tt-low" },
+	{ .name = "tt-mid" },
+	{ .name = "tt-high" },
+	{ .name = "vga" },
+	{ .name = "vga70" },
+	{ .name = "qvga" },
+	{ .name = "hvga" },
+	{ .name = "falh" },
+	{ /* sentinel */ }
+};
+
+static int atari_drm_conn_init(struct atari_drm_device *atari_drm)
+{
+	struct drm_connector *conn = &atari_drm->conn;
+	const struct drm_cmdline_mode *cmdline_mode;
+	int ret;
+
+	// FIXME Depends on monitor type. Handle in .config_init()?
+	conn->interlace_allowed = true;
+	conn->doublescan_allowed = true;
+	conn->named_modes = atari_drm_named_modes;
+
+	drm_connector_helper_add(conn, &atari_drm_conn_helper_funcs);
+	ret = drm_connector_init(&atari_drm->dev, conn, &atari_drm_conn_funcs,
+				 DRM_MODE_CONNECTOR_VGA);
+
+	cmdline_mode = &conn->cmdline_mode;
+	if (cmdline_mode->specified) {
+		pr_info("    name %s\n", cmdline_mode->name);
+		pr_info("    resolution %ux%u\n", cmdline_mode->xres,
+			cmdline_mode->yres);
+	}
+	if (cmdline_mode->bpp_specified)

drivers/gpu/drm/tiny/atari_drm.c static int __init atafb_setup(char *options) · line 3671

Quoted 10 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +10 -0
+		pr_info("    bpp %u\n", cmdline_mode->bpp);
+	if (cmdline_mode->refresh_specified)
+		pr_info("    refresh %u\n", cmdline_mode->refresh);
+
+	return ret;
+}
+
+// FIXME helpers from
+// "[PATCH v2 5/15] drm/fbconv: Add DRM <-> fbdev pixel-format conversion"
+// by Thomas Zimmermann <[email protected]>

All these FIXMEs will need to be resolved.

Quoted 682 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +682 -0
+// FIXME helpers from
+// "[PATCH v2 6/15] drm/fbconv: Add mode conversion DRM <-> fbdev"
+// by Thomas Zimmermann <[email protected]>
+/**
+ * drm_mode_update_from_fb_videomode - Sets a drm_display mode struecture
+ *	from an fb_videomode structure
+ * @mode:	the DRM display mode structure to update
+ * @fb_mode:	an fb_videomode structure
+ */
+static void drm_mode_update_from_fb_videomode(struct drm_display_mode *mode,
+				       const struct fb_videomode *fb_mode)
+{
+	mode->type = DRM_MODE_TYPE_DRIVER;
+
+	mode->clock = PICOS2KHZ(fb_mode->pixclock);
+
+	mode->hdisplay = fb_mode->xres;
+	mode->hsync_start = mode->hdisplay + fb_mode->right_margin;
+	mode->hsync_end = mode->hsync_start + fb_mode->hsync_len;
+	mode->htotal = mode->hsync_end + fb_mode->left_margin;
+	mode->hskew = 0;
+
+	mode->vdisplay = fb_mode->yres;
+	mode->vsync_start = mode->vdisplay + fb_mode->lower_margin;
+	mode->vsync_end = mode->vsync_start + fb_mode->vsync_len;
+	mode->vtotal = mode->vsync_end + fb_mode->upper_margin;
+	mode->vscan = 0;
+
+	mode->flags = 0;
+
+	if (fb_mode->sync & FB_SYNC_HOR_HIGH_ACT)
+		mode->flags |= DRM_MODE_FLAG_PHSYNC;
+	else
+		mode->flags |= DRM_MODE_FLAG_NHSYNC;
+
+	if (fb_mode->sync & FB_SYNC_VERT_HIGH_ACT)
+		mode->flags |= DRM_MODE_FLAG_PVSYNC;
+	else
+		mode->flags |= DRM_MODE_FLAG_NVSYNC;
+
+	if (fb_mode->sync & FB_SYNC_COMP_HIGH_ACT)
+		mode->flags |= DRM_MODE_FLAG_CSYNC | DRM_MODE_FLAG_PCSYNC;
+
+	if (fb_mode->vmode & FB_VMODE_INTERLACED)
+		mode->flags |= DRM_MODE_FLAG_INTERLACE;
+
+	if (fb_mode->vmode & FB_VMODE_DOUBLE)
+		mode->flags |= DRM_MODE_FLAG_DBLSCAN;
+
+	mode->width_mm = 0;
+	mode->height_mm = 0;
+
+	/* final step; depends on previous setup */
+	if (fb_mode->name) {
+		strncpy(mode->name, fb_mode->name, sizeof(mode->name) - 1);
+		mode->name[sizeof(mode->name) - 1] = '\0';
+	} else {
+		drm_mode_set_name(mode);
+	}
+}
+
+/**
+ * drm_mode_update_from_fb_var_screeninfo - Sets a drm_display mode structure
+ *	from an fb_var_screenmode structure
+ * @mode:	the DRM display mode structure to update
+ * @fb_var:	an fb_var_screeninfo structure
+ */
+static void drm_mode_update_from_fb_var_screeninfo(
+	struct drm_display_mode *mode, const struct fb_var_screeninfo *fb_var)
+{
+	struct fb_videomode fb_mode;
+
+	fb_var_to_videomode(&fb_mode, fb_var);
+	drm_mode_update_from_fb_videomode(mode, &fb_mode);
+}
+
+/**
+ * drm_fbconv_init_fb_videomode_from_mode - initializes an fb_videomode
+ *	structure from a DRM display mode
+ * @fb_mode:	the fb_videomode structure to update
+ * @mode:	a DRM display mode
+ */
+static void drm_fbconv_init_fb_videomode_from_mode(
+	struct fb_videomode *fb_mode, const struct drm_display_mode *mode)
+{
+	memset(fb_mode, 0, sizeof(*fb_mode));
+
+	fb_mode->name = NULL;
+	fb_mode->refresh = drm_mode_vrefresh(mode);
+	fb_mode->xres = mode->hdisplay;
+	fb_mode->yres = mode->vdisplay;
+	fb_mode->pixclock = KHZ2PICOS(mode->clock);
+	fb_mode->left_margin = mode->htotal - mode->hsync_end;
+	fb_mode->right_margin = mode->hsync_start - mode->hdisplay;
+	fb_mode->upper_margin = mode->vtotal - mode->vsync_end;
+	fb_mode->lower_margin = mode->vsync_start - mode->vdisplay;
+	fb_mode->hsync_len = mode->hsync_end - mode->hsync_start;
+	fb_mode->vsync_len = mode->vsync_end - mode->vsync_start;
+
+	fb_mode->sync = 0;
+	if (mode->flags & DRM_MODE_FLAG_PHSYNC)
+		fb_mode->sync |= FB_SYNC_HOR_HIGH_ACT;
+	if (mode->flags & DRM_MODE_FLAG_PVSYNC)
+		fb_mode->sync |= FB_SYNC_VERT_HIGH_ACT;
+	if (mode->flags & (DRM_MODE_FLAG_CSYNC | DRM_MODE_FLAG_PCSYNC))
+		fb_mode->sync |= FB_SYNC_COMP_HIGH_ACT;
+
+	fb_mode->vmode = 0;
+	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
+		fb_mode->vmode |= FB_VMODE_INTERLACED;
+	if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
+		fb_mode->vmode |= FB_VMODE_DOUBLE;
+
+	fb_mode->flag = 0;
+}
+
+/**
+ * drm_fbconv_update_fb_var_screeninfo_from_mode - updates an
+ *	fb_var_screeninfo structure from a DRM display mode
+ * @fb_var:	the fb_var_screeninfo structure to update
+ * @mode:	a DRM display mode
+ */
+static void drm_fbconv_update_fb_var_screeninfo_from_mode(
+	struct fb_var_screeninfo *fb_var, const struct drm_display_mode *mode)
+{
+	struct fb_videomode fb_mode;
+
+	drm_fbconv_init_fb_videomode_from_mode(&fb_mode, mode);
+	fb_videomode_to_var(fb_var, &fb_mode);
+
+	fb_var->height = mode->height_mm;
+	fb_var->width = mode->width_mm;
+}
+
+/**
+ * drm_fbconv_init_fb_var_screeninfo_from_mode - initialize an
+ *	fb_var_screeninfo structure from a DRM display mode
+ * @fb_var:	the fb_var_screeninfo structure to update
+ * @mode:	a DRM display mode
+ *
+ * This is the same as drm_fbconv_update_fb_var_screeninfo_from_mode(), but
+ * first clears the fb_screeninfo structure to 0.
+ */
+static void drm_fbconv_init_fb_var_screeninfo_from_mode(
+	struct fb_var_screeninfo *fb_var, const struct drm_display_mode *mode)
+{
+	memset(fb_var, 0, sizeof(*fb_var));
+	drm_fbconv_update_fb_var_screeninfo_from_mode(fb_var, mode);
+}
+
+// FIXME helpers from
+// "[PATCH v2 8/15] drm/fbconv: Add plane-state check and update"
+// by Thomas Zimmermann <[email protected]>
+static void drm_fbconv_update_fb_var_screeninfo_from_crtc_state(
+	struct fb_var_screeninfo *fb_var, struct drm_crtc_state *crtc_state)
+{
+	const struct drm_display_mode *mode = &crtc_state->adjusted_mode;
+
+	drm_fbconv_update_fb_var_screeninfo_from_mode(fb_var, mode);
+}
+
+static int drm_fbconv_update_fb_var_screeninfo_from_framebuffer(
+	struct fb_var_screeninfo *var, struct drm_framebuffer *fb)
+{
+	switch (fb->format[0].format) {
+	case DRM_FORMAT_C1:
+		var->bits_per_pixel = 1;
+		goto color_indexed;
+
+	case DRM_FORMAT_C2:
+		var->bits_per_pixel = 2;
+		goto color_indexed;
+
+	case DRM_FORMAT_C4:
+		var->bits_per_pixel = 4;
+		goto color_indexed;
+
+	case DRM_FORMAT_C8:
+		var->bits_per_pixel = 8;
+color_indexed:
+		var->red.offset = 0;
+		var->red.length = var->bits_per_pixel;
+		var->green.offset = 0;
+		var->green.length = var->bits_per_pixel;
+		var->blue.offset = 0;
+		var->blue.length = var->bits_per_pixel;
+		break;
+
+	case DRM_FORMAT_RGB565:				// FIXME Falcon only
+	case DRM_FORMAT_RGB565 | DRM_FORMAT_BIG_ENDIAN:	// FIXME Falcon only
+	case DRM_FORMAT_XRGB8888:			// FIXME Emulated
+		// FIXME Fall back to C8/RGB332 if !Falcon or pixclock too high
+		var->bits_per_pixel = 16;
+		var->red.offset = 11;
+		var->red.length = 5;
+		var->green.offset = 5;
+		var->green.length = 6;
+		var->blue.offset = 0;
+		var->blue.length = 5;
+		break;
+
+	default:
+		return -EINVAL;
+	}
+
+	var->red.msb_right = 0;
+	var->green.msb_right = 0;
+	var->blue.msb_right = 0;
+	var->transp.offset = 0;
+	var->transp.length = 0;
+	var->transp.msb_right = 0;
+	var->grayscale = 0;
+	var->nonstd = 0;
+
+	/* Our virtual screen covers all the graphics memory (sans some
+	 * trailing bytes). This allows for setting the scanout buffer's
+	 * address with fb_pan_display().
+	 */
+
+#if 0
+	// FIXME fb->pitches[0] is not const?
+	// FIXME hvga@XR24
+	// FIXME 320x480 virt 640x243 off 0,0 bpp 16 gray 0 red 11/5/0 green 5/6/0 blue 0/5/0 transp 0/0/0 nonstd 0 act 0x0 0x0mm accel_flags 0x0 pixclock 79441 margins 9/21/5/16 sync 50/2/0 vmode 0x0 rotate 0 colorspace 0x0
+	// FIXME falcon_decode_var:1417: virtual screen 640x480 too large
+	var->xres_virtual = fb->pitches[0] * 8 / var->bits_per_pixel;
+	var->yres_virtual = screen_len / fb->pitches[0];
+#else
+	var->xres_virtual = var->xres;
+	var->yres_virtual = var->yres;
+#endif
+	return 0;
+}
+
+// FIXME helpers from
+// "[PATCH v2 9/15] drm/fbconv: Mode-setting pipeline enable / disable"
+// by Thomas Zimmermann <[email protected]>
+static int drm_fbconv_update_fb_var_screeninfo_from_simple_display_pipe(
+	struct fb_var_screeninfo *fb_var, struct drm_simple_display_pipe *pipe)
+{
+	struct atari_drm_device *atari_drm = atari_drm_from_pipe(pipe);
+	struct drm_plane *primary = pipe->crtc.primary;
+
+	if (primary && primary->state && primary->state->fb)
+		return drm_fbconv_update_fb_var_screeninfo_from_framebuffer(
+			fb_var, primary->state->fb);
+
+	fb_var->xres_virtual = fb_var->xres;
+	fb_var->yres_virtual = fb_var->yres;
+#if 0
+	// FIXME This is wrong! Bpp should be derived from fourcc
+	fb_var->bits_per_pixel = atari_drm->dev.mode_config.preferred_depth;
+	pr_info("%s:%u: using %u bpp (from preferred_depth)\n", __func__,
+		__LINE__, fb_var->bits_per_pixel);
+#else
+	fb_var->bits_per_pixel = atari_drm->next_bpp;
+#endif
+
+	return 0;
+}
+
+/* ------------------------------------------------------------------ */
+/* atari_drm (simple) display pipe				      */
+
+/**
+ * atari_drm_pipe_mode_valid
+ *
+ * This callback is used to check if a specific mode is valid in the
+ * crtc used in this simple display pipe. This should be implemented
+ * if the display pipe has some sort of restriction in the modes
+ * it can display. For example, a given display pipe may be responsible
+ * to set a clock value. If the clock can not produce all the values
+ * for the available modes then this callback can be used to restrict
+ * the number of modes to only the ones that can be displayed. Another
+ * reason can be bandwidth mitigation: the memory port on the display
+ * controller can have bandwidth limitations not allowing pixel data
+ * to be fetched at any rate.
+ *
+ * This hook is used by the probe helpers to filter the mode list in
+ * drm_helper_probe_single_connector_modes(), and it is used by the
+ * atomic helpers to validate modes supplied by userspace in
+ * drm_atomic_helper_check_modeset().
+ *
+ * This function is optional.
+ *
+ * NOTE:
+ *
+ * Since this function is both called from the check phase of an atomic
+ * commit, and the mode validation in the probe paths it is not allowed
+ * to look at anything else but the passed-in mode, and validate it
+ * against configuration-invariant hardware constraints.
+ *
+ * RETURNS:
+ *
+ * drm_mode_status Enum
+ */
+static enum drm_mode_status
+atari_drm_pipe_mode_valid(struct drm_simple_display_pipe *pipe,
+			  const struct drm_display_mode *mode)
+{
+	if (atari_drm_check_size(mode->hdisplay, mode->vdisplay, NULL) < 0)
+		return MODE_BAD;
+
+	return MODE_OK;
+}
+
+/**
+ * atari_drm_pipe_mode_fixup:
+ *
+ * This callback is used to validate a mode. The parameter mode is the
+ * display mode that userspace requested, adjusted_mode is the mode the
+ * encoders need to be fed with. Note that this is the inverse semantics
+ * of the meaning for the &drm_encoder and &drm_bridge_funcs.mode_fixup
+ * vfunc. If the CRTC of the simple display pipe cannot support the
+ * requested conversion from mode to adjusted_mode it should reject the
+ * modeset.
+ *
+ * This function is optional.
+ *
+ * NOTE:
+ *
+ * This function is called in the check phase of atomic modesets, which
+ * can be aborted for any reason (including on userspace's request to
+ * just check whether a configuration would be possible). Atomic drivers
+ * MUST NOT touch any persistent state (hardware or software) or data
+ * structures except the passed in adjusted_mode parameter.
+ *
+ * Atomic drivers which need to inspect and adjust more state should
+ * instead use the @atomic_check callback, but note that they're not
+ * perfectly equivalent: @mode_valid is called from
+ * drm_atomic_helper_check_modeset(), but @atomic_check is called from
+ * drm_atomic_helper_check_planes(), because originally it was meant for
+ * plane update checks only.
+ *
+ * Also beware that userspace can request its own custom modes, neither
+ * core nor helpers filter modes to the list of probe modes reported by
+ * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
+ * that modes are filtered consistently put any CRTC constraints and
+ * limits checks into @mode_valid.
+ *
+ * RETURNS:
+ *
+ * True if an acceptable configuration is possible, false if the modeset
+ * operation should be rejected.
+ */
+static bool atari_drm_pipe_mode_fixup(struct drm_crtc *crtc,
+				      const struct drm_display_mode *mode,
+				      struct drm_display_mode *adjusted_mode)
+{
+	// FIXME
+	// Based on drm_fbconv_simple_display_pipe_mode_fixup() in
+	// "[PATCH v2 9/15] drm/fbconv: Mode-setting pipeline enable / disable"
+	// by Thomas Zimmermann <[email protected]>
+	struct drm_simple_display_pipe *pipe =
+		container_of(crtc, struct drm_simple_display_pipe, crtc);
+	struct fb_var_screeninfo var;
+	int ret;
+
+	drm_fbconv_init_fb_var_screeninfo_from_mode(&var, mode);
+
+	// FIXME This is wrong! Bpp should be derived from fourcc
+	ret = drm_fbconv_update_fb_var_screeninfo_from_simple_display_pipe(
+		&var, pipe);
+	if (ret)
+		return true;
+
+return true; // FIXME
+	ret = atafb_check_var(&var, &fb_info);
+	if (ret < 0)
+		return false;
+
+	drm_mode_update_from_fb_var_screeninfo(adjusted_mode, &var);
+
+	return true;
+}
+static int atari_drm_pipe_check(struct drm_simple_display_pipe *pipe,
+				struct drm_plane_state *plane_state,
+				struct drm_crtc_state *crtc_state)
+{
+	struct atari_drm_device *atari_drm = atari_drm_from_pipe(pipe);
+	struct drm_framebuffer *fb = plane_state->fb;
+
+	// FIXME
+	// Based on drm_fbconv_simple_display_pipe_check() in
+	// "[PATCH v2 8/15] drm/fbconv: Add plane-state check and update"
+	// by Thomas Zimmermann <[email protected]>
+	int ret;
+	struct fb_var_screeninfo var;
+
+	/*
+	 * CRTC check
+	 */
+
+	/* DRM porting notes: when fbcon takes over the console, it regularly
+	 * changes the display mode. Where's apparently no way to detect this
+	 * directly from fbcon itself. DRM's mode information might therefore
+	 * be out of data, after it takes over the display at a later time.
+	 * Here, we test the CRTC's current mode with the fbdev state. If they
+	 * do not match, we request a mode change from DRM. If you port an
+	 * fbdev driver to DRM, you can remove this code section, DRM will
+	 * be in full control of the display device and doesn't have to react
+	 * to changes from external sources.
+	 */
+
+	if (!crtc_state->mode_changed && crtc_state->adjusted_mode.clock) {
+		struct fb_videomode fb_mode, fb_var_mode;
+
+		drm_fbconv_init_fb_videomode_from_mode(
+			&fb_mode, &crtc_state->adjusted_mode);
+		fb_var_to_videomode(&fb_var_mode, &fb_info.var);
+		if (!fb_mode_is_equal(&fb_mode, &fb_var_mode))
+			crtc_state->mode_changed = true;
+	}
+
+	/*
+	 * Plane check
+	 */
+
+	if (!plane_state->crtc)
+		return 0;
+
+	ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state,
+						  1 << 16, 1 << 16,
+						  false, true);
+	if (ret < 0)
+		return ret;
+
+	if (!plane_state->visible || !fb)
+		return 0;
+
+	/* Virtual screen sizes are not supported.
+	 */
+
+	if (drm_rect_width(&plane_state->dst) != fb->width ||
+	    drm_rect_height(&plane_state->dst) != fb->height) {
+		DRM_ERROR("fbconv: virtual screen sizes not supported\n");
+		return -EINVAL;
+	}
+	if (plane_state->dst.x1 || plane_state->dst.y1) {
+		DRM_ERROR("fbconv: virtual screen offset not supported\n");
+		return -EINVAL;
+	}
+
+	/* Pixel formats have to be compatible with fbdev. This is
+	 * usually some variation of XRGB.
+	 */
+
+	if (!pipe->plane.state || !pipe->plane.state->fb ||
+	    pipe->plane.state->fb->format[0].format != fb->format[0].format) {
+		memcpy(&var, &fb_info.var, sizeof(var));
+		drm_fbconv_update_fb_var_screeninfo_from_crtc_state(
+			&var, crtc_state);
+		atari_drm->next_bpp = var.bits_per_pixel;
+		drm_fbconv_update_fb_var_screeninfo_from_framebuffer(&var, fb);
+		ret = atafb_check_var(&var, &fb_info);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
+static void atari_drm_pipe_enable(struct drm_simple_display_pipe *pipe,
+				  struct drm_crtc_state *crtc_state,
+				  struct drm_plane_state *plane_state)
+{
+	const struct drm_display_mode *mode = &crtc_state->adjusted_mode;
+	struct atari_drm_device *atari_drm = atari_drm_from_pipe(pipe);
+	struct drm_shadow_plane_state *shadow_plane_state =
+		to_drm_shadow_plane_state(plane_state);
+	struct drm_framebuffer *fb = plane_state->fb;
+	struct drm_crtc *crtc = &pipe->crtc;
+	struct fb_var_screeninfo var;
+	int ret;
+
+	drm_crtc_vblank_on(crtc);
+	f_vblank_enabled = 1;	// FIXME
+	// FIXME
+
+	// FIXME
+	// Based on drm_fbconv_simple_display_pipe_enable() in
+	// "[PATCH v2 9/15] drm/fbconv: Mode-setting pipeline enable / disable"
+	// by Thomas Zimmermann <[email protected]>
+
+	/* As this is atomic mode setting, any function call is not
+	 * allowed to fail. If it does, an additional test should be
+	 * added to simple_display_pipe_check().
+	 */
+
+	drm_fbconv_init_fb_var_screeninfo_from_mode(&var, mode);
+
+	if (plane_state && fb) {
+		ret = drm_fbconv_update_fb_var_screeninfo_from_framebuffer(
+			&var, fb);
+		if (ret)
+			return;
+	} else {
+		var.xres_virtual = var.xres;
+		var.yres_virtual = var.yres;
+	}
+
+	fb_info.var = var;
+	atafb_set_par(&fb_info);
+	atari_drm_mode_set(atari_drm, &crtc_state->mode, fb);
+	atafb_blank(FB_BLANK_UNBLANK, &fb_info);
+
+	atari_drm_fb_blit_fullscreen(fb, &shadow_plane_state->data[0]);
+}
+
+static void atari_drm_pipe_disable(struct drm_simple_display_pipe *pipe)
+{
+	struct drm_crtc *crtc = &pipe->crtc;
+
+	f_vblank_enabled = 0;	// FIXME
+	drm_crtc_vblank_off(crtc);
+	atafb_blank(FB_BLANK_POWERDOWN, &fb_info);
+}
+
+static void atari_drm_load_lut(struct drm_crtc *crtc)
+{
+	struct drm_crtc_state *crtc_state = crtc->state;
+	struct drm_color_lut *lut;
+	unsigned int i;
+
+	if (!crtc_state->gamma_lut || !crtc->enabled)
+		return;
+
+	lut = crtc_state->gamma_lut->data;
+
+	// FIXME hardcoded 256
+	for (i = 0; i < 256; i++)
+		fbhw->set_col_reg(i, lut[i].red, lut[i].green, lut[i].blue);
+}
+
+static void atari_drm_pipe_update(struct drm_simple_display_pipe *pipe,
+				  struct drm_plane_state *old_plane_state)
+{
+	struct atari_drm_device *atari_drm = atari_drm_from_pipe(pipe);
+	struct drm_plane_state *plane_state = pipe->plane.state;
+	struct drm_shadow_plane_state *shadow_plane_state =
+		to_drm_shadow_plane_state(plane_state);
+	struct drm_framebuffer *fb = plane_state->fb;
+	struct drm_crtc *crtc = &pipe->crtc;
+	struct fb_var_screeninfo var;
+	struct drm_rect rect;
+	int ret;
+
+	if (!fb) {
+		/* No framebuffer installed; blank display. */
+		atafb_blank(FB_BLANK_NORMAL, &fb_info);
+		return;
+	}
+
+	// FIXME
+	// Based on drm_fbconv_simple_display_pipe_enable() in
+	// "[PATCH v2 8/15] drm/fbconv: Add plane-state check and update"
+	// by Thomas Zimmermann <[email protected]>
+
+	/*
+	 * Plane update
+	 */
+
+	// FIXME Always true for xrgb8888-to-rgb332/rgb565?
+	if (atari_drm->bpp != drm_format_info_bpp(fb->format, 0) ||
+	    fb_info.var.xres_virtual != fb->width) {
+		/*
+		 * Pixel format changed, update fb_info accordingly
+		 */
+
+		var = fb_info.var;
+		ret = drm_fbconv_update_fb_var_screeninfo_from_framebuffer(
+			&var, fb);
+		if (ret)
+			return;
+
+		fb_info.var = var;
+		atafb_set_par(&fb_info);
+#if 1
+		atari_drm_mode_set(atari_drm, &crtc->mode, fb);
+#endif
+	}
+
+	// FIXME Called multiple times (fb_set_logocmap() uses fb_cmap.len = 16)
+	if (!old_plane_state->fb || /* first-time update */
+	    atari_drm->bpp != drm_format_info_bpp(fb->format, 0) ||
+	    crtc->state->color_mgmt_changed) {
+
+		/* DRM porting notes: Below we set the LUTs for palette and
+		 * gamma correction. This is required by some fbdev drivers,
+		 * such as nvidiafb and atyfb, which don't initialize the
+		 * table to pass-through the framebuffer values unchanged. This
+		 * is actually CRTC state, but the respective function
+		 * crtc_helper_mode_set_nofb() is only called when a CRTC
+		 * property changes, changes in color formats are not handled
+		 * there. When you're porting a fbdev driver to DRM, remove
+		 * the call. Gamma LUTs are CRTC properties and should be
+		 * handled there. Either remove gamma correction or set up
+		 * the respective CRTC properties for userspace.
+		 */
+		atari_drm_load_lut(crtc);
+	}
+
+	if (drm_atomic_helper_damage_merged(old_plane_state, plane_state,
+					    &rect))
+		atari_drm_fb_blit_rect(fb, &shadow_plane_state->data[0], &rect);
+
+	// FIXME removing the block below triggers WARN_ON(new_crtc_state->event) in drivers/gpu/drm/drm_atomic_helper.c:2475 drm_atomic_helper_commit_hw_done
+	// FIXME I still see that warning when running modetest
+	if (crtc->state->event) {
+		spin_lock_irq(&crtc->dev->event_lock);
+		drm_crtc_send_vblank_event(crtc, crtc->state->event);
+		crtc->state->event = NULL;
+		spin_unlock_irq(&crtc->dev->event_lock);
+	}
+}
+
+static const struct drm_simple_display_pipe_funcs atari_drm_pipe_funcs = {
+	.mode_valid = atari_drm_pipe_mode_valid,
+	.mode_fixup = atari_drm_pipe_mode_fixup,
+	.check	    = atari_drm_pipe_check,
+	.enable	    = atari_drm_pipe_enable,
+	.disable    = atari_drm_pipe_disable,
+	.update	    = atari_drm_pipe_update,
+	DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS,
+};
+
+static const uint32_t atari_drm_formats[] = {
+	DRM_FORMAT_C1,		/* FIXME */
+	DRM_FORMAT_C2,		/* FIXME */
+	DRM_FORMAT_C4,		/* FIXME */
+	DRM_FORMAT_C8,		/* FIXME TT & Falcon only */
+	DRM_FORMAT_RGB565,	/* FIXME Falcon only */
+	DRM_FORMAT_RGB565 | DRM_FORMAT_BIG_ENDIAN,	/* FIXME Falcon only */
+	DRM_FORMAT_XRGB8888,	/* FIXME Always needed? E.g. for modetest */
+};
+
+static const uint64_t atari_drm_modifiers[] = {
+	DRM_FORMAT_MOD_LINEAR,
+	DRM_FORMAT_MOD_INVALID
+};
+
+static int atari_drm_pipe_init(struct atari_drm_device *atari_drm)
+{
+	int ret;
+
+	ret = drm_simple_display_pipe_init(&atari_drm->dev, &atari_drm->pipe,
+					   &atari_drm_pipe_funcs,
+					   atari_drm_formats,
+					   ARRAY_SIZE(atari_drm_formats),
+					   atari_drm_modifiers,
+					   &atari_drm->conn);
+	if (ret)
+		return ret;
+
+	// FIXME hardcoded 256
+	drm_mode_crtc_set_gamma_size(&atari_drm->pipe.crtc, 256);
+	drm_crtc_enable_color_mgmt(&atari_drm->pipe.crtc, 0, false, 256);
+
+	drm_plane_enable_fb_damage_clips(&atari_drm->pipe.plane);
+	return 0;
+}
+
+/* ------------------------------------------------------------------ */
+/* atari_drm framebuffers & mode config				      */
+
+static struct drm_framebuffer*
+atari_drm_fb_create(struct drm_device *dev, struct drm_file *file_priv,
+		    const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+	struct drm_framebuffer *fb;
+
+	switch (mode_cmd->pixel_format) {
+	case DRM_FORMAT_C1:
+	case DRM_FORMAT_C2:
+	case DRM_FORMAT_C4:
+		break;
+
+	case DRM_FORMAT_C8:
+		// FIXME TT & Falcon only
+		break;
+
+	case DRM_FORMAT_RGB565:
+	case DRM_FORMAT_RGB565 | DRM_FORMAT_BIG_ENDIAN:

drivers/gpu/drm/tiny/atari_drm.c static int __init atafb_setup(char *options) · line 4363

Quoted 10 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +10 -0
+		// FIXME Falcon only
+		break;
+
+	case DRM_FORMAT_XRGB8888:
+		// FIXME
+		break;
+
+	default:
+		return ERR_PTR(-EINVAL);
+	}

The format checks don't belong here. IIRC the format will be validated when you try to set the framebuffer for a plane during the atomic commit

drivers/gpu/drm/tiny/atari_drm.c static int __init atafb_setup(char *options) · line 4366

Quoted 3 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +3 -0
+
+	if (atari_drm_check_size(mode_cmd->width, mode_cmd->height, NULL) < 0)
+		return ERR_PTR(-EINVAL);

Same here. The size checks are performed when the framebuffer is used.

drivers/gpu/drm/tiny/atari_drm.c static int __init atafb_setup(char *options) · line 4378

Quoted 12 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +12 -0
+
+	// FIXME allocate C1 and RGB565 in ST-RAM?
+	fb = drm_gem_fb_create_with_dirty(dev, file_priv, mode_cmd);
+	drm_WARN_ON_ONCE(dev, fb->pitches[0] > fb->width *
+			      drm_format_info_bpp(fb->format, 0) / 8);
+	return fb;
+}
+
+static const struct drm_mode_config_funcs atari_drm_mode_config_funcs = {
+	.fb_create = atari_drm_fb_create,
+	.atomic_check = drm_atomic_helper_check,	// FIXME
+	.atomic_commit = drm_atomic_helper_commit,	// FIXME

Why FIXMEs? Thes elines appear correct.

Quoted 42 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +42 -0
+};
+
+static int atari_drm_mode_config_init(struct atari_drm_device *atari_drm)
+{
+	struct drm_device *dev = &atari_drm->dev;
+	int ret;
+
+	ret = drmm_mode_config_init(dev);
+	if (ret)
+		return ret;
+
+	ret = fbhw->config_init(atari_drm);
+	if (ret)
+		return ret;
+
+	dev->mode_config.prefer_shadow = 0;
+	// FIXME drm_mode_addfb2_ioctl() needs
+	// FIXME quirk_addfb_prefer_host_byte_order on big-endian
+	dev->mode_config.quirk_addfb_prefer_host_byte_order = true;
+	dev->mode_config.funcs = &atari_drm_mode_config_funcs;
+
+	return 0;
+}
+
+/* ------------------------------------------------------------------ */
+
+DEFINE_DRM_GEM_FOPS(atari_drm_fops);
+
+static const struct drm_driver atari_drm_driver = {
+	.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
+
+	.name		 = DRIVER_NAME,
+	.desc		 = "Atari",
+	.date		 = "2020",
+	.major		 = 1,
+	.minor		 = 0,
+
+	.fops		 = &atari_drm_fops,
+	DRM_GEM_SHMEM_DRIVER_OPS,
+};
+
+static int __init atari_drm_probe(struct platform_device *pdev)

drivers/gpu/drm/tiny/atari_drm.c static int __init atafb_setup(char *options) · line 4430

Quoted 10 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +10 -0
+{
+	struct atari_drm_device *atari_drm;
+	int pad, detected_mode, error;
+	struct drm_device *dev;
+	unsigned long mem_req;
+	char *option = NULL;
+	int ret;
+
+	if (fb_get_options("atafb", &option))
+		return -ENODEV;

That function is not available here.

Best regards
Thomas

Quoted 244 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +153 -38
+
+	ret = -ENOMEM;
+	atari_drm = devm_drm_dev_alloc(&pdev->dev, &atari_drm_driver,
+				       struct atari_drm_device, dev);
+	if (IS_ERR(atari_drm))
+		return PTR_ERR(atari_drm);
+
+	dev = &atari_drm->dev;
+
+	atafb_setup(option);
+	dev_dbg(&pdev->dev, "%s: start\n", __func__);
+
+	do {
+#ifdef ATAFB_EXT
+		if (external_addr) {
+			dev_dbg(&pdev->dev, "initializing external hw\n");
+			fbhw = &ext_switch;
+			atari_drm->defmode = DEFMODE_EXT;
+			break;
+		}
+#endif
+#ifdef ATAFB_TT
+		if (ATARIHW_PRESENT(TT_SHIFTER)) {
+			dev_dbg(&pdev->dev, "initializing TT hw\n");
+			fbhw = &tt_switch;
+			atari_drm->defmode = DEFMODE_TT;
+			break;
+		}
+#endif
+#ifdef ATAFB_FALCON
+		if (ATARIHW_PRESENT(VIDEL_SHIFTER)) {
+			dev_dbg(&pdev->dev, "initializing Falcon hw\n");
+			fbhw = &falcon_switch;
+			error = request_irq(IRQ_AUTO_4, falcon_vbl_switcher, 0,
+					    "framebuffer:modeswitch",
+					    &atari_drm->pipe.crtc);
+			if (error)
+				return error;
+			atari_drm->defmode = DEFMODE_F30;
+			break;
+		}
+#endif
+#ifdef ATAFB_STE
+		if (ATARIHW_PRESENT(STND_SHIFTER) ||
+		    ATARIHW_PRESENT(EXTD_SHIFTER)) {
+			dev_dbg(&pdev->dev, "initializing ST/E hw\n");
+			fbhw = &st_switch;
+			atari_drm->defmode = DEFMODE_STE;
+			break;
+		}
+		fbhw = &st_switch;
+		dev_warn(&pdev->dev,
+			 "Cannot determine video hardware; defaulting to ST(e)\n");
+#else /* ATAFB_STE */
+		/* no default driver included */
+		/* Nobody will ever see this message :-) */
+		panic("Cannot initialize video hardware");
+#endif
+	} while (0);
+
+	/* Multisync monitor capabilities */
+	/* Atari-TOS defaults if no boot option present */
+	if (fb_info.monspecs.hfmin == 0) {
+		fb_info.monspecs.hfmin = 31000;
+		fb_info.monspecs.hfmax = 33000;	// FIXME stmid fails with 32000
+		fb_info.monspecs.vfmin = 58;
+		fb_info.monspecs.vfmax = 62;
+	}
+
+	detected_mode = fbhw->detect();
+	check_default_par(detected_mode);
+#ifdef ATAFB_EXT
+	if (!external_addr) {
+#endif /* ATAFB_EXT */
+		mem_req = default_mem_req + ovsc_offset + ovsc_addlen;
  		mem_req = PAGE_ALIGN(mem_req) + PAGE_SIZE;
  		screen_base = atari_stram_alloc(mem_req, "atafb");
  		if (!screen_base)
@@ -3098,7 +4538,6 @@ static int __init atafb_probe(struct platform_device *pdev)
  	}
  #endif /* ATAFB_EXT */
 
-//	strcpy(fb_info.mode->name, "Atari Builtin ");
  	fb_info.fbops = &atafb_ops;
  	// try to set default (detected; requested) var
  	do_fb_set_var(&atafb_predefined[default_par - 1], 1);
@@ -3109,25 +4548,10 @@ static int __init atafb_probe(struct platform_device *pdev)
  	// so set sane var first, then call atafb_set_par
  	atafb_get_var(&fb_info.var, &fb_info);
 
-#ifdef ATAFB_FALCON
-	fb_info.pseudo_palette = current_par.hw.falcon.pseudo_palette;
-#endif
  	fb_info.flags = FBINFO_FLAG_DEFAULT;
 
-	if (!fb_find_mode(&fb_info.var, &fb_info, mode_option, atafb_modedb,
-			  NUM_TOTAL_MODES, &atafb_modedb[defmode],
-			  fb_info.var.bits_per_pixel)) {
-		return -EINVAL;
-	}
-
-	fb_videomode_to_modelist(atafb_modedb, NUM_TOTAL_MODES,
-				 &fb_info.modelist);
-
  	atafb_set_disp(&fb_info);
 
-	fb_alloc_cmap(&(fb_info.cmap), 1 << fb_info.var.bits_per_pixel, 0);
-
-
  	dev_info(&pdev->dev, "Determined %dx%d, depth %d\n", fb_info.var.xres,
  		 fb_info.var.yres, fb_info.var.bits_per_pixel);
  	if ((fb_info.var.xres != fb_info.var.xres_virtual) ||
@@ -3135,53 +4559,109 @@ static int __init atafb_probe(struct platform_device *pdev)
  		dev_info(&pdev->dev, "   virtual %dx%d\n",
  			 fb_info.var.xres_virtual, fb_info.var.yres_virtual);
 
-	if (register_framebuffer(&fb_info) < 0) {
+	atari_drm->bpp = fb_info.var.bits_per_pixel;
+
+	ret = drm_vblank_init(&atari_drm->dev, 1);
+	if (ret)
+		goto fail;
+
+	ret = atari_drm_mode_config_init(atari_drm);
+	if (ret)
+		goto fail;
+
+	ret = atari_drm_conn_init(atari_drm);
+	if (ret < 0)
+		goto fail;
+
+	ret = atari_drm_pipe_init(atari_drm);
+	if (ret < 0)
+		goto fail;
+
+	drm_mode_config_reset(dev);
+
+	platform_set_drvdata(pdev, dev);
+	ret = drm_dev_register(dev, 0);
+	if (ret)
+		goto fail;
+
+	dev_info(&pdev->dev, "Atari DRM, using %dK of video memory\n",
+		 screen_len >> 10);
+
+	drm_fbdev_generic_setup(dev, dev->mode_config.preferred_depth);
+
+	/* TODO: This driver cannot be unloaded yet */
+	return 0;
+
+fail:
+	/* FIXME drmm_add_action_or_reset() */
+	/* FIXME cleanup non-external frame buffer */
  #ifdef ATAFB_EXT
-		if (external_addr) {
-			iounmap(external_screen_base);
-			external_addr = 0;
-		}
-		if (external_vgaiobase) {
-			iounmap((void*)external_vgaiobase);
-			external_vgaiobase = 0;
-		}
-#endif
-		return -EINVAL;
+	if (external_addr) {
+		iounmap(external_screen_base);
+		external_addr = 0;
+	}
+	if (external_vgaiobase) {
+		iounmap((void*)external_vgaiobase);
+		external_vgaiobase = 0;
  	}
+#endif
+	return ret;
+}
 
-	fb_info(&fb_info, "frame buffer device, using %dK of video memory\n",
-		screen_len >> 10);
+#if 0 // FIXME
+static int atari_drm_remove(struct platform_device *pdev)
+{
+	struct drm_device *dev = platform_get_drvdata(pdev);
+
+	drm_dev_unplug(dev);
+	drm_atomic_helper_shutdown(dev);
 
-	/* TODO: This driver cannot be unloaded yet */
  	return 0;
  }
+#endif
 
-static void atafb_shutdown(struct platform_device *pdev)
+static void atari_drm_shutdown(struct platform_device *pdev)
  {
  	/* Unblank before kexec */
  	if (fbhw->blank)
  		fbhw->blank(0);
  }
 
-static struct platform_driver atafb_driver = {
-	.shutdown	= atafb_shutdown,
+static struct platform_driver atari_drm_platform_driver = {
  	.driver	= {
-		.name	= "atafb",
+		.name = DRIVER_NAME,
  	},
+	// FIXME .probe = atari_drm_probe,
+	// FIXME .remove = atari_drm_remove,
+	.shutdown = atari_drm_shutdown,
  };
 
-static int __init atafb_init(void)
+static int __init atari_drm_init(void)
  {
  	struct platform_device *pdev;
 
  	if (!MACH_IS_ATARI)
  		return -ENODEV;
 
-	pdev = platform_device_register_simple("atafb", -1, NULL, 0);
+	// FIXME Should use the same platform device as atafb
+	pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
  	if (IS_ERR(pdev))
  		return PTR_ERR(pdev);
 
-	return platform_driver_probe(&atafb_driver, atafb_probe);
+	// FIXME platform_driver_register
+	return platform_driver_probe(&atari_drm_platform_driver,
+				     atari_drm_probe);
+}
+
+module_init(atari_drm_init);
+
+#if 0 // FIXME
+static void __exit atari_drm_exit(void)
+{
+	platform_driver_unregister(&atari_drm_platform_driver);
  }
 
-device_initcall(atafb_init);
+module_exit(atari_drm_exit);
+#endif
+
+MODULE_LICENSE("GPL");
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
#6 lore raw

Re: [PATCH/RFC 3/3] drm: atari: Add a DRM driver for Atari graphics hardware

Hi Thomas,

Quoted 1 line · Thomas Zimmermann

that's an interesting driver. I left a few comments below.

Thanks for your comments!

Quoted 19 lines

Am 25.11.22 um 21:31 schrieb Geert Uytterhoeven:

Quoted 18 lines

Supported formats:
- C[1248],
- RG16 (both standard DRM (little-endian) and native (big-endian)),
- XR24.

RG16 and XR24 are only supported with the underlying RGB565 hardware mode on Falcon, and are subject to hardware restrictions (limited to e.g. "qvga" and "hvga" modes).

All formats use a shadow buffer (TODO: BE RG16 buffers from ST-RAM). Initial mode setting works, later mode changes sometimes fail.

drivers/gpu/drm/tiny/Kconfig +0 -0
@@ -10,6 +10,14 @@ config DRM_ARCPGU
 
        If M is selected the module will be called arcpgu.
 
Quoted 7 lines

drivers/gpu/drm/tiny/Kconfig config DRM_ARCPGU · line 17

Quoted 5 lines
drivers/gpu/drm/tiny/Kconfig +5 -0
+config DRM_ATARI
+     tristate "DRM support for Atari native chipset"
+     depends on DRM && ATARI
+     select DRM_KMS_HELPER
+     select DRM_GEM_SHMEM_HELPER

Alphabetical sorting of the select statements.

OK

(I blame the chain of DRM_KMS_CMA_HELPER -> DRM_GEM_CMA_HELPER ->
DRM_GEM_DMA_HELPER renames ;-)

Quoted 50 lines
Quoted 33 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +4 -0
@@ -2288,11 +2279,13 @@ static struct fb_hwswitch tt_switch = {
  static struct fb_hwswitch falcon_switch = {
      .detect         = falcon_detect,
      .encode_fix     = falcon_encode_fix,
+     .config_init    = falcon_config_init,
      .decode_var     = falcon_decode_var,
      .encode_var     = falcon_encode_var,
      .get_par        = falcon_get_par,
      .set_par        = falcon_set_par,
      .set_screen_base = set_screen_base,
+     .set_col_reg    = falcon_set_col_reg,
      .blank          = falcon_blank,
      .pan_display    = falcon_pan_display,
  };
@@ -2302,11 +2295,13 @@ static struct fb_hwswitch falcon_switch = {
  static struct fb_hwswitch st_switch = {
      .detect         = stste_detect,
      .encode_fix     = stste_encode_fix,
+     .config_init    = stste_config_init,
      .decode_var     = stste_decode_var,
      .encode_var     = stste_encode_var,
      .get_par        = stste_get_par,
      .set_par        = stste_set_par,
      .set_screen_base = stste_set_screen_base,
+     .set_col_reg    = stste_set_col_reg,
      .pan_display    = pan_display
  };
  #endif
@@ -2315,10 +2310,12 @@ static struct fb_hwswitch st_switch = {
  static struct fb_hwswitch ext_switch = {

drivers/gpu/drm/tiny/atari_drm.c static struct fb_hwswitch st_switch = { · line 2320

Quoted 10 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +2 -0
      .detect         = ext_detect,
      .encode_fix     = ext_encode_fix,
+     .config_init    = ext_config_init,
      .decode_var     = ext_decode_var,
      .encode_var     = ext_encode_var,
      .get_par        = ext_get_par,
      .set_par        = ext_set_par,
+     .set_col_reg    = ext_set_col_reg,
  };
  #endif

This design is problematic. It recreates fbdev interfaces within DRM and makes it very hard to convert the driver to good DRM code. I suggest to branch at the outer-most point for each supported model. So each model effectively receives it's own mode-config pipeline. Common code can still be shared.

Quoted 2 lines

For a good example, I'd refer to the latest mgag200 driver, which implements this pattern for the variety of revisions of its hardware.

I do not intend to keep this internal API.
It should be reworked by removing all fbdev'isms.

Quoted 5 lines

drivers/gpu/drm/tiny/atari_drm.c static int __init atafb_setup(char *options) · line 3671

Quoted 3 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +3 -0
+// FIXME helpers from
+// "[PATCH v2 5/15] drm/fbconv: Add DRM <-> fbdev pixel-format conversion"
+// by Thomas Zimmermann <[email protected]>

All these FIXMEs will need to be resolved.

Definitely.

Quoted 10 lines
Quoted 9 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +9 -0
+static void atari_drm_pipe_update(struct drm_simple_display_pipe *pipe,
+                               struct drm_plane_state *old_plane_state)
+{
+     struct atari_drm_device *atari_drm = atari_drm_from_pipe(pipe);
+     struct drm_plane_state *plane_state = pipe->plane.state;
+     struct drm_shadow_plane_state *shadow_plane_state =
+             to_drm_shadow_plane_state(plane_state);
+     struct drm_framebuffer *fb = plane_state->fb;
+     struct drm_crtc *crtc = &pipe->crtc;
Quoted 2 lines

drivers/gpu/drm/tiny/atari_drm.c static int __init atafb_setup(char *options) · line 4278

Quoted 2 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +2 -0
+     // FIXME removing the block below triggers WARN_ON(new_crtc_state->event) in drivers/gpu/drm/drm_atomic_helper.c:2475 drm_atomic_helper_commit_hw_done
+     // FIXME I still see that warning when running modetest

BTW, do you know why I see that warning?
It happens less when sprinkling debug prints all over the place.

Quoted 31 lines
Quoted 31 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +30 -0
+     if (crtc->state->event) {
+             spin_lock_irq(&crtc->dev->event_lock);
+             drm_crtc_send_vblank_event(crtc, crtc->state->event);
+             crtc->state->event = NULL;
+             spin_unlock_irq(&crtc->dev->event_lock);
+     }
+}
 
+static struct drm_framebuffer*
+atari_drm_fb_create(struct drm_device *dev, struct drm_file *file_priv,
+                 const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+     struct drm_framebuffer *fb;
+
+     switch (mode_cmd->pixel_format) {
+     case DRM_FORMAT_C1:
+     case DRM_FORMAT_C2:
+     case DRM_FORMAT_C4:
+             break;
+
+     case DRM_FORMAT_C8:
+             // FIXME TT & Falcon only
+             break;
+
+     case DRM_FORMAT_RGB565:
+     case DRM_FORMAT_RGB565 | DRM_FORMAT_BIG_ENDIAN:
+             // FIXME Falcon only
+             break;
+
+     case DRM_FORMAT_XRGB8888:
+             // FIXME
Quoted 8 lines

drivers/gpu/drm/tiny/atari_drm.c static int __init atafb_setup(char *options) · line 4363

Quoted 5 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +5 -0
+             break;
+
+     default:
+             return ERR_PTR(-EINVAL);
+     }

The format checks don't belong here. IIRC the format will be validated when you try to set the framebuffer for a plane during the atomic commit

OK

Quoted 5 lines

drivers/gpu/drm/tiny/atari_drm.c static int __init atafb_setup(char *options) · line 4366

Quoted 3 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +3 -0
+
+     if (atari_drm_check_size(mode_cmd->width, mode_cmd->height, NULL) < 0)
+             return ERR_PTR(-EINVAL);

Same here. The size checks are performed when the framebuffer is used.

FTR, this was based on cirrus_fb_create()...

Quoted 3 lines

drivers/gpu/drm/tiny/atari_drm.c static int __init atafb_setup(char *options) · line 4369

Quoted 3 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +3 -0
+
+     // FIXME allocate C1 and RGB565 in ST-RAM?
+     fb = drm_gem_fb_create_with_dirty(dev, file_priv, mode_cmd);

BTW, how do I allocate a buffer from graphics memory? Any example to point me to?

Quoted 11 lines

drivers/gpu/drm/tiny/atari_drm.c static int __init atafb_setup(char *options) · line 4378

Quoted 9 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +9 -0
+     drm_WARN_ON_ONCE(dev, fb->pitches[0] > fb->width *
+                           drm_format_info_bpp(fb->format, 0) / 8);
+     return fb;
+}
+
+static const struct drm_mode_config_funcs atari_drm_mode_config_funcs = {
+     .fb_create = atari_drm_fb_create,
+     .atomic_check = drm_atomic_helper_check,        // FIXME
+     .atomic_commit = drm_atomic_helper_commit,      // FIXME

Why FIXMEs? Thes elines appear correct.

Because I had the feeling I should pass my own functions...

Quoted 16 lines
Quoted 4 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +2 -0
+};
 
+static int __init atari_drm_probe(struct platform_device *pdev)

drivers/gpu/drm/tiny/atari_drm.c static int __init atafb_setup(char *options) · line 4430

Quoted 10 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +10 -0
+{
+     struct atari_drm_device *atari_drm;
+     int pad, detected_mode, error;
+     struct drm_device *dev;
+     unsigned long mem_req;
+     char *option = NULL;
+     int ret;
+
+     if (fb_get_options("atafb", &option))
+             return -ENODEV;

That function is not available here.

It is.

But now I see drm_connector_get_cmdline_mode() already calls fb_get_options(), and handles this when calling drm_connector_init(), albeit a bit late (it should bail out before changing any hardware state)?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#7 lore raw

Re: [PATCH/RFC 3/3] drm: atari: Add a DRM driver for Atari graphics hardware

In reply to Geert Uytterhoeven

Hi,

Quoted 1 line · Geert Uytterhoeven

+// FIXME create dynamically from atari_drm_modes[]?

Not necessarily, but they should have proper descriptors at the very least.

Quoted 5 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +5 -0
+static const struct drm_named_mode atari_drm_named_modes[] =
+{
+	{ .name = "st-low" },
+	{ .name = "st-mid" },
+	{ .name = "st-high" },

drivers/gpu/drm/tiny/atari_drm.c static int __init atafb_setup(char *options) · line 3638

Quoted 10 lines
drivers/gpu/drm/tiny/atari_drm.c renamed from drivers/video/fbdev/atafb.c +10 -0
+	{ .name = "tt-low" },
+	{ .name = "tt-mid" },
+	{ .name = "tt-high" },
+	{ .name = "vga" },
+	{ .name = "vga70" },
+	{ .name = "qvga" },
+	{ .name = "hvga" },
+	{ .name = "falh" },
+	{ /* sentinel */ }
+};

I'm really not convinced about per-driver named modes. This will only lead to each driver having its own set of undocumented and obscure mode names that will just make everything work.

And some of them in that list are completely generic: VGA, QVGA, HVGA at least should definitely be part of the generic named modes.

Maxime

#8 lore raw
In reply to Geert Uytterhoeven

Hi Geert!

Quoted 3 lines · Geert Uytterhoeven

This RFC patch series adds a DRM driver for the good old Atari ST/TT/Falcon hardware. It was developed and tested (only) on the ARAnyM emulator.

I just remembered this WIP driver. Has there been any progress?

Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
#9 lore raw

Hi Adrian,

Quoted 6 lines · John Paul Adrian Glaubitz
Quoted 3 lines · Geert Uytterhoeven

This RFC patch series adds a DRM driver for the good old Atari ST/TT/Falcon hardware. It was developed and tested (only) on the ARAnyM emulator.

I just remembered this WIP driver. Has there been any progress?

So far no further progress.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#10 lore raw

Hi Geert,

Quoted 10 lines · Geert Uytterhoeven
Quoted 6 lines · John Paul Adrian Glaubitz
Quoted 3 lines · Geert Uytterhoeven

This RFC patch series adds a DRM driver for the good old Atari ST/TT/Falcon hardware. It was developed and tested (only) on the ARAnyM emulator.

I just remembered this WIP driver. Has there been any progress?

So far no further progress.

I tried your "atari-drm-wip-v1" branch commits on top of 6.14.

After some minor changes those applied. Getting it to build required adding "&shadow_plane_state->fmtcnv_state" (struct drm_format_conv_state *) argument to *_blit() functions in atari_drm.c, and changing:

	drm_fbdev_generic_setup(dev, dev->mode_config.preferred_depth);
in its probe function to:
	struct drm_format_info *format = NULL;
        drm_client_setup(dev, format);

However, the result is not working very well yet.

Driver gets initialized fine under Hatari TT emulation:
-------------------------
atafb atafb: phys_screen_base 511000 screen_len 311296 atafb atafb: Determined 1280x960, depth 1
atafb atafb: virtual 1280x1945
Console: switching to mono frame buffer device 160x60
fb0: frame buffer device, using 304K of video memory
...
atari_drm atari_drm: phys_screen_base 55d000 screen_len 311296 atari_drm atari_drm: Determined 1280x960, depth 1
atari_drm atari_drm: virtual 1280x1945
[drm] Initialized atari_drm 1.0.0 for atari_drm on minor 0 atari_drm atari_drm: Atari DRM, using 304K of video memory
-------------------------

However, once screen switches from "atafb" to "atari_drm" driver, Linux boot logo & texts disappear, and (emulated) screen is either all white (on mono monitor) or all black (on VGA & RGGB monitors).

And while "atafb" works fine also under Falcon emulation with RGB (50Hz) or VGA (60Hz) monitor, "atari_drm" probing fails:
-------------------------
genirq: Flags mismatch irq 4. 00200000 (framebuffer:modeswitch) vs. 00200000 (framebuffer:modeswitch)

CPU: 0 UID: 0 PID: 1 Comm: swapper Not tainted 6.14.0hatari-00001-g1d98935cdfd7-dirty #4
Stack from 01029c78:
        ...
Call Trace: [<000088b0>] dump_stack+0x10/0x16
 [<0005852a>] __setup_irq+0x264/0x4a4
 [<00200000>] dma_buf_map_attachment_unlocked+0x34/0x6a
 [<00200000>] dma_buf_map_attachment_unlocked+0x34/0x6a
 [<001e874c>] falcon_vbl_switcher+0x0/0x14a
 [<00058876>] request_threaded_irq+0x10c/0x142
 [<0030fa1e>] strsep+0x0/0x36
 [<00449cfe>] atari_drm_probe+0x8ba/0xe28
 [<001e874c>] falcon_vbl_switcher+0x0/0x14a
 [<00200000>] dma_buf_map_attachment_unlocked+0x34/0x6a
 [<00042d6c>] parse_args+0x0/0x260
 [<00300c2a>] klist_next+0x0/0x8a
 [<00300c2a>] klist_next+0x0/0x8a
 [<00116d3c>] sysfs_do_create_link_sd+0x68/0x92
 [<00116d8e>] sysfs_create_link+0x28/0x3a
 [<001f2a52>] driver_sysfs_add+0x46/0x6c
 [<001f4dd0>] platform_probe+0x26/0x58
 [<001f3390>] really_probe+0xfa/0x1f8
 [<001f3296>] really_probe+0x0/0x1f8
 [<001f3558>] __driver_probe_device+0xca/0xd8
 [<00042d6c>] parse_args+0x0/0x260
 [<00300c2a>] klist_next+0x0/0x8a
 [<001f35da>] driver_probe_device+0x24/0x7c
 [<001f378a>] __driver_attach+0xca/0xda
 [<00300c2a>] klist_next+0x0/0x8a
 [<001f2156>] bus_for_each_dev+0x64/0x8a
 [<001f2d24>] driver_attach+0x1a/0x1e
 [<001f36c0>] __driver_attach+0x0/0xda
 [<001f270c>] bus_add_driver+0x9a/0x188
 [<001f3e66>] driver_register+0xa6/0xe4
 [<0044a790>] __platform_driver_probe+0x6c/0xa4
 [<004493ee>] atari_drm_init+0x0/0x56
 [<0044943c>] atari_drm_init+0x4e/0x56
 [<00449444>] atari_drm_probe+0x0/0xe28
 [<00437578>] do_one_initcall+0x5a/0x164
 [<0030f7e4>] strcpy+0x0/0x22
 [<00042d6c>] parse_args+0x0/0x260
 [<00060006>] __timer_delete_sync+0x38/0x6a
 [<00437820>] kernel_init_freeable+0x13e/0x198
 [<00437876>] kernel_init_freeable+0x194/0x198
 [<004493ee>] atari_drm_init+0x0/0x56
 [<00315cac>] kernel_init+0x0/0xf4
 [<00315cc4>] kernel_init+0x18/0xf4
 [<00315cac>] kernel_init+0x0/0xf4
 [<0000934c>] ret_from_kernel_thread+0xc/0x14

atari_drm atari_drm: probe with driver atari_drm failed with error -16
-------------------------

Any ideas?

============================================================

Btw. While testing this, I noticed quite a few "atafb" issues:

It panics under Falcon with mono monitor, so I couldn't test that with "atari_drm":
-------------------------

Kernel panic - not syncing: can't set default video mode
-------------------------

"video=atafb:stlow" CLI arg causes probe fail on Falcon + VGA monitor (but works with RGB monitor, and on TT):
-------------------------
atafb atafb: probe with driver atafb failed with error -22
-------------------------

Kernel CLI argument "video=atafb:falh2" gives 16-color mode, same as "falh16", not 2-color one as documented (in arch/m68k/kernel-options.rst).

Monochrome Tux logo is not shown in 2-color ("vga2", "sthigh") modes, only in 4-color ("vga4", "stmed") ones.

On TT, requesting unsupported mode, e.g. "fal2" or "tthigh" on color monitor, gives lowest (320x200x4) resolution, instead of more reasonable one, like the 640x480x4 given under Falcon. "ttmid" (640x480x4) would be more reasonable default...

On TT, console text color is blue-on-black in "sthigh" mode, instead of expected white-on-black (and cyan-on-black in "stmid"). I suspect this is because "Duochrome" mode is not handled correctly, its colors should be set with palette entries 254 & 255, and palette entry 0 is used just for inverting the screen (like on real ST-high monitor/resolution).

- Eero

#11 lore raw

Hi Eero,

Quoted 8 lines · Eero Tamminen
Quoted 7 lines · Geert Uytterhoeven
Quoted 5 lines · John Paul Adrian Glaubitz
Quoted 3 lines · Geert Uytterhoeven

This RFC patch series adds a DRM driver for the good old Atari ST/TT/Falcon hardware. It was developed and tested (only) on the ARAnyM emulator.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I just remembered this WIP driver. Has there been any progress?

So far no further progress.

I tried your "atari-drm-wip-v1" branch commits on top of 6.14.

Thanks for testing!

Quoted 7 lines

After some minor changes those applied. Getting it to build required adding "&shadow_plane_state->fmtcnv_state" (struct drm_format_conv_state *) argument to *_blit() functions in atari_drm.c, and changing:

        drm_fbdev_generic_setup(dev, dev->mode_config.preferred_depth);
in its probe function to:
        struct drm_format_info *format = NULL;
         drm_client_setup(dev, format);

I do keep it up-to-date locally, so I could provide these changes, if you are interested.

Quoted 17 lines

However, the result is not working very well yet.

Driver gets initialized fine under Hatari TT emulation:
-------------------------
atafb atafb: phys_screen_base 511000 screen_len 311296 atafb atafb: Determined 1280x960, depth 1
atafb atafb: virtual 1280x1945
Console: switching to mono frame buffer device 160x60
fb0: frame buffer device, using 304K of video memory
...
atari_drm atari_drm: phys_screen_base 55d000 screen_len 311296 atari_drm atari_drm: Determined 1280x960, depth 1
atari_drm atari_drm: virtual 1280x1945
[drm] Initialized atari_drm 1.0.0 for atari_drm on minor 0 atari_drm atari_drm: Atari DRM, using 304K of video memory
-------------------------

Quoted 3 lines

However, once screen switches from "atafb" to "atari_drm" driver, Linux boot logo & texts disappear, and (emulated) screen is either all white (on mono monitor) or all black (on VGA & RGGB monitors).

So you have both atafb and atari_drm enabled? Please don't do that.

Quoted 5 lines

And while "atafb" works fine also under Falcon emulation with RGB (50Hz) or VGA (60Hz) monitor, "atari_drm" probing fails:
-------------------------
genirq: Flags mismatch irq 4. 00200000 (framebuffer:modeswitch) vs. 00200000 (framebuffer:modeswitch)

That's also a sign of two drivers requesting the same IRQ unexpectedly.

Quoted 1 line

atari_drm atari_drm: probe with driver atari_drm failed with error -16

i.e. -EBUSY.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#12 lore raw

Hi Geert,

Quoted 13 lines · Geert Uytterhoeven
Quoted 1 line · Eero Tamminen

I tried your "atari-drm-wip-v1" branch commits on top of 6.14.

Thanks for testing!

Quoted 7 lines

After some minor changes those applied. Getting it to build required adding "&shadow_plane_state->fmtcnv_state" (struct drm_format_conv_state *) argument to *_blit() functions in atari_drm.c, and changing:

         drm_fbdev_generic_setup(dev, dev->mode_config.preferred_depth);
in its probe function to:
         struct drm_format_info *format = NULL;
          drm_client_setup(dev, format);
Quoted 2 lines

I do keep it up-to-date locally, so I could provide these changes, if you are interested.

Yes, please! (see below)

Quoted 17 lines
Quoted 17 lines

However, the result is not working very well yet.

Driver gets initialized fine under Hatari TT emulation:
-------------------------
atafb atafb: phys_screen_base 511000 screen_len 311296 atafb atafb: Determined 1280x960, depth 1
atafb atafb: virtual 1280x1945
Console: switching to mono frame buffer device 160x60
fb0: frame buffer device, using 304K of video memory
...
atari_drm atari_drm: phys_screen_base 55d000 screen_len 311296 atari_drm atari_drm: Determined 1280x960, depth 1
atari_drm atari_drm: virtual 1280x1945
[drm] Initialized atari_drm 1.0.0 for atari_drm on minor 0 atari_drm atari_drm: Atari DRM, using 304K of video memory
-------------------------

Quoted 5 lines
Quoted 3 lines

However, once screen switches from "atafb" to "atari_drm" driver, Linux boot logo & texts disappear, and (emulated) screen is either all white (on mono monitor) or all black (on VGA & RGGB monitors).

So you have both atafb and atari_drm enabled? Please don't do that.

Disabling CONFIG_FB_ATARI option (but still keeping rest of FB options), worked worse:
-------------------------
atari_drm atari_drm: phys_screen_base 512000 screen_len 311296
atari_drm atari_drm: Determined 640x480, depth 4
atari_drm atari_drm: virtual 640x972
[drm] Initialized atari_drm 1.0.0 for atari_drm on minor 0
atari_drm atari_drm: Atari DRM, using 304K of video memory
Data write fault at 0x00000020 in Super Data (pc=0x3115f6)
BAD KERNEL BUSERR

Oops: 00000000
PC: [<003115f6>] strcpy+0x16/0x22
SR: 2200  SP: (ptrval)  a2: 01026000
d0: 00000000    d1: 0000015b    d2: 0114e000    d3: 00319f2a
d4: 01181118    d5: 00000001    a0: 00000020    a1: 003e1cbf
Process swapper (pid: 1, task=(ptrval))
Frame format=A ssw=0315 isc=66f2 isb=2008 daddr=00000020 dobuf=0000005b
Stack from 01029c24:
        ...
Call Trace:
 [<001e6bc8>] __drm_fb_helper_initial_config_and_unlock+0x3a6/0x46c
 [<001e6cb0>] drm_fb_helper_initial_config+0x22/0x30
 [<001e85a0>] drm_fbdev_client_hotplug+0x6e/0x9c
 [<001d6efc>] drm_client_register+0x62/0x9e
 [<001e8714>] drm_fbdev_client_setup+0x146/0x14e
 [<00311650>] strcmp+0x0/0x34
 [<001e7bb6>] drm_client_setup+0x32/0xaa
 [<00007336>] _dev_info+0x0/0x34
 [<0044b472>] atari_drm_probe+0xd58/0xe32

...
-------------------------

=> due to me using NULL as drm_client_setup() "drm_format_info"?

Quoted 11 lines
Quoted 5 lines

And while "atafb" works fine also under Falcon emulation with RGB (50Hz) or VGA (60Hz) monitor, "atari_drm" probing fails:
-------------------------
genirq: Flags mismatch irq 4. 00200000 (framebuffer:modeswitch) vs. 00200000 (framebuffer:modeswitch)

That's also a sign of two drivers requesting the same IRQ unexpectedly.

Quoted 1 line

atari_drm atari_drm: probe with driver atari_drm failed with error -16

i.e. -EBUSY.

Ok, makes sense.

- Eero

#13 lore raw

Hi Eero,

Quoted 14 lines · Eero Tamminen
Quoted 13 lines · Geert Uytterhoeven
Quoted 1 line · Eero Tamminen

I tried your "atari-drm-wip-v1" branch commits on top of 6.14.

Thanks for testing!

Quoted 7 lines

After some minor changes those applied. Getting it to build required adding "&shadow_plane_state->fmtcnv_state" (struct drm_format_conv_state *) argument to *_blit() functions in atari_drm.c, and changing:

         drm_fbdev_generic_setup(dev, dev->mode_config.preferred_depth);
in its probe function to:
         struct drm_format_info *format = NULL;
          drm_client_setup(dev, format);
Quoted 4 lines
Quoted 2 lines

I do keep it up-to-date locally, so I could provide these changes, if you are interested.

Yes, please! (see below)

Sorry for taking so long:
https://web.git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git/log/?h=atari-drm-wip-rebasing

Enjoy!

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#14 lore raw

Hi Geert,

Quoted 9 lines · Geert Uytterhoeven
Quoted 5 lines · Eero Tamminen
Quoted 2 lines · Geert Uytterhoeven

I do keep it up-to-date locally, so I could provide these changes, if you are interested.

Yes, please! (see below)

Sorry for taking so long:
https://web.git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git/log/?h=atari-drm-wip-rebasing

Thanks!

I did boot testing on Hatari emulator with a minimal kernel config having atari_drm enabled, atafb disabled, FB & boot logo enabled.

Under Falcon emulation:
- RGB/VGA => works fine
- Mono monitor => panic
"Kernel panic - not syncing: can't set default video mode"

Under TT emulation:
- RGB/VGA => boots, but console is black[1] (palette issue?)
- Mono monitor => looks OKish[2], but has constant warnings:
-----------------------------------

WARNING: CPU: 0 PID: 1 at drivers/gpu/drm/drm_atomic_helper.c:1720 drm_atomic_helper_wait_for_vblanks+0x1a0/0x1ee

[CRTC:35:crtc-0] vblank wait timed out
-----------------------------------

Under 030 ST/STe emulation:
- RGB/VGA => boots, but console is black (palette issue?)
- Mono monitor => looks OK, but has constant slowpath warnings with:
"[CRTC:35:crtc-0] vblank wait timed out"

=> Any advice on the issues?

[1] Black when booted with (Hatari) LILO, all white when booted with "bootstra.prg", meaning from TOS.

[2] Mono colors are black on white instead of vice verse, e.g. boot logo colors are obviously inversed.

Note: the functional differences between ST, STE, TT and Falcon are all accurately emulated in Hatari.

- Eero

PS. I also profiled where most of time goes from "atari-drm" probing, until boot reaches user space. On a minimal -Os built kernel, running on (emulated) 32Mhz 030 Falcon, in the default 640x480@4 resolution:
----------------------------------------------------------------
Time spent in profile = 15.29712s.
...
Used cycles:

  22.37%  22.42%  25.35%   _transp
  19.15%  19.19%  46.82%   atari_drm_fb_blit_rect.isra.0
   8.09%   8.09%  13.80%   sys_copyarea
   3.94%   3.95%   6.23%   sys_imageblit
   3.69%   3.69%   3.69%   fb_copy_offset.isra.0
   2.12%   2.13%   2.41%   atari_scsi_falcon_reg_read
   2.03%   2.03%   2.03%   fb_address_forward
   1.85%   1.85%  17.98%   fbcon_redraw_blit.constprop.0
   1.81%   1.81%   2.04%   atari_keyb_init
   1.78%   1.78%   1.98%   fb_reverse_long
   1.58%   1.58%   1.90%   arch_cpu_idle
   1.05%                   memcpy
   0.95%                   memset

...
----------------------------------------------------------------

=> atari-drm blitting takes half the time during boot.

Building kernel with -O2, changes above rather radically, both time-wise, and where that time goes:
----------------------------------------------------------------
Time spent in profile = 6.54049s.
...
Used cycles:

  17.61%  17.61%  17.61%   sys_copyarea
  11.18%  11.18%  13.11%   arch_cpu_idle
   7.53%   7.55%   8.45%   atari_drm_fb_blit_rect.isra.0
   4.26%   4.27%   4.76%   atari_keyb_init
   2.70%   2.70%   2.93%   atari_scsi_falcon_reg_read
   2.45%   2.45%  23.81%   fbcon_redraw_blit.constprop.0
   2.35%   2.35%   2.48%   sys_imageblit
   2.12%   2.12%   5.89%   atari_floppy_init
   1.97%                   memset
   1.31%                   memcpy

...
Instruction cache misses:
27.14% 27.14% 27.14% sys_copyarea
3.77% 3.77% 4.05% atari_scsi_falcon_reg_read
...
Data cache hits:

  63.55%  63.55%  63.67%   atari_keyb_init
   7.61%   7.62%   7.84%   atari_drm_fb_blit_rect.isra.0
   3.86%   3.86%   3.86%   sys_copyarea <= not much hits for copying

...
----------------------------------------------------------------

However, -O2 build has the downside that the resulting kernel Oopses once it reaches user-space, if 030 data cache emulation is enabled:
----------------------------------------------------------------
Run /init as init process
...
Instruction fault at 0x0041a256
BAD KERNEL BUSERR

Oops: 00000000
PC: [<0041a256>] __generic_copy_from_user+0x1e/0x46
SR: 2200  SP: (ptrval)  a2: 011fe590
d0: 00000005    d1: 00000000    d2: 00000003    d3: 00000003
d4: 00000008    d5: 00000000    a0: eff70720    a1: 01225f9c

Process init (pid: 32, task=(ptrval))
Frame format=B ssw=5066 isc=5380 isb=66f6 daddr=eff7071c dobuf=00000000 baddr=eff7071c dibuf=eff7071c ver=0
Stack from 01225f78:

        ...
Call Trace: [<000409b0>] sys_rt_sigaction+0x32/0xc8
 [<00005062>] req_need_defer+0x2a/0x3a
 [<0000a4ca>] syscall+0x8/0xc

Code: 7403 c282 206e 000c 226e 0008 4a80 670a <0e98> 2000 22c2 5380 66f6 0801 0001 6706 0e58 2000 32c2 0801 0000 6706 0e18 2000
Disabling lock debugging due to kernel taint
Instruction fault at 0x00088ada
BAD KERNEL BUSERR
Oops: 00000000
PC: [<00088ada>] exit_robust_list+0x12/0xee
SR: 2200  SP: (ptrval)  a2: 011fe590
d0: 00000000    d1: 00000000    d2: 011fe94e    d3: 000000ff
d4: 00000000    d5: 00000000    a0: 011fe590    a1: 011e2b90

Process init (pid: 32, task=(ptrval))
Frame format=B ssw=5066 isc=660a isb=0eab daddr=801a206c dobuf=011fe94e baddr=801a206c dibuf=801a206c ver=0
Stack from 01225dc8:

        ....
Call Trace: [<00003730>] _printk+0x0/0x16
 [<000896ce>] futex_exit_release+0x9e/0xb8
 [<00030186>] exit_mm_release+0x12/0x28
 [<00034612>] do_exit+0x178/0x96e
 [<00002200>] show_stack+0xce/0xf4
 [<000691da>] vprintk+0x12/0x16
 [<00034e84>] make_task_dead+0x7c/0x172
 [<00005066>] req_need_defer+0x2e/0x3a
 [<00003730>] _printk+0x0/0x16
 [<0000d514>] die_if_kernel+0x0/0x22
 [<0000d536>] trap_c+0x0/0x24c
 [<0000ddaa>] buserr_c+0x628/0x756
 [<0000a3f0>] buserr+0x20/0x28
 [<00005066>] req_need_defer+0x2e/0x3a
 [<0004097e>] sys_rt_sigaction+0x0/0xc8
 [<00020007>] _FP_CALL_TOP+0x48e5/0xd512
 [<00002000>] _start+0x0/0x6
 [<000409b0>] sys_rt_sigaction+0x32/0xc8
 [<00005062>] req_need_defer+0x2a/0x3a
 [<0000a4ca>] syscall+0x8/0xc
----------------------------------------------------------------

My GCC is 12.2 in Debian bookworm, and "/init" is shell script run with static Debian Busybox, to mount virtual file systems:
https://github.com/hatari/hatari/blob/main/tools/linux/init.sh

On an small system image built and used as documented here:
https://github.com/hatari/hatari/blob/main/doc/m68k-linux.txt

#15 lore raw

Hi Eero,

Quoted 24 lines · Eero Tamminen
Quoted 9 lines · Geert Uytterhoeven
Quoted 5 lines · Eero Tamminen
Quoted 2 lines · Geert Uytterhoeven

I do keep it up-to-date locally, so I could provide these changes, if you are interested.

Yes, please! (see below)

Sorry for taking so long:
https://web.git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git/log/?h=atari-drm-wip-rebasing

Thanks!

I did boot testing on Hatari emulator with a minimal kernel config having atari_drm enabled, atafb disabled, FB & boot logo enabled.

Under Falcon emulation:
- RGB/VGA => works fine
- Mono monitor => panic
"Kernel panic - not syncing: can't set default video mode"
Under TT emulation:
- RGB/VGA => boots, but console is black[1] (palette issue?)
- Mono monitor => looks OKish[2], but has constant warnings:
-----------------------------------

Quoted 3 lines
WARNING: CPU: 0 PID: 1 at drivers/gpu/drm/drm_atomic_helper.c:1720
drm_atomic_helper_wait_for_vblanks+0x1a0/0x1ee

[CRTC:35:crtc-0] vblank wait timed out

I am not sure this is a bug in atari-drm, or just an issue when using DRM on slow machines.

Quoted 8 lines

-----------------------------------

Under 030 ST/STe emulation:
- RGB/VGA => boots, but console is black (palette issue?)
- Mono monitor => looks OK, but has constant slowpath warnings with:
"[CRTC:35:crtc-0] vblank wait timed out"

=> Any advice on the issues?

Are these regression in atari-drm, or do they happen with atafb, too?

Quoted 20 lines

PS. I also profiled where most of time goes from "atari-drm" probing, until boot reaches user space. On a minimal -Os built kernel, running on (emulated) 32Mhz 030 Falcon, in the default 640x480@4 resolution:
----------------------------------------------------------------
Time spent in profile = 15.29712s.
...
Used cycles:

   22.37%  22.42%  25.35%   _transp
   19.15%  19.19%  46.82%   atari_drm_fb_blit_rect.isra.0
    8.09%   8.09%  13.80%   sys_copyarea
    3.94%   3.95%   6.23%   sys_imageblit
    3.69%   3.69%   3.69%   fb_copy_offset.isra.0
    2.12%   2.13%   2.41%   atari_scsi_falcon_reg_read
    2.03%   2.03%   2.03%   fb_address_forward
    1.85%   1.85%  17.98%   fbcon_redraw_blit.constprop.0
    1.81%   1.81%   2.04%   atari_keyb_init
    1.78%   1.78%   1.98%   fb_reverse_long
    1.58%   1.58%   1.90%   arch_cpu_idle
    1.05%                   memcpy
    0.95%                   memset
Quoted 4 lines

...
----------------------------------------------------------------

=> atari-drm blitting takes half the time during boot.

Yeah, conversion from chunky to planar is expensive. Would be great to have a text console that operates directly on the buffer used by the hardware...

Quoted 25 lines

Building kernel with -O2, changes above rather radically, both time-wise, and where that time goes:
----------------------------------------------------------------
Time spent in profile = 6.54049s.
...
Used cycles:

   17.61%  17.61%  17.61%   sys_copyarea
   11.18%  11.18%  13.11%   arch_cpu_idle
    7.53%   7.55%   8.45%   atari_drm_fb_blit_rect.isra.0
    4.26%   4.27%   4.76%   atari_keyb_init
    2.70%   2.70%   2.93%   atari_scsi_falcon_reg_read
    2.45%   2.45%  23.81%   fbcon_redraw_blit.constprop.0
    2.35%   2.35%   2.48%   sys_imageblit
    2.12%   2.12%   5.89%   atari_floppy_init
    1.97%                   memset
    1.31%                   memcpy
...
Instruction cache misses:
   27.14%  27.14%  27.14%   sys_copyarea
    3.77%   3.77%   4.05%   atari_scsi_falcon_reg_read
...
Data cache hits:
   63.55%  63.55%  63.67%   atari_keyb_init
    7.61%   7.62%   7.84%   atari_drm_fb_blit_rect.isra.0
    3.86%   3.86%   3.86%   sys_copyarea <= not much hits for copying
Quoted 2 lines

...
----------------------------------------------------------------

So it would be worthwhile to factor out the code that is most performance-critical into its own file, and use CFLAGS_foo.o += -O2 (or even -O3? or other options?) in the Makefile to build it with a better optimization level.

Quoted 7 lines

However, -O2 build has the downside that the resulting kernel Oopses once it reaches user-space, if 030 data cache emulation is enabled:
----------------------------------------------------------------
Run /init as init process
...
Instruction fault at 0x0041a256
BAD KERNEL BUSERR

Interesting...

Thanks a lot for testing, and for your analysis!

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#16 lore raw

Hi Geert,

Quoted 17 lines · Geert Uytterhoeven
Quoted 8 lines · Eero Tamminen

I did boot testing on Hatari emulator with a minimal kernel config having atari_drm enabled, atafb disabled, FB & boot logo enabled.

Under Falcon emulation:
- RGB/VGA => works fine
- Mono monitor => panic
"Kernel panic - not syncing: can't set default video mode"

Quoted 7 lines

Under TT emulation:
- RGB/VGA => boots, but console is black[1] (palette issue?)
- Mono monitor => looks OKish[2], but has constant warnings:
-----------------------------------

WARNING: CPU: 0 PID: 1 at drivers/gpu/drm/drm_atomic_helper.c:1720
drm_atomic_helper_wait_for_vblanks+0x1a0/0x1ee

[CRTC:35:crtc-0] vblank wait timed out

Quoted 2 lines

I am not sure this is a bug in atari-drm, or just an issue when using DRM on slow machines.

This does not trigger with -Os built "atafb" kernel, but happens even with -O2 built "atari-drm" kernel. Something related to the higher (71) HZ of the mono monitors?

(I don't think it relates to TT mono monitor's larger 1280x960 resolution, because it happens also with ST mono monitor 640x400 one.)

Btw. both kernels include:

$ grep ^CONFIG.*WATCH .config
CONFIG_WATCHDOG=y
CONFIG_WATCHDOG_CORE=y
CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED=y
CONFIG_WATCHDOG_OPEN_TIMEOUT=0
CONFIG_SOFT_WATCHDOG=y
CONFIG_WQ_WATCHDOG=y
Quoted 10 lines
Quoted 8 lines

-----------------------------------

Under 030 ST/STe emulation:
- RGB/VGA => boots, but console is black (palette issue?)
- Mono monitor => looks OK, but has constant slowpath warnings with:
"[CRTC:35:crtc-0] vblank wait timed out"

=> Any advice on the issues?

Are these regression in atari-drm, or do they happen with atafb, too?

Only the "can't set default video" issue in Falcon mono mode happens also with "atafb".

It has neither the above vblank timeout issue in mono mode, nor black-on-black color issue in color mode (on TT and 030 ST).

...

Quoted 9 lines
Quoted 7 lines

However, -O2 build has the downside that the resulting kernel Oopses once it reaches user-space, if 030 data cache emulation is enabled:
----------------------------------------------------------------
Run /init as init process
...
Instruction fault at 0x0041a256
BAD KERNEL BUSERR

Interesting...

There were some extra config differences between my builds for 6.15 "atafb" and your "atari-drm-wip-rebasing" branch.

After removing the ones I could:
--------------------------------

$ diff -ub .config.old .config | grep '^[-+]C'
-CONFIG_I2C_HELPER_AUTO=y
-CONFIG_LOGO=y
-CONFIG_LOGO_LINUX_MONO=y
-CONFIG_LOGO_LINUX_VGA16=y
-------------------------------

Bus error issue went away.

=> Could there be some issue with how logo and "atari-drm" code interact, which could manifest when reaching user-space?

Note: I haven't tried enabling logo with "atafb" + -O2 build. I could try that later on.

- Eero

#17 lore raw

Hi,

Quoted 12 lines · Eero Tamminen

On 28.5.2025 11.57, Geert Uytterhoeven wrote:
There were some extra config differences between my builds for 6.15 "atafb" and your "atari-drm-wip-rebasing" branch.

After removing the ones I could:
--------------------------------

$ diff -ub .config.old .config | grep '^[-+]C'
(quoted diff) +0 -5
-CONFIG_I2C_HELPER_AUTO=y
-CONFIG_LOGO=y
-CONFIG_LOGO_LINUX_MONO=y
-CONFIG_LOGO_LINUX_VGA16=y
-------------------------------
Quoted 5 lines

Bus error issue went away.

=> Could there be some issue with how logo and "atari-drm" code interact, which could manifest when reaching user-space?

Note: I haven't tried enabling logo with "atafb" + -O2 build. I could try that later on.

Tried that now. Enabling logo config options for "atafb" kernel did not cause bus error with -O2. It did not show logo though, the area where the logo was shown with "atari-drm", was just black.

=> No conclusive result on whether logo triggers the bus error.

As to boot time with minimal kernel booting on (emulated) 32Mhz Falcon, according to /proc/uptime...

"-Os" kernel build:
- atafb: 11.87s
- atari-drm: 21.04s

=> Nearly 80% slower.

"-O2" kernel build:
- atafb: 10.35s
- atari-drm: 11.42s

=> Only 10% slower.

I.e. difference in -Os / -O2 boot time is clearly due to "atari-drm" driver.

- Eero

#18 lore raw
In reply to Eero Tamminen

Hi Eero,

Quoted 21 lines · Eero Tamminen
Quoted 17 lines · Geert Uytterhoeven
Quoted 8 lines · Eero Tamminen

I did boot testing on Hatari emulator with a minimal kernel config having atari_drm enabled, atafb disabled, FB & boot logo enabled.

Under Falcon emulation:
- RGB/VGA => works fine
- Mono monitor => panic
"Kernel panic - not syncing: can't set default video mode"

Quoted 7 lines

Under TT emulation:
- RGB/VGA => boots, but console is black[1] (palette issue?)
- Mono monitor => looks OKish[2], but has constant warnings:
-----------------------------------

WARNING: CPU: 0 PID: 1 at drivers/gpu/drm/drm_atomic_helper.c:1720
drm_atomic_helper_wait_for_vblanks+0x1a0/0x1ee

[CRTC:35:crtc-0] vblank wait timed out

Quoted 2 lines

I am not sure this is a bug in atari-drm, or just an issue when using DRM on slow machines.

Quoted 6 lines

This does not trigger with -Os built "atafb" kernel, but happens even with -O2 built "atari-drm" kernel. Something related to the higher (71) HZ of the mono monitors?

(I don't think it relates to TT mono monitor's larger 1280x960 resolution, because it happens also with ST mono monitor 640x400 one.)

DRM vblank handling is part of DRM, so it is not applicable to atafb.

Quoted 7 lines
Quoted 1 line

Are these regression in atari-drm, or do they happen with atafb, too?

Only the "can't set default video" issue in Falcon mono mode happens also with "atafb".

It has neither the above vblank timeout issue in mono mode, nor black-on-black color issue in color mode (on TT and 030 ST).

Unless I made a mistake, color handling should be the same for atari-drm and atafb. Unfortunately I am no Atari hardware expert.

Quoted 22 lines
Quoted 9 lines
Quoted 7 lines

However, -O2 build has the downside that the resulting kernel Oopses once it reaches user-space, if 030 data cache emulation is enabled:
----------------------------------------------------------------
Run /init as init process
...
Instruction fault at 0x0041a256
BAD KERNEL BUSERR

Interesting...

There were some extra config differences between my builds for 6.15 "atafb" and your "atari-drm-wip-rebasing" branch.

After removing the ones I could:
--------------------------------

$ diff -ub .config.old .config | grep '^[-+]C'
(quoted diff) +0 -5
-CONFIG_I2C_HELPER_AUTO=y
-CONFIG_LOGO=y
-CONFIG_LOGO_LINUX_MONO=y
-CONFIG_LOGO_LINUX_VGA16=y
-------------------------------
Quoted 7 lines

Bus error issue went away.

=> Could there be some issue with how logo and "atari-drm" code interact, which could manifest when reaching user-space?

Note: I haven't tried enabling logo with "atafb" + -O2 build. I could try that later on.

Logo shouldn't matter.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds