Skip to contentSkip to conversation

GUD USB Display driver

PATCH In review Noralf Trønnes 3 participants 8 messages Mar 13, 2021 – Mar 19, 2021

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

v8 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:
- Forgot to filter RGB111 from reaching userspace
- Handle a device that only returns unknown device properties (Peter)
- s/GUD_PIXEL_FORMAT_RGB111/GUD_PIXEL_FORMAT_XRGB1111/ (Peter)
- Fix R1 and XRGB1111 format conversion
- Add FIXME about Big Endian being broken (Peter, Ilia)

I will apply the patches as soon as the dependency shows up in drm-misc-next.

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       | 661 +++++++++++++++++++++++++
 drivers/gpu/drm/gud/gud_internal.h  | 154 ++++++
 drivers/gpu/drm/gud/gud_pipe.c      | 552 +++++++++++++++++++++
 include/drm/gud.h                   | 333 +++++++++++++
 include/uapi/drm/drm_mode.h         |   1 +
 13 files changed, 2466 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 v8 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 v8 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 v8 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)

v8:
- Forgot to filter RGB111 from reaching userspace
- Handle a device that only returns unknown device properties (Peter)
- s/GUD_PIXEL_FORMAT_RGB111/GUD_PIXEL_FORMAT_XRGB1111/ (Peter)
- Fix R1 and XRGB1111 format conversion
- Add FIXME about Big Endian being broken (Peter, Ilia)

---
 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       | 661 +++++++++++++++++++++++++
 drivers/gpu/drm/gud/gud_internal.h  | 154 ++++++
 drivers/gpu/drm/gud/gud_pipe.c      | 552 +++++++++++++++++++++
 include/drm/gud.h                   | 333 +++++++++++++
 10 files changed, 2458 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 +661 -0

661 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 +552 -0

552 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 v8 3/3] drm: Add GUD USB Display driver

Hi Noralf,

super fair call with the BE testing, let's hope for some testing soonish.

I was thinking about my device doing protocol STALL when I try to return 0 bytes, and while it *is* a bug in my device, from a standards point of view it's actually completely valid, if not expected:

--8<-- usb_20.pdf 8.5.3.4 STALL Handshakes Returned by Control Pipes If the device is unable to complete a command, it returns a STALL in the Data and/or Status stages of the control transfer. Unlike the case of a functional stall, protocol stall does not indicate an error with the device. -->8--

I think it's fair to say that a device can't complete the command when it has no data to return.

So how about allowing STALL for optional GUD_REQ_GET_:s to mean the same as a 0 byte response? Should I propose a separate patch for it later?

Quoted 1 line · Noralf Trønnes

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

..

Quoted 1 line

+static int gud_connector_get_modes(struct drm_connector *connector)

..

drivers/gpu/drm/gud/gud_connector.c line 235

Quoted 2 lines
drivers/gpu/drm/gud/gud_connector.c new file +2 -0
+	ret = gud_usb_get(gdrm, GUD_REQ_GET_CONNECTOR_EDID, connector->index,
+			  edid_ctx.buf, GUD_CONNECTOR_MAX_EDID_LEN);

if (ret == -EPIPE)

	ret = 0;
Quoted 9 lines
drivers/gpu/drm/gud/gud_connector.c new file +7 -0
+	if (ret > 0 && ret % EDID_LENGTH) {
+		gud_conn_err(connector, "Invalid EDID size", ret);
+	} else if (ret > 0) {
+		edid_ctx.len = ret;
+		edid = drm_do_get_edid(connector, gud_connector_get_edid_block, &edid_ctx);
+	}
 
 
+static int gud_connector_add_properties(struct gud_device *gdrm, struct gud_connector *gconn)

..

drivers/gpu/drm/gud/gud_connector.c line 487

Quoted 2 lines
drivers/gpu/drm/gud/gud_connector.c new file +2 -0
+	ret = gud_usb_get(gdrm, GUD_REQ_GET_CONNECTOR_PROPERTIES, connector->index,
+			  properties, GUD_CONNECTOR_PROPERTIES_MAX_NUM * sizeof(*properties));

if (ret == -EPIPE)

	ret = 0;
Quoted 9 lines
drivers/gpu/drm/gud/gud_connector.c new file +7 -0
+	if (ret <= 0)
+		goto out;
+	if (ret % sizeof(*properties)) {
+		ret = -EIO;
+		goto out;
+	}
 
 
+++ b/drivers/gpu/drm/gud/gud_drv.c

..
..

Quoted 1 line

+static int gud_get_properties(struct gud_device *gdrm)

..

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

Quoted 2 lines
drivers/gpu/drm/gud/gud_drv.c new file +2 -0
+	ret = gud_usb_get(gdrm, GUD_REQ_GET_PROPERTIES, 0,
+			  properties, GUD_PROPERTIES_MAX_NUM * sizeof(*properties));

if (ret == -EPIPE)

	ret = 0;

drivers/gpu/drm/gud/gud_connector.c line 493

Quoted 6 lines
drivers/gpu/drm/gud/gud_connector.c new file +6 -0
+	if (ret <= 0)
+		goto out;
+	if (ret % sizeof(*properties)) {
+		ret = -EIO;
+		goto out;
+	}

Then I looked whether a device could cause trouble in the driver by returning complex/unexpected data, and found this:

Quoted 1 line

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

..

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

Quoted 2 lines
drivers/gpu/drm/gud/gud_drv.c new file +2 -0
+	/* Add room for emulated XRGB8888 */
+	formats = devm_kmalloc_array(dev, GUD_FORMATS_MAX_NUM + 1, sizeof(*formats), GFP_KERNEL);

It looks like this +1 and the way xrgb8888_emulation_format works means that an interface will not always work correctly if multiple emulated formats (R1, XRGB1111, RGB565) are returned, because only one emulated mode is added after the loop, with struct drm_format_info for the last emulated format returned by the device. So userspace would only see the last emulated mode and the bulk output would only ever use that particular pixel format, any earlier ones would be unavailable?

If this is EWONTFIX then how about adding an error message if multiple emulated modes are returned and ignore all but the first, rather than all but the last?

Related: Can userspace find out which GUD_PIXEL_FORMAT_* is behind an emulated format? It's needed to decide how the emulated framebuffer should be used, in particular to not use G or B if GUD_PIXEL_FORMAT_R1.

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

Quoted 12 lines
drivers/gpu/drm/gud/gud_drv.c new file +12 -0
+		switch (format) {
+		case GUD_DRM_FORMAT_R1:
+			fallthrough;
+		case GUD_DRM_FORMAT_XRGB1111:
+			if (!xrgb8888_emulation_format)
+				xrgb8888_emulation_format = info;
+			break;
+		case DRM_FORMAT_RGB565:
+			rgb565_supported = true;
+			if (!xrgb8888_emulation_format)
+				xrgb8888_emulation_format = info;
+			break;

Could RGB565 go before XRGB111 (or R1) and also fallthrough; in this construct? Not terribly important, but the repetition caught my eye.

Then, in gud_connector.c I saw this, which surprised me:

+int gud_connector_fill_properties(struct drm_connector_state *connector_state, ..
+ if (prop == GUD_PROPERTY_BACKLIGHT_BRIGHTNESS) {
+ val = connector_state->tv.brightness;
+ } else {

Why is this using tv.brightness rather than say gconn->initial_brightness?

It looks like the end result might be the same because tv.brightness is set to gconn->initial_brightness in gud_connector_reset() but it's a little confusing to me, since a GUD backlight isn't a drm/TV thing?

Thanks a lot

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

#5 lore raw

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

Den 15.03.2021 20.37, skrev Peter Stuge:

Quoted 15 lines

Hi Noralf,

super fair call with the BE testing, let's hope for some testing soonish.

I was thinking about my device doing protocol STALL when I try to return 0 bytes, and while it *is* a bug in my device, from a standards point of view it's actually completely valid, if not expected:

--8<-- usb_20.pdf 8.5.3.4 STALL Handshakes Returned by Control Pipes If the device is unable to complete a command, it returns a STALL in the Data and/or Status stages of the control transfer. Unlike the case of a functional stall, protocol stall does not indicate an error with the device. -->8--

Quoted 6 lines

I think it's fair to say that a device can't complete the command when it has no data to return.

So how about allowing STALL for optional GUD_REQ_GET_:s to mean the same as a 0 byte response? Should I propose a separate patch for it later?

Yeah, that would be nice.

We can't look for -EPIPE though, since GUD_REQ_GET_STATUS will ask for the actual error. We have these to choose from currently:

  #define GUD_STATUS_OK				0x00
  #define GUD_STATUS_BUSY			0x01
  #define GUD_STATUS_REQUEST_NOT_SUPPORTED	0x02
  #define GUD_STATUS_PROTOCOL_ERROR		0x03
  #define GUD_STATUS_INVALID_PARAMETER		0x04
  #define GUD_STATUS_ERROR			0x05

Maybe REQUEST_NOT_SUPPORTED (-EOPNOTSUPP) or add a more fitting status value.

If the driver sees -EPIPE this means that the device has failed to respond properly. See gud_usb_transfer().

Quoted 71 lines
Quoted 1 line · Noralf Trønnes

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

..

Quoted 1 line

+static int gud_connector_get_modes(struct drm_connector *connector)

..

drivers/gpu/drm/gud/gud_connector.c line 235

Quoted 2 lines
drivers/gpu/drm/gud/gud_connector.c new file +2 -0
+	ret = gud_usb_get(gdrm, GUD_REQ_GET_CONNECTOR_EDID, connector->index,
+			  edid_ctx.buf, GUD_CONNECTOR_MAX_EDID_LEN);

if (ret == -EPIPE)

	ret = 0;
Quoted 9 lines
drivers/gpu/drm/gud/gud_connector.c new file +7 -0
+	if (ret > 0 && ret % EDID_LENGTH) {
+		gud_conn_err(connector, "Invalid EDID size", ret);
+	} else if (ret > 0) {
+		edid_ctx.len = ret;
+		edid = drm_do_get_edid(connector, gud_connector_get_edid_block, &edid_ctx);
+	}
 
 
+static int gud_connector_add_properties(struct gud_device *gdrm, struct gud_connector *gconn)

..

drivers/gpu/drm/gud/gud_connector.c line 487

Quoted 2 lines
drivers/gpu/drm/gud/gud_connector.c new file +2 -0
+	ret = gud_usb_get(gdrm, GUD_REQ_GET_CONNECTOR_PROPERTIES, connector->index,
+			  properties, GUD_CONNECTOR_PROPERTIES_MAX_NUM * sizeof(*properties));

if (ret == -EPIPE)

	ret = 0;
Quoted 9 lines
drivers/gpu/drm/gud/gud_connector.c new file +7 -0
+	if (ret <= 0)
+		goto out;
+	if (ret % sizeof(*properties)) {
+		ret = -EIO;
+		goto out;
+	}
 
 
+++ b/drivers/gpu/drm/gud/gud_drv.c

..
..

Quoted 1 line

+static int gud_get_properties(struct gud_device *gdrm)

..

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

Quoted 2 lines
drivers/gpu/drm/gud/gud_drv.c new file +2 -0
+	ret = gud_usb_get(gdrm, GUD_REQ_GET_PROPERTIES, 0,
+			  properties, GUD_PROPERTIES_MAX_NUM * sizeof(*properties));

if (ret == -EPIPE)

	ret = 0;

drivers/gpu/drm/gud/gud_connector.c line 493

Quoted 6 lines
drivers/gpu/drm/gud/gud_connector.c new file +6 -0
+	if (ret <= 0)
+		goto out;
+	if (ret % sizeof(*properties)) {
+		ret = -EIO;
+		goto out;
+	}

Then I looked whether a device could cause trouble in the driver by returning complex/unexpected data, and found this:

Quoted 1 line

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

..

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

Quoted 2 lines
drivers/gpu/drm/gud/gud_drv.c new file +2 -0
+	/* Add room for emulated XRGB8888 */
+	formats = devm_kmalloc_array(dev, GUD_FORMATS_MAX_NUM + 1, sizeof(*formats), GFP_KERNEL);

It looks like this +1 and the way xrgb8888_emulation_format works means that an interface will not always work correctly if multiple emulated formats (R1, XRGB1111, RGB565) are returned, because only one emulated mode is added after the loop, with struct drm_format_info for the last emulated format returned by the device. So userspace would only see the last emulated mode and the bulk output would only ever use that particular pixel format, any earlier ones would be unavailable?

Quoted 4 lines

If this is EWONTFIX then how about adding an error message if multiple emulated modes are returned and ignore all but the first, rather than all but the last?

It does ignore all but the first... doesn't it?

You could make a patch if you care about this:

		case GUD_DRM_FORMAT_R1:
			fallthrough;
		case GUD_DRM_FORMAT_XRGB1111:
			if (!xrgb8888_emulation_format)
				xrgb8888_emulation_format = info;
+			else
+				dev_err(dev, "...");
			break;

It's only needed for the formats that are not exported to userspace.

Quoted 5 lines

Related: Can userspace find out which GUD_PIXEL_FORMAT_* is behind an emulated format? It's needed to decide how the emulated framebuffer should be used, in particular to not use G or B if GUD_PIXEL_FORMAT_R1.

There's no way for userspace to know that. drm_fb_xrgb8888_to_gray8() uses ITU BT.601 rgb conversion so userspace doesn't have to know which colors to use, but ofc it will need to know there's a monochrome display for it to look good.

XRGB8888 is the only format that is allowed to be emulated since some userspace only supports that one format. So we can't have a device that supports both R1 and XRGB1111.

Quoted 17 lines

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

Quoted 13 lines
drivers/gpu/drm/gud/gud_drv.c new file +12 -0
+		switch (format) {
+		case GUD_DRM_FORMAT_R1:
+			fallthrough;
+		case GUD_DRM_FORMAT_XRGB1111:
+			if (!xrgb8888_emulation_format)
+				xrgb8888_emulation_format = info;
+			break;
+		case DRM_FORMAT_RGB565:
+			rgb565_supported = true;
+			if (!xrgb8888_emulation_format)
+				xrgb8888_emulation_format = info;
+			break;

Could RGB565 go before XRGB111 (or R1) and also fallthrough; in this construct? Not terribly important, but the repetition caught my eye.

It could but I'd like to keep the increasing bits-per-pixel order.

Quoted 9 lines

Then, in gud_connector.c I saw this, which surprised me:

drivers/gpu/drm/gud/gud_connector.c new file +4 -0
+int gud_connector_fill_properties(struct drm_connector_state *connector_state,
..
+		if (prop == GUD_PROPERTY_BACKLIGHT_BRIGHTNESS) {
+			val = connector_state->tv.brightness;
+		} else {
Quoted 6 lines

Why is this using tv.brightness rather than say gconn->initial_brightness?

It looks like the end result might be the same because tv.brightness is set to gconn->initial_brightness in gud_connector_reset() but it's a little confusing to me, since a GUD backlight isn't a drm/TV thing?

I'm reusing the tv state property since that saves me from subclassing the connector state. I want to have the value in the state because that makes it less of a special case. Some time in the future DRM will have proper backlight support as a DRM property, but so far no one has been willing to invest the necessary time and effort to make it happen.

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

#6 lore raw

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

In reply to Noralf Trønnes
I love your patch! Yet something to improve:

Hi "Noralf,

I love your patch! Yet something to improve:

[auto build test ERROR on drm-intel/for-linux-next]
[also build test ERROR on tegra-drm/drm/tegra/for-next linus/master drm-exynos/exynos-drm-next v5.12-rc3] [cannot apply to drm-tip/drm-tip drm/drm-next next-20210319]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Noralf-Tr-nnes/GUD-USB-Display-driver/20210313-192802
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/744847276b3d24137418fc2f15fc99ad8bd229c6
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Noralf-Tr-nnes/GUD-USB-Display-driver/20210313-192802
        git checkout 744847276b3d24137418fc2f15fc99ad8bd229c6
        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/gud/gud_drv.c:22:10: fatal error: drm/drm_gem_atomic_helper.h: No such file or directory
      22 | #include <drm/drm_gem_atomic_helper.h>
         |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.

vim +22 drivers/gpu/drm/gud/gud_drv.c

    15	
    16	#include <drm/drm_atomic_helper.h>
    17	#include <drm/drm_damage_helper.h>
    18	#include <drm/drm_debugfs.h>
    19	#include <drm/drm_drv.h>
    20	#include <drm/drm_fb_helper.h>
    21	#include <drm/drm_fourcc.h>
  > 22	#include <drm/drm_gem_atomic_helper.h>
    23	#include <drm/drm_gem_framebuffer_helper.h>
    24	#include <drm/drm_gem_shmem_helper.h>
    25	#include <drm/drm_managed.h>
    26	#include <drm/drm_print.h>
    27	#include <drm/drm_probe_helper.h>
    28	#include <drm/drm_simple_kms_helper.h>
    29	#include <drm/gud.h>
    30	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#7 lore raw
In reply to Noralf Trønnes

Den 13.03.2021 12.25, skrev Noralf Trønnes:

Quoted 27 lines

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:
- Forgot to filter RGB111 from reaching userspace
- Handle a device that only returns unknown device properties (Peter)
- s/GUD_PIXEL_FORMAT_RGB111/GUD_PIXEL_FORMAT_XRGB1111/ (Peter)
- Fix R1 and XRGB1111 format conversion
- Add FIXME about Big Endian being broken (Peter, Ilia)

I will apply the patches as soon as the dependency shows up in drm-misc-next.

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.

Quoted 9 lines

[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

Patches are now applied to drm-misc-next.
Thanks for reviewing and testing!

Noralf.

Quoted 13 lines
 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       | 661 +++++++++++++++++++++++++
 drivers/gpu/drm/gud/gud_internal.h  | 154 ++++++
 drivers/gpu/drm/gud/gud_pipe.c      | 552 +++++++++++++++++++++
 include/drm/gud.h                   | 333 +++++++++++++
 include/uapi/drm/drm_mode.h         |   1 +
Quoted 9 lines
 13 files changed, 2466 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

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