Skip to contentSkip to conversation

GUD USB Display driver

PATCH Superseded Noralf Trønnes 3 participants 18 messages Mar 5, 2021 – Mar 12, 2021

Subsystems (4)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v7 cover GUD USB Display driver

Hi,

A while back I had the idea to turn a Raspberry Pi Zero into a $5 USB to HDMI/SDTV/DPI display adapter.

The protocol is open so people are free to make displays implementing it and use this driver, all that's needed is to add a USB vid:pid to the driver for the display.

See the wiki[1] for more information and images for the Raspberry Pi Zero/4.

Changes in this version:
- LZ4_compress_default() can return zero, check for that
- Fix memory leak in gud_pipe_check() error path (Peter)
- Improve debug and error messages (Peter)
- Don't pass length in protocol structs (Peter)
- Pass USB interface to gud_usb_control_msg() et al. (Peter)
- Improve gud_connector_fill_properties() (Peter)
- Add GUD_PIXEL_FORMAT_RGB111 (Peter)
- Remove GUD_REQ_SET_VERSION (Peter)
- Fix DRM_IOCTL_MODE_OBJ_SETPROPERTY and the rotation property
- Fix dma-buf import (Thomas)

Note: There are several changes to the protocol.

I plan to apply the patches in a week or so unless something turns out to be broken.

Dependency:
drm: Use USB controller's DMA mask when importing dmabufs[2] (currently in drm-misc-fixes but not in drm-misc-next yet, also present in drm-tip and linux-next)

Noralf.

[1] https://github.com/notro/gud/wiki
[2] https://patchwork.freedesktop.org/patch/msgid/[email protected]

Noralf Trønnes (3):
drm/uapi: Add USB connector type
drm/probe-helper: Check epoch counter in output_poll_execute()
drm: Add GUD USB Display driver

 MAINTAINERS                         |   8 +
 drivers/gpu/drm/Kconfig             |   2 +
 drivers/gpu/drm/Makefile            |   1 +
 drivers/gpu/drm/drm_connector.c     |   1 +
 drivers/gpu/drm/drm_probe_helper.c  |   7 +-
 drivers/gpu/drm/gud/Kconfig         |  14 +
 drivers/gpu/drm/gud/Makefile        |   4 +
 drivers/gpu/drm/gud/gud_connector.c | 729 ++++++++++++++++++++++++++++
 drivers/gpu/drm/gud/gud_drv.c       | 659 +++++++++++++++++++++++++
 drivers/gpu/drm/gud/gud_internal.h  | 154 ++++++
 drivers/gpu/drm/gud/gud_pipe.c      | 535 ++++++++++++++++++++
 include/drm/gud.h                   | 333 +++++++++++++
 include/uapi/drm/drm_mode.h         |   1 +
 13 files changed, 2447 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/gud/Kconfig
 create mode 100644 drivers/gpu/drm/gud/Makefile
 create mode 100644 drivers/gpu/drm/gud/gud_connector.c
 create mode 100644 drivers/gpu/drm/gud/gud_drv.c
 create mode 100644 drivers/gpu/drm/gud/gud_internal.h
 create mode 100644 drivers/gpu/drm/gud/gud_pipe.c
 create mode 100644 include/drm/gud.h
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH v7 1/3 drm/uapi: Add USB connector type

Add a connector type for USB connected display panels.

Some examples of what current userspace will name the connector:
- Weston: "UNNAMED-%d"
- Mutter: "Unknown20-%d"
- X: "Unknown20-%d"

v2:
- Update drm_connector_enum_list
- Add examples to commit message

---
 drivers/gpu/drm/drm_connector.c | 1 +
 include/uapi/drm/drm_mode.h     | 1 +
 2 files changed, 2 insertions(+)
drivers/gpu/drm/drm_connector.c +1 -0
index 717c4e7271b0..52712daed3bc 100644
@@ -94,6 +94,7 @@ static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
 	{ DRM_MODE_CONNECTOR_DPI, "DPI" },
 	{ DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
 	{ DRM_MODE_CONNECTOR_SPI, "SPI" },
+	{ DRM_MODE_CONNECTOR_USB, "USB" },
 };
 
 void drm_connector_ida_init(void)
include/uapi/drm/drm_mode.h +1 -0
index fed66a03c7ae..33024cc5d26e 100644
@@ -367,6 +367,7 @@ enum drm_mode_subconnector {
 #define DRM_MODE_CONNECTOR_DPI		17
 #define DRM_MODE_CONNECTOR_WRITEBACK	18
 #define DRM_MODE_CONNECTOR_SPI		19
+#define DRM_MODE_CONNECTOR_USB		20
 
 /**
  * struct drm_mode_get_connector - Get connector metadata.
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

PATCH v7 2/3 drm/probe-helper: Check epoch counter in output_poll_execute()

In reply to Noralf Trønnes

drm_helper_hpd_irq_event() checks the epoch counter to determine connector status change. This was introduced in
commit 5186421cbfe2 ("drm: Introduce epoch counter to drm_connector"). Do the same for output_poll_execute() so it can detect other changes beside connection status value changes.

v2:
- Add Fixes tag (Daniel)

Fixes 5186421cbfe2 ("drm: Introduce epoch counter to drm_connector")
---
 drivers/gpu/drm/drm_probe_helper.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_probe_helper.c +6 -1
index d6017726cc2a..e5432dcf6999 100644
@@ -623,6 +623,7 @@ static void output_poll_execute(struct work_struct *work)
 	struct drm_connector_list_iter conn_iter;
 	enum drm_connector_status old_status;
 	bool repoll = false, changed;
+	u64 old_epoch_counter;
 
 	if (!dev->mode_config.poll_enabled)
 		return;
@@ -659,8 +660,9 @@ static void output_poll_execute(struct work_struct *work)
 
 		repoll = true;
 
+		old_epoch_counter = connector->epoch_counter;
 		connector->status = drm_helper_probe_detect(connector, NULL, false);
-		if (old_status != connector->status) {
+		if (old_epoch_counter != connector->epoch_counter) {
 			const char *old, *new;
 
 			/*
@@ -689,6 +691,9 @@ static void output_poll_execute(struct work_struct *work)
 				      connector->base.id,
 				      connector->name,
 				      old, new);
+			DRM_DEBUG_KMS("[CONNECTOR:%d:%s] epoch counter %llu -> %llu\n",
+				      connector->base.id, connector->name,
+				      old_epoch_counter, connector->epoch_counter);
 
 			changed = true;
 		}
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

PATCH v7 3/3 drm: Add GUD USB Display driver

In reply to Noralf Trønnes

This adds a USB display driver with the intention that it can be used with future USB interfaced low end displays/adapters. The Linux gadget device driver will serve as the canonical device implementation.

The following DRM properties are supported:
- Plane rotation
- Connector TV properties

There is also support for backlight brightness exposed as a backlight device.

Display modes can be made available to the host driver either as DRM display modes or through EDID. If both are present, EDID is just passed on to userspace.

Performance is preferred over color depth, so if the device supports RGB565, DRM_CAP_DUMB_PREFERRED_DEPTH will return 16.

If the device transfer buffer can't fit an uncompressed framebuffer update, the update is split up into parts that do fit.

Optimal user experience is achieved by providing damage reports either by setting FB_DAMAGE_CLIPS on pageflips or calling DRM_IOCTL_MODE_DIRTYFB.

LZ4 compression is used if the device supports it.

The driver supports a one bit monochrome transfer format: R1. This is not implemented in the gadget driver. It is added in preparation for future monochrome e-ink displays.

The driver is MIT licensed to smooth the path for any BSD port of the driver.

v2:
- Use devm_drm_dev_alloc() and drmm_mode_config_init()
- drm_fbdev_generic_setup: Use preferred_bpp=0, 16 was a copy paste error
- The drm_backlight_helper is dropped, copy in the code
- Support protocol version backwards compatibility for device

v3:
- Use donated Openmoko USB pid
- Use direct compression from framebuffer when pitch matches, not only on full frames, so split updates can benefit
- Use __le16 in struct gud_drm_req_get_connector_status
- Set edid property when the device only provides edid
- Clear compression fields in struct gud_drm_req_set_buffer
- Fix protocol version negotiation
- Remove mode->vrefresh, it's calculated

v4:
- Drop the status req polling which was a workaround for something that turned out to be a dwc2 udc driver problem
- Add a flag for the Linux gadget to require a status request on SET operations. Other devices will only get status req on STALL errors
- Use protocol specific error codes (Peter)
- Add a flag for devices that want to receive the entire framebuffer on each flush (Lubomir)
- Retry a failed framebuffer flush
- If mode has changed wait for worker and clear pending damage before queuing up new damage, fb width/height might have changed
- Increase error counter on bulk transfer failures
- Use DRM_MODE_CONNECTOR_USB
- Handle R1 kmalloc error (Peter)
- Don't try and replicate the USB get descriptor request standard for the display descriptor (Peter)
- Make max_buffer_size optional (Peter), drop the pow2 requirement since it's not necessary anymore.
- Don't pre-alloc a control request buffer, it was only 4k
- Let gud.h describe the whole protocol explicitly and don't let DRM leak into it (Peter)
- Drop display mode .hskew and .vscan from the protocol
- Shorten names: s/GUD_DRM_/GUD_/ s/gud_drm_/gud_/ (Peter)
- Fix gud_pipe_check() connector picking when switching connector
- Drop gud_drm_driver_gem_create_object() cached is default now
- Retrieve USB device from struct drm_device.dev instead of keeping a pointer
- Honour fb->offsets[0]
- Fix mode fetching when connector status is forced
- Check EDID length reported by the device
- Use drm_do_get_edid() so userspace can overrride EDID
- Set epoch counter to signal connector status change
- gud_drm_driver can be const now

v5:
- GUD_DRM_FORMAT_R1: Use non-human ascii values (Daniel)
- Change name to: GUD USB Display (Thomas, Simon)
- Change one __u32 -> __le32 in protocol header
- Always log fb flush errors, unless the previous one failed
- Run backlight update in a worker to avoid upsetting lockdep (Daniel)
- Drop backlight_ops.get_brightness, there's no readback from the device so it doesn't really add anything.
- Set dma mask, needed by dma-buf importers

v6:
- Use obj-y in Makefile (Peter)
- Fix missing le32_to_cpu() when using GUD_DISPLAY_MAGIC (Peter)
- Set initial brightness on backlight device

v7:
- LZ4_compress_default() can return zero, check for that
- Fix memory leak in gud_pipe_check() error path (Peter)
- Improve debug and error messages (Peter)
- Don't pass length in protocol structs (Peter)
- Pass USB interface to gud_usb_control_msg() et al. (Peter)
- Improve gud_connector_fill_properties() (Peter)
- Add GUD_PIXEL_FORMAT_RGB111 (Peter)
- Remove GUD_REQ_SET_VERSION (Peter)
- Fix DRM_IOCTL_MODE_OBJ_SETPROPERTY and the rotation property
- Fix dma-buf import (Thomas)

---
 MAINTAINERS                         |   8 +
 drivers/gpu/drm/Kconfig             |   2 +
 drivers/gpu/drm/Makefile            |   1 +
 drivers/gpu/drm/gud/Kconfig         |  14 +
 drivers/gpu/drm/gud/Makefile        |   4 +
 drivers/gpu/drm/gud/gud_connector.c | 729 ++++++++++++++++++++++++++++
 drivers/gpu/drm/gud/gud_drv.c       | 659 +++++++++++++++++++++++++
 drivers/gpu/drm/gud/gud_internal.h  | 154 ++++++
 drivers/gpu/drm/gud/gud_pipe.c      | 535 ++++++++++++++++++++
 include/drm/gud.h                   | 333 +++++++++++++
 10 files changed, 2439 insertions(+)
 create mode 100644 drivers/gpu/drm/gud/Kconfig
 create mode 100644 drivers/gpu/drm/gud/Makefile
 create mode 100644 drivers/gpu/drm/gud/gud_connector.c
 create mode 100644 drivers/gpu/drm/gud/gud_drv.c
 create mode 100644 drivers/gpu/drm/gud/gud_internal.h
 create mode 100644 drivers/gpu/drm/gud/gud_pipe.c
 create mode 100644 include/drm/gud.h
MAINTAINERS +8 -0
index 00112c044608..e7f71ac55f08 100644
@@ -5525,6 +5525,14 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/display/panel/feiyang,fy07024di26a30d.yaml
 F:	drivers/gpu/drm/panel/panel-feiyang-fy07024di26a30d.c
 
+DRM DRIVER FOR GENERIC USB DISPLAY
+M:	Noralf Trønnes <[email protected]>
+S:	Maintained
+W:	https://github.com/notro/gud/wiki
+T:	git git://anongit.freedesktop.org/drm/drm-misc
+F:	drivers/gpu/drm/gud/
+F:	include/drm/gud.h
+
 DRM DRIVER FOR GRAIN MEDIA GM12U320 PROJECTORS
 M:	Hans de Goede <[email protected]>
 S:	Maintained
drivers/gpu/drm/Kconfig +2 -0
index 147d61b9674e..6d3f47933e51 100644
@@ -388,6 +388,8 @@ source "drivers/gpu/drm/tidss/Kconfig"
 
 source "drivers/gpu/drm/xlnx/Kconfig"
 
+source "drivers/gpu/drm/gud/Kconfig"
+
 # Keep legacy drivers last
 
 menuconfig DRM_LEGACY
drivers/gpu/drm/Makefile +1 -0
index 81569009f884..78dd8e12525d 100644
@@ -124,3 +124,4 @@ obj-$(CONFIG_DRM_ASPEED_GFX) += aspeed/
 obj-$(CONFIG_DRM_MCDE) += mcde/
 obj-$(CONFIG_DRM_TIDSS) += tidss/
 obj-y			+= xlnx/
+obj-y			+= gud/
drivers/gpu/drm/gud/Kconfig new file +14 -0
new file mode 100644
index 000000000000..1c8601bf4d91
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config DRM_GUD
+	tristate "GUD USB Display"
+	depends on DRM && USB
+	select LZ4_COMPRESS
+	select DRM_KMS_HELPER
+	select DRM_GEM_SHMEM_HELPER
+	select BACKLIGHT_CLASS_DEVICE
+	help
+	  This is a DRM display driver for GUD USB Displays or display
+	  adapters.
+
+	  If M is selected the module will be called gud.
drivers/gpu/drm/gud/Makefile new file +4 -0
new file mode 100644
index 000000000000..68a1c622cf33
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+
+gud-y				:= gud_drv.o gud_pipe.o gud_connector.o
+obj-$(CONFIG_DRM_GUD)		+= gud.o
drivers/gpu/drm/gud/gud_connector.c new file +729 -0

729 lines not on this page · raw message

drivers/gpu/drm/gud/gud_drv.c new file +659 -0

659 lines not on this page · raw message

drivers/gpu/drm/gud/gud_internal.h new file +154 -0

154 lines not on this page · raw message

drivers/gpu/drm/gud/gud_pipe.c new file +535 -0

535 lines not on this page · raw message

include/drm/gud.h new file +333 -0

333 lines not on this page · raw message

Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

Re: [PATCH v7 3/3] drm: Add GUD USB Display driver

Den 05.03.2021 17.31, skrev Noralf Trønnes:

Quoted 40 lines

This adds a USB display driver with the intention that it can be used with future USB interfaced low end displays/adapters. The Linux gadget device driver will serve as the canonical device implementation.

drivers/gpu/drm/gud/gud_drv.c +32 -0
 
+static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)
+{
 
+	num_formats_dev = ret;
+	for (i = 0; i < num_formats_dev; i++) {
+		const struct drm_format_info *info;
+		size_t fmt_buf_size;
+		u32 format;
+
+		format = gud_to_fourcc(formats_dev[i]);
+		if (!format) {
+			drm_dbg(drm, "Unsupported format: 0x%02x\n", formats_dev[i]);
+			continue;
+		}
+
+		if (format == GUD_DRM_FORMAT_R1)
+			info = &gud_drm_format_r1;
+		else if (format == GUD_DRM_FORMAT_RGB111)
+			info = &gud_drm_format_rgb111;
+		else
+			info = drm_format_info(format);
+
+		switch (format) {
+		case GUD_DRM_FORMAT_R1:
+			fallthrough;
+		case GUD_DRM_FORMAT_RGB111:
+			xrgb8888_emulation_format = info;
+			break;
+		case DRM_FORMAT_RGB565:
+			rgb565_supported = true;
+			if (!xrgb8888_emulation_format)
+				xrgb8888_emulation_format = info;
+			break;

drivers/gpu/drm/gud/gud_drv.c line 515

Quoted 10 lines
drivers/gpu/drm/gud/gud_drv.c +10 -0
+		case DRM_FORMAT_XRGB8888:
+			xrgb8888_supported = true;
+			break;
+		};
+
+		fmt_buf_size = drm_format_info_min_pitch(info, 0, drm->mode_config.max_width) *
+			       drm->mode_config.max_height;
+		max_buffer_size = max(max_buffer_size, fmt_buf_size);
+
+		if (format == GUD_DRM_FORMAT_R1)

This line should be:

		if (format == GUD_DRM_FORMAT_R1 || format == GUD_DRM_FORMAT_RGB111)

There's also a bug in the format conversion functions that shows up on transfers with widths that are not pixels per byte aligned. I've fixed R1, I'll look at RGB111 tomorrow.

Noralf.

drivers/gpu/drm/gud/gud_drv.c line 519

Quoted 4 lines
drivers/gpu/drm/gud/gud_drv.c +4 -0
+			continue; /* Internal not for userspace */
+
+		formats[num_formats++] = format;
+	}

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw

Re: [PATCH v7 3/3] drm: Add GUD USB Display driver

In reply to Noralf Trønnes

Hello Noralf,

I've made some progress with my test device. I'm implementing R1 first and once that works I'll test RGB111 as well. Along the way I've found a couple of things in the code:

Quoted 1 line · Noralf Trønnes

+++ b/drivers/gpu/drm/gud/gud_drv.c

..

Quoted 1 line

+static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)

..

Review

Quoted 2 lines
(quoted diff) +2 -0
+		if (format == GUD_DRM_FORMAT_R1)
+			continue; /* Internal not for userspace */

You already found RGB111 missing here.

Quoted 2 lines
drivers/gpu/drm/gud/gud_drv.c new file +2 -0
+static int gud_usb_control_msg(struct usb_interface *intf, bool in,
+			       u8 request, u16 value, void *buf, size_t len)

..

Quoted 1 line

+static int gud_usb_transfer(struct gud_device *gdrm, bool in, u8 request, u16 index,

..

drivers/gpu/drm/gud/gud_drv.c line 165

Quoted 1 line
drivers/gpu/drm/gud/gud_drv.c new file +1 -0
+	ret = gud_usb_control_msg(intf, in, request, index, buf, len);

The u16 index parameter to gud_usb_transfer() and at least also gud_usb_{get,set,get_u8,set_u8}() is eventually passed in u16 value in the call to gud_usb_control_msg(), which had me confused for a bit.

What do you think about renaming all of those parameters to wValue, to show that and where they are part of the control request? I think it would help make the protocol more clear.

Finally, an actual bug:

drivers/gpu/drm/gud/gud_drv.c line 578

Quoted 5 lines
drivers/gpu/drm/gud/gud_drv.c new file +5 -0
+	ret = gud_get_properties(gdrm);
+	if (ret) {
+		dev_err(dev, "Failed to get properties (error=%d)\n", ret);
+		return ret;
+	}

If gud_get_properties() and gud_connector_add_properties() receive and process (only!) one or more unknown properties then they return the number of bytes received from the device rather than 0.

I fixed this by setting ret = 0; before the for() loop, but maybe you want to do it another way.

I found this because I can't get my device to send 0 bytes IN when the host requests more, if I provide no data the request STALLs. This is for sure a bug in my device and I'll come back to it, but for now I added a dummy 65535 property as a workaround.

What do you think about formalizing this, adding an actual dummy property?

Or maybe adding flags to the display descriptor for "I have properties", "I have connector properties" and "I have EDID" ?

Quoted 1 line

+++ b/drivers/gpu/drm/gud/gud_pipe.c

..

Quoted 1 line

+static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb,

..

Quoted 6 lines
drivers/gpu/drm/gud/gud_pipe.c new file +6 -0
+	/*
+	 * Imported buffers are assumed to be write-combined and thus uncached
+	 * with slow reads (at least on ARM).
+	 */
+	if (format != fb->format) {
+		if (format->format == GUD_DRM_FORMAT_R1) {

drivers/gpu/drm/gud/gud_pipe.c line 167

Quoted 10 lines
drivers/gpu/drm/gud/gud_pipe.c new file +10 -0
+			len = gud_xrgb8888_to_r124(buf, format, vaddr, fb, rect);
+			if (!len) {
+				ret = -ENOMEM;
+				goto end_cpu_access;
+			}
+		} else if (format->format == DRM_FORMAT_RGB565) {
+			drm_fb_xrgb8888_to_rgb565(buf, vaddr, fb, rect, gud_is_big_endian());
+		} else {
+			len = gud_xrgb8888_to_color(buf, format, vaddr, fb, rect);
+		}

Does this section also need a RGB111 case?

Quoted 1 line

+void gud_pipe_update(struct drm_simple_display_pipe *pipe,

..

drivers/gpu/drm/gud/gud_pipe.c line 520

Quoted 2 lines
drivers/gpu/drm/gud/gud_pipe.c new file +2 -0
+	if (fb && (crtc->state->mode_changed || crtc->state->connectors_changed))
+		gud_usb_set(gdrm, GUD_REQ_SET_STATE_COMMIT, 0, NULL, 0);

You mentioned that commit must not fail; what happens/should happen if a request does fail in pipe_update()? Some reasons could be that the device was unplugged, a bad cable is glitchy or even that some device doesn't even implement STATE_COMMIT or does it incorrectly and will report back failure?

Quoted 1 line

+++ b/include/drm/gud.h

..

Quoted 1 line

+ #define GUD_STATUS_REQUEST_NOT_SUPPORTED 0x02

Maybe this can be removed? SET_VERSION has been removed so it's no longer used anywhere, and in any case devices typically signal that requests are unsupported using a protocol STALL, which comes back as -EPIPE from the USB stack.

Finally, here's the drm debug output when I connect my device:

Mar 09 14:57:19 vm kernel: usb 1-1: new full-speed USB device number 24 using uhci_hcd
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_probe] version=1 flags=0x2 compression=0x0 max_buffer_size=0
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_usb_transfer] get: request=0x40 index=0 len=32
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_usb_transfer] get: request=0x41 index=0 len=320
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_probe] Ignoring unknown property: 65535
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_usb_transfer] get: request=0x50 index=0 len=256
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_get_connectors] Connector: index=0 type=0 flags=0x0
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_usb_transfer] get: request=0x51 index=0 len=320
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_get_connectors] property: 65535 = 0(0x0)
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_get_connectors] Ignoring unknown property: 65535
Mar 09 14:57:19 vm kernel: [drm:drm_minor_register] 
Mar 09 14:57:19 vm kernel: [drm:drm_minor_register] 
Mar 09 14:57:19 vm kernel: [drm:drm_minor_register] new minor registered 0
Mar 09 14:57:19 vm kernel: [drm:drm_sysfs_connector_add] adding "USB-1" to sysfs
Mar 09 14:57:19 vm kernel: [drm:drm_sysfs_hotplug_event] generating hotplug event
Mar 09 14:57:19 vm kernel: [drm] Initialized gud 1.0.0 20200422 for 1-1:27.0 on minor 0
Mar 09 14:57:19 vm kernel: [drm:drm_client_modeset_probe] 
Mar 09 14:57:19 vm kernel: [drm:drm_mode_object_get] OBJ ID: 35 (2)
Mar 09 14:57:19 vm kernel: [drm:drm_helper_probe_single_connector_modes] [CONNECTOR:35:USB-1]
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_usb_transfer] set: request=0x53 index=0 len=0
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_usb_transfer] get: request=0x54 index=0 len=1
Mar 09 14:57:19 vm kernel: [drm:drm_helper_probe_single_connector_modes] [CONNECTOR:35:USB-1] status updated from unknown to connected
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_usb_transfer] get: request=0x56 index=0 len=2048
Mar 09 14:57:19 vm kernel: [drm:drm_sysfs_hotplug_event] generating hotplug event
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: USB-1: Invalid EDID size (ret=1)
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_usb_transfer] get: request=0x55 index=0 len=3072
Mar 09 14:57:19 vm kernel: [drm:drm_helper_probe_single_connector_modes] [CONNECTOR:35:USB-1] probed modes :
Mar 09 14:57:19 vm kernel: [drm:drm_mode_debug_printmodeline] Modeline "400x240": 104 10000 400 400 400 400 240 240 240 240 0x40 0x0
Mar 09 14:57:19 vm kernel: [drm:drm_client_modeset_probe] connector 35 enabled? yes
Mar 09 14:57:19 vm kernel: [drm:drm_client_modeset_probe] Not using firmware configuration
Mar 09 14:57:19 vm kernel: [drm:drm_client_modeset_probe] looking for cmdline mode on connector 35
Mar 09 14:57:19 vm kernel: [drm:drm_client_modeset_probe] looking for preferred mode on connector 35 0
Mar 09 14:57:19 vm kernel: [drm:drm_client_modeset_probe] found mode 400x240
Mar 09 14:57:19 vm kernel: [drm:drm_client_modeset_probe] picking CRTCs for 400x240 config
Mar 09 14:57:19 vm kernel: [drm:drm_client_modeset_probe] desired mode 400x240 set on crtc 33 (0,0)
Mar 09 14:57:19 vm kernel: [drm:drm_mode_object_get] OBJ ID: 35 (2)
Mar 09 14:57:19 vm kernel: [drm:drm_mode_object_put.part.0] OBJ ID: 35 (3)
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:__drm_fb_helper_initial_config_and_unlock] test CRTC 0 primary plane
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:drm_fb_helper_generic_probe] surface width(400), height(240) and bpp(32)
Mar 09 14:57:19 vm kernel: [drm:drm_mode_addfb2] [FB:36]
Mar 09 14:57:19 vm kernel: [drm:drm_mode_object_put.part.0] OBJ ID: 36 (2)
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm] fb0: guddrmfb frame buffer device

It looks good, I think? However, neither GUD_REQ_SET_CONTROLLER_ENABLE nor GUD_REQ_SET_DISPLAY_ENABLE is ever called, and there is no bulk output if I write to /dev/fb0.

Can you tell what's missing?

Many thanks and kind regards

//Peter
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw

Re: [PATCH v7 3/3] drm: Add GUD USB Display driver

Den 09.03.2021 15.02, skrev Peter Stuge:

Quoted 28 lines

Hello Noralf,

I've made some progress with my test device. I'm implementing R1 first and once that works I'll test RGB111 as well. Along the way I've found a couple of things in the code:

Quoted 1 line · Noralf Trønnes

+++ b/drivers/gpu/drm/gud/gud_drv.c

..

Quoted 1 line

+static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)

..

Review

Quoted 2 lines
(quoted diff) +2 -0
+		if (format == GUD_DRM_FORMAT_R1)
+			continue; /* Internal not for userspace */

You already found RGB111 missing here.

Quoted 2 lines
drivers/gpu/drm/gud/gud_drv.c new file +2 -0
+static int gud_usb_control_msg(struct usb_interface *intf, bool in,
+			       u8 request, u16 value, void *buf, size_t len)

..

Quoted 1 line

+static int gud_usb_transfer(struct gud_device *gdrm, bool in, u8 request, u16 index,

..

drivers/gpu/drm/gud/gud_drv.c line 165

Quoted 1 line
drivers/gpu/drm/gud/gud_drv.c new file +1 -0
+	ret = gud_usb_control_msg(intf, in, request, index, buf, len);

The u16 index parameter to gud_usb_transfer() and at least also gud_usb_{get,set,get_u8,set_u8}() is eventually passed in u16 value in the call to gud_usb_control_msg(), which had me confused for a bit.

Quoted 4 lines

What do you think about renaming all of those parameters to wValue, to show that and where they are part of the control request? I think it would help make the protocol more clear.

Only connector requests use this value and in that case it's the connector index. I need to get this driver applied now, and can't spend more time polishing it, so I'll just keep it as-is.

Quoted 13 lines

Finally, an actual bug:

drivers/gpu/drm/gud/gud_drv.c line 578

Quoted 5 lines
drivers/gpu/drm/gud/gud_drv.c new file +5 -0
+	ret = gud_get_properties(gdrm);
+	if (ret) {
+		dev_err(dev, "Failed to get properties (error=%d)\n", ret);
+		return ret;
+	}

If gud_get_properties() and gud_connector_add_properties() receive and process (only!) one or more unknown properties then they return the number of bytes received from the device rather than 0.

Quoted 3 lines

I fixed this by setting ret = 0; before the for() loop, but maybe you want to do it another way.

I'll do that.

Quoted 8 lines

I found this because I can't get my device to send 0 bytes IN when the host requests more, if I provide no data the request STALLs. This is for sure a bug in my device and I'll come back to it, but for now I added a dummy 65535 property as a workaround.

What do you think about formalizing this, adding an actual dummy property?

I want to avoid that. I'd rather add a descriptor flag GUD_DISPLAY_FLAG_CANT_RETURN_ZERO or something for such devices. Also this property warning is just a debug message so not a very big problem. Worse is EDID if you don't want to support that since it prints an error in that case.

Quoted 3 lines

Or maybe adding flags to the display descriptor for "I have properties", "I have connector properties" and "I have EDID" ?

Then I might as well go back to the previous version and have count in the structs won't I ;)

Quoted 15 lines
Quoted 2 lines

+++ b/drivers/gpu/drm/gud/gud_pipe.c

..

Quoted 1 line

+static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb,

..

Quoted 10 lines
drivers/gpu/drm/gud/gud_pipe.c new file +10 -0
+	/*
+	 * Imported buffers are assumed to be write-combined and thus uncached
+	 * with slow reads (at least on ARM).
+	 */
+	if (format != fb->format) {
+		if (format->format == GUD_DRM_FORMAT_R1) {
+			len = gud_xrgb8888_to_r124(buf, format, vaddr, fb, rect);
+			if (!len) {
+				ret = -ENOMEM;
+				goto end_cpu_access;
Quoted 9 lines

drivers/gpu/drm/gud/gud_pipe.c line 167

Quoted 6 lines
drivers/gpu/drm/gud/gud_pipe.c new file +6 -0
+			}
+		} else if (format->format == DRM_FORMAT_RGB565) {
+			drm_fb_xrgb8888_to_rgb565(buf, vaddr, fb, rect, gud_is_big_endian());
+		} else {
+			len = gud_xrgb8888_to_color(buf, format, vaddr, fb, rect);
+		}

Does this section also need a RGB111 case?

gud_xrgb8888_to_color() handles that, although broken in this version for partial updates. Here's the fix:
https://gist.github.com/notro/a94d381cf98b7e15fcddbc90e4af0a21

Quoted 12 lines
Quoted 2 lines

+void gud_pipe_update(struct drm_simple_display_pipe *pipe,

..

drivers/gpu/drm/gud/gud_pipe.c line 520

Quoted 2 lines
drivers/gpu/drm/gud/gud_pipe.c new file +2 -0
+	if (fb && (crtc->state->mode_changed || crtc->state->connectors_changed))
+		gud_usb_set(gdrm, GUD_REQ_SET_STATE_COMMIT, 0, NULL, 0);

You mentioned that commit must not fail; what happens/should happen if a request does fail in pipe_update()? Some reasons could be that the device was unplugged, a bad cable is glitchy or even that some device doesn't even implement STATE_COMMIT or does it incorrectly and will report back failure?

The failure is just ignored since there's nothing to be done. The error counter for the debufgs file is increased, making it somewhat visible.

I've chosen to only print probe errors, flush errors and devices returning incorrect reply lengths. I hate drivers that fill the logs with errors, but I might have gone to far on the silent side, I don't know. But one nice thing about DRM is that debug is always builtin and can be enabled.

Quoted 10 lines
Quoted 2 lines

+++ b/include/drm/gud.h

..

Quoted 1 line

+ #define GUD_STATUS_REQUEST_NOT_SUPPORTED 0x02

Maybe this can be removed? SET_VERSION has been removed so it's no longer used anywhere, and in any case devices typically signal that requests are unsupported using a protocol STALL, which comes back as -EPIPE from the USB stack.

The driver issues a GUD_REQ_GET_STATUS on -EPIPE to find out what the exact problem is. GUD_STATUS_REQUEST_NOT_SUPPORTED is returned by the device on an unsupported/unrecognised request.

Quoted 48 lines

Finally, here's the drm debug output when I connect my device:

Mar 09 14:57:19 vm kernel: usb 1-1: new full-speed USB device number 24 using uhci_hcd
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_probe] version=1 flags=0x2 compression=0x0 max_buffer_size=0
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_usb_transfer] get: request=0x40 index=0 len=32
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_usb_transfer] get: request=0x41 index=0 len=320
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_probe] Ignoring unknown property: 65535
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_usb_transfer] get: request=0x50 index=0 len=256
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_get_connectors] Connector: index=0 type=0 flags=0x0
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_usb_transfer] get: request=0x51 index=0 len=320
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_get_connectors] property: 65535 = 0(0x0)
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_get_connectors] Ignoring unknown property: 65535
Mar 09 14:57:19 vm kernel: [drm:drm_minor_register] 
Mar 09 14:57:19 vm kernel: [drm:drm_minor_register] 
Mar 09 14:57:19 vm kernel: [drm:drm_minor_register] new minor registered 0
Mar 09 14:57:19 vm kernel: [drm:drm_sysfs_connector_add] adding "USB-1" to sysfs
Mar 09 14:57:19 vm kernel: [drm:drm_sysfs_hotplug_event] generating hotplug event
Mar 09 14:57:19 vm kernel: [drm] Initialized gud 1.0.0 20200422 for 1-1:27.0 on minor 0
Mar 09 14:57:19 vm kernel: [drm:drm_client_modeset_probe] 
Mar 09 14:57:19 vm kernel: [drm:drm_mode_object_get] OBJ ID: 35 (2)
Mar 09 14:57:19 vm kernel: [drm:drm_helper_probe_single_connector_modes] [CONNECTOR:35:USB-1]
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_usb_transfer] set: request=0x53 index=0 len=0
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_usb_transfer] get: request=0x54 index=0 len=1
Mar 09 14:57:19 vm kernel: [drm:drm_helper_probe_single_connector_modes] [CONNECTOR:35:USB-1] status updated from unknown to connected
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_usb_transfer] get: request=0x56 index=0 len=2048
Mar 09 14:57:19 vm kernel: [drm:drm_sysfs_hotplug_event] generating hotplug event
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: USB-1: Invalid EDID size (ret=1)
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:gud_usb_transfer] get: request=0x55 index=0 len=3072
Mar 09 14:57:19 vm kernel: [drm:drm_helper_probe_single_connector_modes] [CONNECTOR:35:USB-1] probed modes :
Mar 09 14:57:19 vm kernel: [drm:drm_mode_debug_printmodeline] Modeline "400x240": 104 10000 400 400 400 400 240 240 240 240 0x40 0x0
Mar 09 14:57:19 vm kernel: [drm:drm_client_modeset_probe] connector 35 enabled? yes
Mar 09 14:57:19 vm kernel: [drm:drm_client_modeset_probe] Not using firmware configuration
Mar 09 14:57:19 vm kernel: [drm:drm_client_modeset_probe] looking for cmdline mode on connector 35
Mar 09 14:57:19 vm kernel: [drm:drm_client_modeset_probe] looking for preferred mode on connector 35 0
Mar 09 14:57:19 vm kernel: [drm:drm_client_modeset_probe] found mode 400x240
Mar 09 14:57:19 vm kernel: [drm:drm_client_modeset_probe] picking CRTCs for 400x240 config
Mar 09 14:57:19 vm kernel: [drm:drm_client_modeset_probe] desired mode 400x240 set on crtc 33 (0,0)
Mar 09 14:57:19 vm kernel: [drm:drm_mode_object_get] OBJ ID: 35 (2)
Mar 09 14:57:19 vm kernel: [drm:drm_mode_object_put.part.0] OBJ ID: 35 (3)
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:__drm_fb_helper_initial_config_and_unlock] test CRTC 0 primary plane
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm:drm_fb_helper_generic_probe] surface width(400), height(240) and bpp(32)
Mar 09 14:57:19 vm kernel: [drm:drm_mode_addfb2] [FB:36]
Mar 09 14:57:19 vm kernel: [drm:drm_mode_object_put.part.0] OBJ ID: 36 (2)
Mar 09 14:57:19 vm kernel: gud 1-1:27.0: [drm] fb0: guddrmfb frame buffer device
Quoted 6 lines

It looks good, I think? However, neither GUD_REQ_SET_CONTROLLER_ENABLE nor GUD_REQ_SET_DISPLAY_ENABLE is ever called, and there is no bulk output if I write to /dev/fb0.

Can you tell what's missing?

IIRC you need ioctl FBIOPUT_VSCREENINFO to enable the pipeline. You can use 'con2fbmap' to put a console on the fbdev or use 'fbi' to show an image. They will do the necessary ioctls.

I use modetest for simple testing:
https://github.com/notro/tinydrm/wiki/Development#modetest

I have made tool that employs usbmon to show what happens just outside the wire (runs on the host):
https://github.com/notro/gud/blob/master/tools/monitor.py

I haven't got a proper USB analyser, so this was second best. I was primarily looking for performance numbers, but it has been helpful in debugging problems as well. It's not perfect, GUD_DISPLAY_FLAG_FULL_UPDATE is not handled for instance.

Depending on how long it takes for the DMA mask dependency patch to show up in drm-misc-next, I will either publish a new version or apply the current and provide patches with the necessary fixes. It's tiresome to stay out-of-tree for a long time, DRM is constantly changing. And I've spent way to long on this project already. This is one of those things that would never have happened if I knew how long it would take :)

Thanks for helping me improve it, especially the protocol which is difficult to change after the fact.

Noralf.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw

Re: [PATCH v7 3/3] drm: Add GUD USB Display driver

Den 09.03.2021 19.07, skrev Noralf Trønnes:

Quoted 5 lines

Den 09.03.2021 15.02, skrev Peter Stuge:

Quoted 2 lines

Hello Noralf,

Quoted 8 lines
Quoted 4 lines

I've made some progress with my test device. I'm implementing R1 first and once that works I'll test RGB111 as well. Along the way I've found a couple of things in the code:

Depending on how long it takes for the DMA mask dependency patch to show up in drm-misc-next, I will either publish a new version or apply the current and provide patches with the necessary fixes.

In case I apply this version, are you happy enough with it that you want to give an ack or r-b?

Noralf.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by Tested-by
#8 lore raw

Re: [PATCH v7 3/3] drm: Add GUD USB Display driver

Quoted 9 lines · Noralf Trønnes
Quoted 5 lines

The u16 index parameter to gud_usb_transfer() and at least also gud_usb_{get,set,get_u8,set_u8}() is eventually passed in u16 value in the call to gud_usb_control_msg(), which had me confused for a bit.

What do you think about renaming all of those parameters to wValue,

Only connector requests use this value and in that case it's the connector index. I need to get this driver applied now, and can't spend more time polishing it, so I'll just keep it as-is.

Okay.

Quoted 3 lines
Quoted 3 lines

I found this because I can't get my device to send 0 bytes IN when the host requests more, if I provide no data the request STALLs. This is for sure a bug in my device

..

Quoted 3 lines
Quoted 1 line

What do you think about formalizing this, adding an actual dummy property?

I want to avoid that.

Ack. I too prefer not adding workarounds, this needs to be fixed in my device, but I wanted to bring it up.

Quoted 4 lines

I'd rather add a descriptor flag GUD_DISPLAY_FLAG_CANT_RETURN_ZERO or something for such devices.
Also this property warning is just a debug message so not a very big problem.

I'd rather not squat a currently-unused property that may be allocated later.

Quoted 2 lines

Worse is EDID if you don't want to support that since it prints an error in that case.

I'll fix my device. If that proves impossible I can still add EDID bytes.

Quoted 5 lines
Quoted 2 lines

Or maybe adding flags to the display descriptor for "I have properties", "I have connector properties" and "I have EDID" ?

Then I might as well go back to the previous version and have count in the structs won't I ;)

That's true. Forget the workarounds.

Quoted 3 lines

gud_xrgb8888_to_color() handles that, although broken in this version for partial updates. Here's the fix:
https://gist.github.com/notro/a94d381cf98b7e15fcddbc90e4af0a21

Thanks.

Quoted 5 lines

I've chosen to only print probe errors, flush errors and devices returning incorrect reply lengths. I hate drivers that fill the logs with errors, but I might have gone to far on the silent side, I don't know. But one nice thing about DRM is that debug is always builtin and can be enabled.

I think you've struck a good balance. The error messages I've seen were all unique and immediately led me to the right place in the driver. That's really helpful.

Quoted 1 line
Quoted 1 line

Finally, here's the drm debug output when I connect my device:

..

Quoted 9 lines
Quoted 5 lines

It looks good, I think? However, neither GUD_REQ_SET_CONTROLLER_ENABLE nor GUD_REQ_SET_DISPLAY_ENABLE is ever called, and there is no bulk output if I write to /dev/fb0.

Can you tell what's missing?

IIRC you need ioctl FBIOPUT_VSCREENINFO to enable the pipeline. You can use 'con2fbmap' to put a console on the fbdev or use 'fbi' to show an image. They will do the necessary ioctls.

Thanks for the hints! I've used fbi, but remembered writing directly to /dev/fb0 without ioctl:s. I think that must have been after the console had already been moved to the framebuffer and thus activated the pipe. I dug up a version of fbset which calls that ioctl.

Quoted 2 lines

I use modetest for simple testing:
https://github.com/notro/tinydrm/wiki/Development#modetest

Ack, libdrm just has an inconveniently long dependency tail for my test environment. But fbset + dd works.

Quoted 4 lines

I have made tool that employs usbmon to show what happens just outside the wire (runs on the host):
https://github.com/notro/gud/blob/master/tools/monitor.py
I haven't got a proper USB analyser, so this was second best.

Nice idea! I've been using usbmon as well during development, it's great. I find a hardware analyzer is only really neccessary for lowlevel problems like my no-0-bytes bug.

Quoted 3 lines

Depending on how long it takes for the DMA mask dependency patch to show up in drm-misc-next, I will either publish a new version or apply the current and provide patches with the necessary fixes.

I look forward to it landing.

Quoted 2 lines

This is one of those things that would never have happened if I knew how long it would take :)

Thanks again for working on this great idea! I'm happy that I can help.

Quoted 6 lines · Noralf Trønnes
Quoted 3 lines

Depending on how long it takes for the DMA mask dependency patch to show up in drm-misc-next, I will either publish a new version or apply the current and provide patches with the necessary fixes.

In case I apply this version, are you happy enough with it that you want to give an ack or r-b?

I've now tested R1 and RGB111 and I think I've found two more things:

I didn't receive the expected bits/bytes for RGB111 on the bulk endpoint, I think because of how components were extracted in gud_xrgb8888_to_color().

Changing to the following gets me the expected (X R1 G1 B1 X R2 G2 B2) bytes:

			r = (*pix32 >> 8) & 0xff;
			g = (*pix32 >> 16) & 0xff;
			b = (*pix32++ >> 24) & 0xff;

Then, gud_xrgb8888_to_color() and maybe even gud_xrgb8888_to_r124() seem to be host endian dependent, at least because of that pix32, but maybe more? I don't know whether drm guarantees "native" XRGB byte sequence in memory, then I guess the pix32 is okay? Please take a look?

Finally my very last ask: Please consider renaming GUD_PIXEL_FORMAT_RGB111 to GUD_PIXEL_FORMAT_XRGB1111?

Someone may want to add the bit fiddling to output actual RGB111 data later, then that name would be occupied, and XRGB1111 would describe the current data format more accurately.

With the two ret=0 fixes, your gist and the three things above addressed I'm happy to say:

R1 and RGB111 are: (if v8 perhaps for a separate RGB commit)

Later I think there's good potential for performance optimization. I noticed that the drm pipe flush submits the frame as 64 byte bulk transfers, which becomes slow. The USB stack can take at least 16kb if not far more and will split as needed. The split into single 64-byte bulk packets is even done by the host controller hardware if it is given the chance. Some numbers:

usbmon during drm flush of 400x240 RGB111 (48000 byte) shows 750ms from first submit to last complete:

c1b883c0 0.503674 S Bo:4:022:1 - 64 =
4f7f2900 1.254213 C Bo:4:022:1 0 64 >

A simple userspace program with one libusb_bulk_transfer() call needs just 300ms for the same data (libusb splits it into 3x16kb transfers):

$ time ./bo < test266.xrgb1111
will output 48000 bytes
real    0m0.298s
user    0m0.002s
sys     0m0.008s

$

The display is slow, but the difference is noticeable. Something for later.

Kind regards

//Peter
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#9 lore raw

Re: [PATCH v7 3/3] drm: Add GUD USB Display driver

Den 10.03.2021 05.55, skrev Peter Stuge:

Quoted 10 lines
Quoted 6 lines · Noralf Trønnes
Quoted 3 lines

Depending on how long it takes for the DMA mask dependency patch to show up in drm-misc-next, I will either publish a new version or apply the current and provide patches with the necessary fixes.

In case I apply this version, are you happy enough with it that you want to give an ack or r-b?

I've now tested R1 and RGB111 and I think I've found two more things:

Quoted 9 lines

I didn't receive the expected bits/bytes for RGB111 on the bulk endpoint, I think because of how components were extracted in gud_xrgb8888_to_color().

Changing to the following gets me the expected (X R1 G1 B1 X R2 G2 B2) bytes:

			r = (*pix32 >> 8) & 0xff;
			g = (*pix32 >> 16) & 0xff;
			b = (*pix32++ >> 24) & 0xff;

We're accessing the whole word here through pix32, no byte access, so endianess doesn't come into play. This change will flip r and b, which
gives: XRGB8888 -> XBGR1111

BGR is a common thing on controllers, are you sure yours are set to RGB and not BGR?

And the 0xff masking isn't necessary since we're assigning to a byte, right?

I haven't got a native R1G1B1 display so I have emulated and I do get the expected colors. This is the conversion function I use on the device which I think is correct:

static size_t rgb111_to_rgb565(uint16_t *dst, uint8_t *src,
uint16_t src_width, uint16_t src_height)

{
    uint8_t rgb111, val = 0;
    size_t len = 0;

    for (uint16_t y = 0; y < src_height; y++) {
        for (uint16_t x = 0; x < src_width; x++) {
            if (!(x % 2))
                val = *src++;
            rgb111 = val >> 4;
            *dst++ = ((rgb111 & 0x04) << 13) | ((rgb111 & 0x02) << 9) |
                     ((rgb111 & 0x01) << 4);
            len += sizeof(*dst);
            val <<= 4;
        }
    }

return len;
}

Quoted 10 lines

Then, gud_xrgb8888_to_color() and maybe even gud_xrgb8888_to_r124() seem to be host endian dependent, at least because of that pix32, but maybe more? I don't know whether drm guarantees "native" XRGB byte sequence in memory, then I guess the pix32 is okay? Please take a look?

Finally my very last ask: Please consider renaming GUD_PIXEL_FORMAT_RGB111 to GUD_PIXEL_FORMAT_XRGB1111?

It has crossed my mind, I'll change it.

Noralf.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#10 lore raw

Re: [PATCH v7 3/3] drm: Add GUD USB Display driver

Quoted 11 lines · Noralf Trønnes
Quoted 8 lines

I didn't receive the expected bits/bytes for RGB111 on the bulk endpoint, I think because of how components were extracted in gud_xrgb8888_to_color().

Changing to the following gets me the expected (X R1 G1 B1 X R2 G2 B2) bytes:

			r = (*pix32 >> 8) & 0xff;
			g = (*pix32 >> 16) & 0xff;
			b = (*pix32++ >> 24) & 0xff;

We're accessing the whole word here through pix32, no byte access, so endianess doesn't come into play.

Endianness matters because parts of pix32 are used.

Software only sees bytes (or larger) because addresses are byte granular, but must pay attention to the bit order when dealing with smaller values inside larger memory accesses.

Given 4 bytes of memory {0x11, 0x22, 0x33, 0x44} at address A, both LE and BE machines appear the same when accessing individual bytes, but with uint32_t *a32 = A then a32[0] is 0x44332211 on LE and 0x11223344 on BE.

Hence the question: What does DRM promise about the XRGB8888 mode?

Is it guaranteed that the first byte in memory is always unused, the second represents red, the third green and the fourth blue (endianess agnostic)? I'd expect this and I guess that it is the case, but I don't know DRM?

Or is it instead guaranteed that when accessed natively as one 32-bit value the blue component is always in the most significant byte (endianess abstracted, always LE in memory) or always in the least significant byte (endianess abstracted, always BE in memory)?
This would be annoying for userspace, but well, it's possible.

In the abstracted (latter) case pix32 would work, but could still be questioned on style, and in fact, pix32 didn't work for me, so at a minimum the byte order would be the reverse.

In the agnostic (former) case your code was correct for BE and mine for LE, but I'd then suggest using a u8 * to both work correctly everywhere and be obvious.

Quoted 1 line

This change will flip r and b, which gives: XRGB8888 -> XBGR1111

The old code was:

			r = *pix32 >> 16;
			g = *pix32 >> 8;
			b = *pix32++;

On my LE machine this set r to the third byte (G), g to the second (R) and b to the first (X), explaining the color confusion that I saw.

Quoted 2 lines

BGR is a common thing on controllers, are you sure yours are set to RGB and not BGR?

Yes; I've verified that my display takes red in MSB both in its data sheet and by writing raw bits to it on a system without the gud driver.

Quoted 1 line

And the 0xff masking isn't necessary since we're assigning to a byte, right?

Not strictly neccessary but I like to do it anyway, both to be explicit and also to ensure that the compiler will never sign extend, if types are changed or if values become treated as signed and/or larger by the compiler because the code is changed.

It's frustrating to debug such unexpected changes in behavior due to a type change or calculation change, but if you find it too defensive then go ahead and remove it, if pix32 does stay.

Quoted 6 lines

I haven't got a native R1G1B1 display so I have emulated and I do get the expected colors. This is the conversion function I use on the device which I think is correct:

static size_t rgb111_to_rgb565(uint16_t *dst, uint8_t *src,
uint16_t src_width, uint16_t src_height)

Quoted 11 lines
{
    uint8_t rgb111, val = 0;
    size_t len = 0;

    for (uint16_t y = 0; y < src_height; y++) {
        for (uint16_t x = 0; x < src_width; x++) {
            if (!(x % 2))
                val = *src++;
            rgb111 = val >> 4;
            *dst++ = ((rgb111 & 0x04) << 13) | ((rgb111 & 0x02) << 9) |
                     ((rgb111 & 0x01) << 4);

I'm afraid this isn't correct. Two wrongs end up cancelling each other out and it's not so obvious because the destination has symmetric (565) components.

If you were to convert to xrgb8888 in the same way I think you'd also see some color confusion, and in any case blue is getting lost already in gud_xrgb8888_to_color() on LE.

//Peter
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#11 lore raw

Re: [PATCH v7 3/3] drm: Add GUD USB Display driver

Den 11.03.2021 15.48, skrev Peter Stuge:

Quoted 6 lines
Quoted 5 lines · Noralf Trønnes
Quoted 5 lines

I didn't receive the expected bits/bytes for RGB111 on the bulk endpoint, I think because of how components were extracted in gud_xrgb8888_to_color().

Changing to the following gets me the expected (X R1 G1 B1 X R2 G2 B2) bytes:

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
			r = (*pix32 >> 8) & 0xff;
			g = (*pix32 >> 16) & 0xff;
			b = (*pix32++ >> 24) & 0xff;

We're accessing the whole word here through pix32, no byte access, so endianess doesn't come into play.

Endianness matters because parts of pix32 are used.

This code:

#include <stdio.h>
#include <stdint.h>

void main()

{
	volatile uint32_t endian = 0x01234567;
	uint32_t v = 0xaabbccdd;
	uint32_t *pix32 = &v;
	uint8_t r, g, b, *p;

	r = *pix32 >> 16;
	g = *pix32 >> 8;
	b = *pix32++;

	printf("xrgb8888=%08x\n", v);

	printf("32-bit access:\n");
	printf("r=%02x\n", r);
	printf("g=%02x\n", g);
	printf("b=%02x\n", b);

	printf("Byte access on %s:\n", (*((uint8_t*)(&endian))) == 0x67 ? "LE"
: "BE");
	p = (uint8_t *)&v;
	printf("r=%02x\n", p[1]);
	printf("g=%02x\n", p[2]);
	printf("b=%02x\n", p[3]);
}

prints:

xrgb8888=aabbccdd
32-bit access:
r=bb
g=cc
b=dd
Byte access on LE:
r=cc
g=bb
b=aa

Quoted 11 lines

Software only sees bytes (or larger) because addresses are byte granular, but must pay attention to the bit order when dealing with smaller values inside larger memory accesses.

Given 4 bytes of memory {0x11, 0x22, 0x33, 0x44} at address A, both LE and BE machines appear the same when accessing individual bytes, but with uint32_t *a32 = A then a32[0] is 0x44332211 on LE and 0x11223344 on BE.

Hence the question: What does DRM promise about the XRGB8888 mode?

That it's a 32-bit value. From include/uapi/drm/drm_fourcc.h:

/* 32 bpp RGB */
#define DRM_FORMAT_XRGB8888 fourcc_code('X', 'R', '2', '4') /* [31:0]
x:R:G:B 8:8:8:8 little endian */

If a raw buffer was passed from a BE to an LE machine, there would be problems because of how the value is stored, but here it's the same endianness in userspace and kernel space.

There is code in gud_prep_flush() that handles a BE host with a multibyte format:

	} else if (gud_is_big_endian() && format->cpp[0] > 1) {
		drm_fb_swab(buf, vaddr, fb, rect, !import_attach);

In this case we can't just pass on the raw buffer to the device since the protocol is LE, and thus have to swap the bytes to match up how they're stored in memory on the device.

I'm not loosing any of the colors when running modetest. This is the test image that modetest uses and it comes through just like that:
https://commons.wikimedia.org/wiki/File:SMPTE_Color_Bars.svg

Noralf.

Quoted 72 lines

Is it guaranteed that the first byte in memory is always unused, the second represents red, the third green and the fourth blue (endianess agnostic)? I'd expect this and I guess that it is the case, but I don't know DRM?

Or is it instead guaranteed that when accessed natively as one 32-bit value the blue component is always in the most significant byte (endianess abstracted, always LE in memory) or always in the least significant byte (endianess abstracted, always BE in memory)?
This would be annoying for userspace, but well, it's possible.

In the abstracted (latter) case pix32 would work, but could still be questioned on style, and in fact, pix32 didn't work for me, so at a minimum the byte order would be the reverse.

In the agnostic (former) case your code was correct for BE and mine for LE, but I'd then suggest using a u8 * to both work correctly everywhere and be obvious.

Quoted 1 line

This change will flip r and b, which gives: XRGB8888 -> XBGR1111

The old code was:

			r = *pix32 >> 16;
			g = *pix32 >> 8;
			b = *pix32++;

On my LE machine this set r to the third byte (G), g to the second (R) and b to the first (X), explaining the color confusion that I saw.

Quoted 2 lines

BGR is a common thing on controllers, are you sure yours are set to RGB and not BGR?

Yes; I've verified that my display takes red in MSB both in its data sheet and by writing raw bits to it on a system without the gud driver.

Quoted 1 line

And the 0xff masking isn't necessary since we're assigning to a byte, right?

Not strictly neccessary but I like to do it anyway, both to be explicit and also to ensure that the compiler will never sign extend, if types are changed or if values become treated as signed and/or larger by the compiler because the code is changed.

It's frustrating to debug such unexpected changes in behavior due to a type change or calculation change, but if you find it too defensive then go ahead and remove it, if pix32 does stay.

Quoted 6 lines

I haven't got a native R1G1B1 display so I have emulated and I do get the expected colors. This is the conversion function I use on the device which I think is correct:

static size_t rgb111_to_rgb565(uint16_t *dst, uint8_t *src,
uint16_t src_width, uint16_t src_height)

Quoted 11 lines
{
    uint8_t rgb111, val = 0;
    size_t len = 0;

    for (uint16_t y = 0; y < src_height; y++) {
        for (uint16_t x = 0; x < src_width; x++) {
            if (!(x % 2))
                val = *src++;
            rgb111 = val >> 4;
            *dst++ = ((rgb111 & 0x04) << 13) | ((rgb111 & 0x02) << 9) |
                     ((rgb111 & 0x01) << 4);

I'm afraid this isn't correct. Two wrongs end up cancelling each other out and it's not so obvious because the destination has symmetric (565) components.

Quoted 7 lines

If you were to convert to xrgb8888 in the same way I think you'd also see some color confusion, and in any case blue is getting lost already in gud_xrgb8888_to_color() on LE.

//Peter

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#12 lore raw

Re: [PATCH v7 3/3] drm: Add GUD USB Display driver

Quoted 3 lines · Noralf Trønnes
Quoted 1 line

Endianness matters because parts of pix32 are used.

This code:

..

Quoted 11 lines

prints:

xrgb8888=aabbccdd
32-bit access:
r=bb
g=cc
b=dd
Byte access on LE:
r=cc
g=bb
b=aa

As expected, and:

xrgb8888=aabbccdd
32-bit access:
r=bb
g=cc
b=dd
Byte access on BE:
r=bb
g=cc
b=dd

I've done similar tests in the past and did another before my last mail.

We agree about endian effects. Apologies if I came across as overbearing!

Quoted 7 lines
Quoted 1 line

Hence the question: What does DRM promise about the XRGB8888 mode?

That it's a 32-bit value. From include/uapi/drm/drm_fourcc.h:

/* 32 bpp RGB */
#define DRM_FORMAT_XRGB8888 fourcc_code('X', 'R', '2', '4') /* [31:0]
x:R:G:B 8:8:8:8 little endian */

Okay, "[31:0] x:R:G:B 8:8:8:8" can certainly mean
[31:24]=x [23:16]=R [15:8]=G [7:0]=B, which when stored "little endian" becomes B G R X in memory, for which your pix32 code is correct.

That's the reverse *memory* layout of what the name says :) but yes, the name then matches the representation seen by software. That's the "abstracted" case that I didn't expect, because I thought the name was refering to memory layout and because I was thinking about how traditional graphics adapter video memory has the R component at the lower address, at least in early linear modes.

I also didn't pay attention to the fbset output:

    rgba 8/16,8/8,8/0,0/0

With drm format describing software pixel representation and per the fbset rgba description my test file was incorrect. I've recreated it with B G R X bytes and it shows correctly with your pix32 code.

Sending data directly to the device without the gud driver uses different data, so isn't actually a fair comparison, but I didn't change the device at all now, and that still works.

Quoted 2 lines

If a raw buffer was passed from a BE to an LE machine, there would be problems because of how the value is stored,

And swab would be required on a LE machine with a graphics adapter in a mode with X R G B memory layout, or that system would just never present XRGB8888 for that adapter/mode but perhaps something called BGRX8888 instead? I see.

Quoted 1 line

but here it's the same endianness in userspace and kernel space.

Ack.

Quoted 9 lines

There is code in gud_prep_flush() that handles a BE host with a multibyte format:

	} else if (gud_is_big_endian() && format->cpp[0] > 1) {
		drm_fb_swab(buf, vaddr, fb, rect, !import_attach);

In this case we can't just pass on the raw buffer to the device since the protocol is LE, and thus have to swap the bytes to match up how they're stored in memory on the device.

Ack.

Quoted 3 lines

I'm not loosing any of the colors when running modetest. This is the test image that modetest uses and it comes through just like that:
https://commons.wikimedia.org/wiki/File:SMPTE_Color_Bars.svg

So your destination rgb565 buffer has a [15:11]=R [10:5]=G [4:0]=B pixel format, which stores as B+G G+R in memory, as opposed to R+G G+B. All right.

Thanks a lot for clearing up my misunderstanding of drm format names and my endianess concerns!

//Peter
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#13 lore raw

Re: [PATCH v7 3/3] drm: Add GUD USB Display driver

Quoted 12 lines · Peter Stuge
Quoted 7 lines
Quoted 1 line

Hence the question: What does DRM promise about the XRGB8888 mode?

That it's a 32-bit value. From include/uapi/drm/drm_fourcc.h:

/* 32 bpp RGB */
#define DRM_FORMAT_XRGB8888 fourcc_code('X', 'R', '2', '4') /* [31:0]
x:R:G:B 8:8:8:8 little endian */

Okay, "[31:0] x:R:G:B 8:8:8:8" can certainly mean
[31:24]=x [23:16]=R [15:8]=G [7:0]=B, which when stored "little endian" becomes B G R X in memory, for which your pix32 code is correct.

Quoted 6 lines

That's the reverse *memory* layout of what the name says :) but yes, the name then matches the representation seen by software. That's the "abstracted" case that I didn't expect, because I thought the name was refering to memory layout and because I was thinking about how traditional graphics adapter video memory has the R component at the lower address, at least in early linear modes.

The definition of the formats is memory layout in little endian. The definition you see is of a 32-bit packed little-endian integer, which is a fixed memory layout.

Now, if you're on an actual big-endian platform, and you want to accept big-endian-packed formats, there's a bit of unpleasantness that goes on. Basically there are two options:

1. Ignore the above definition and interpret the formats as *big-endian* layouts. This is what nouveau and radeon do. They also don't support AddFB2 (which is what allows supplying a format) -- only AddFB which just has depth (and bpp). That's fine for nouveau and radeon because the relevant userspace just uses AddFB, and knows what the drivers want, so it all works out.

2. Comply with the above definition and set dev->mode_config.quirk_addfb_prefer_host_byte_order to false. This loses you native host packing of RGB565/etc, since they're just not defined as formats. There's a DRM_FORMAT_BIG_ENDIAN bit but it's not properly supported for anything but the 8888 formats.

I'm not sure why you guys were talking about BE in the first place, but since this is a topic I've looked into (in the context of moving nouveau from 1 to 2 - but that can't happen due to the reduced format availability), figured I'd share some of the current sad state.

Cheers,

-ilia
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#14 lore raw

Re: [PATCH v7 3/3] drm: Add GUD USB Display driver

Quoted 10 lines · Ilia Mirkin
Quoted 8 lines
Quoted 2 lines

#define DRM_FORMAT_XRGB8888 fourcc_code('X', 'R', '2', '4') /* [31:0]
x:R:G:B 8:8:8:8 little endian */

Okay, "[31:0] x:R:G:B 8:8:8:8" can certainly mean
[31:24]=x [23:16]=R [15:8]=G [7:0]=B, which when stored "little endian" becomes B G R X in memory, for which your pix32 code is correct.

That's the reverse *memory* layout of what the name says :)

The definition of the formats is memory layout in little endian.

To clarify, my new (hopefully correct?) understanding is this:

XRGB8888 does *not* mean that address 0=X, 1=R, 2=G, 3=B, but that the most significant byte in a packed XRGB8888 32-bit integer is X and the least significant byte is B, and that this is the case both on LE and BE machines.

I previously thought that XRGB8888 indicated the memory byte order of components being X R G B regardless of machine endianess, but now understand XRGB to mean the MSB..LSB order of component bytes within the 32-bit integer, as seen by software, not the order of bytes in memory.

Quoted 2 lines

The definition you see is of a 32-bit packed little-endian integer, which is a fixed memory layout.

In the header definition I'm not completely sure what the "little endian" means - I guess it refers to how the 32-bit integer will be stored in memory, but it could also refer to the order of component packing within.

Noralf's code and testing and also what fbset tells me seems to support this understanding, at least on LE machines.

Quoted 3 lines

Now, if you're on an actual big-endian platform, and you want to accept big-endian-packed formats, there's a bit of unpleasantness that goes on.

In the particular case of XRGB8888 that Noralf has implemented and I've tested every pixel is translated "manually" anyway; each component byte is downconverted to a single bit, but this use case is mostly for smaller resolutions, so no too big deal.

Quoted 1 line

I'm not sure why you guys were talking about BE in the first place,

I was worried that the translation didn't consider endianess.

Noralf, looking at the 3/3 patch again now, drm_fb_swab() gets called on BE when format == fb->format, but does it also need to be called on BE they are different, or will circumstances be such that it's never neccessary then?

Thanks and sorry if I'm confusing things needlessly

//Peter
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#15 lore raw

Re: [PATCH v7 3/3] drm: Add GUD USB Display driver

Quoted 11 lines · Peter Stuge
Quoted 9 lines · Ilia Mirkin
Quoted 8 lines
Quoted 2 lines

#define DRM_FORMAT_XRGB8888 fourcc_code('X', 'R', '2', '4') /* [31:0]
x:R:G:B 8:8:8:8 little endian */

Okay, "[31:0] x:R:G:B 8:8:8:8" can certainly mean
[31:24]=x [23:16]=R [15:8]=G [7:0]=B, which when stored "little endian" becomes B G R X in memory, for which your pix32 code is correct.

That's the reverse *memory* layout of what the name says :)

Quoted 8 lines
Quoted 1 line

The definition of the formats is memory layout in little endian.

To clarify, my new (hopefully correct?) understanding is this:

XRGB8888 does *not* mean that address 0=X, 1=R, 2=G, 3=B, but that the most significant byte in a packed XRGB8888 32-bit integer is X and the least significant byte is B, and that this is the case both on LE and BE machines.

Not quite.

XRGB8888 means that the memory layout should match a 32-bit integer, stored as LE, with the low bits being B, next bits being G, etc. This translates to byte 0 = B, byte 1 = G, etc. If you're on a BE system, and you're handed a XRGB8888 buffer, it still expects that byte 0 = B, etc (except as I outlined, some drivers which are from before these formats were a thing, sort of do their own thing). Thankfully this is equivalent to BGRX8888 (big-endian packing), so you can just munge the format. Not so with e.g. RGB565 though (since the components don't fall on byte boundaries).

Quoted 4 lines

I previously thought that XRGB8888 indicated the memory byte order of components being X R G B regardless of machine endianess, but now understand XRGB to mean the MSB..LSB order of component bytes within the 32-bit integer, as seen by software, not the order of bytes in memory.

There are about 100 conventions, and they all manage to be different from each other. Packed vs array. BE vs LE. If you're *not* confused, that should be a red flag.

[...]

Quoted 3 lines
Quoted 1 line

I'm not sure why you guys were talking about BE in the first place,

I was worried that the translation didn't consider endianess.

The translation in gud_xrgb8888_to_color definitely seems suspect. There's also a gud_is_big_endian, but I'm guessing this applies to the downstream device rather than the host system. I didn't check if dev->mode_config.quirk_addfb_prefer_host_byte_order is set -- that setting dictates whether these formats are in host-byte-order (and AddFB2 is disabled, so buffers can only be specified with depth/bpp and ambiguous component orders) or in LE byte order (and userspace can use AddFB2 which gives allows precise formats for these buffers). Not 100% sure what something like Xorg's modesetting driver does, TBH. This is a very poorly-tested scenario.

-ilia
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#16 lore raw

Re: [PATCH v7 3/3] drm: Add GUD USB Display driver

Quoted 8 lines · Ilia Mirkin

XRGB8888 means that the memory layout should match a 32-bit integer, stored as LE, with the low bits being B, next bits being G, etc. This translates to byte 0 = B, byte 1 = G, etc. If you're on a BE system, and you're handed a XRGB8888 buffer, it still expects that byte 0 = B, etc (except as I outlined, some drivers which are from before these formats were a thing, sort of do their own thing). Thankfully this is equivalent to BGRX8888 (big-endian packing), so you can just munge the format.

I understand! Thanks a lot for clarifying.

It makes much more sense to me that the format indeed describes what is in memory rather than how pixels look to software.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I'm not sure why you guys were talking about BE in the first place,

I was worried that the translation didn't consider endianess.

The translation in gud_xrgb8888_to_color definitely seems suspect.

So to me this means that the gud_pipe translations from XRGB8888 to the 1-bit formats *do* have to adjust for the reversed order on BE.

Quoted 2 lines

There's also a gud_is_big_endian, but I'm guessing this applies to the downstream device rather than the host system.

gud_is_big_endian() is a static bool wrapper around defined(__BIG_ENDIAN) so yes, it applies to the host.

With memory layout being constant I again think gud_xrgb8888_to_color() needs to take further steps to work correctly also on BE hosts. (Maybe that's le32_to_cpu(*pix32), maybe drm_fb_swab(), maybe something else?)

Quoted 2 lines

I didn't check if dev->mode_config.quirk_addfb_prefer_host_byte_order is set

I can't tell if that's helpful, probably Noralf can.

Thanks a lot

//Peter
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#17 lore raw

Re: [PATCH v7 3/3] drm: Add GUD USB Display driver

Den 12.03.2021 05.32, skrev Peter Stuge:

Quoted 37 lines
Quoted 8 lines · Ilia Mirkin

XRGB8888 means that the memory layout should match a 32-bit integer, stored as LE, with the low bits being B, next bits being G, etc. This translates to byte 0 = B, byte 1 = G, etc. If you're on a BE system, and you're handed a XRGB8888 buffer, it still expects that byte 0 = B, etc (except as I outlined, some drivers which are from before these formats were a thing, sort of do their own thing). Thankfully this is equivalent to BGRX8888 (big-endian packing), so you can just munge the format.

I understand! Thanks a lot for clarifying.

It makes much more sense to me that the format indeed describes what is in memory rather than how pixels look to software.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I'm not sure why you guys were talking about BE in the first place,

I was worried that the translation didn't consider endianess.

The translation in gud_xrgb8888_to_color definitely seems suspect.

So to me this means that the gud_pipe translations from XRGB8888 to the 1-bit formats *do* have to adjust for the reversed order on BE.

Quoted 2 lines

There's also a gud_is_big_endian, but I'm guessing this applies to the downstream device rather than the host system.

gud_is_big_endian() is a static bool wrapper around defined(__BIG_ENDIAN) so yes, it applies to the host.

With memory layout being constant I again think gud_xrgb8888_to_color() needs to take further steps to work correctly also on BE hosts. (Maybe that's le32_to_cpu(*pix32), maybe drm_fb_swab(), maybe something else?)

Quoted 5 lines
Quoted 2 lines

I didn't check if dev->mode_config.quirk_addfb_prefer_host_byte_order is set

I can't tell if that's helpful, probably Noralf can.

I skimmed a discussion a while back around BE and all it's problems through the whole graphics stack and my take away was that I needed a BE machine so I could test the whole stack to make sure it works. Judging from what Ilia says I've been wrong in my assumptions so the driver is probably broken on BE (along with my SPI display drivers). I'm not going to try and fix this now, I need someone with a BE machine that can test the whole stack and make sure it actually works. Me doing more guesswork is not going to work out well I think :)

I'll add a FIXME in gud_pipe.c that BE is probably broken and link to this discussion.

It seems Gerd did some work to fix BE in the kernel:
drm: byteorder fixes
https://patchwork.freedesktop.org/series/49073/

But that seems to deal with the format value itself and not the buffer contents.

Noralf.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel