mbox series

[0/3] Propagate DP-over-Type-C hotplug events from Type-C subsys to drm-drivers

Message ID 20190225132037.31458-1-hdegoede@redhat.com (mailing list archive)
Headers show
Series Propagate DP-over-Type-C hotplug events from Type-C subsys to drm-drivers | expand

Message

Hans de Goede Feb. 25, 2019, 1:20 p.m. UTC
Hi All,

On some Cherry Trail devices, DisplayPort over Type-C is supported through
a USB-PD microcontroller (e.g. a fusb302) + a mux to switch the superspeed
datalines between USB-3 and DP (e.g. a pi3usb30532). The kernel in this
case does the PD/alt-mode negotiation itself, rather then everything being
handled in firmware.

So the kernel itself picks an alt-mode, tells the Type-C "dongle" to switch
to DP mode and sets the mux accordingly. In this setup the HPD pin is not
connected, so the i915 driver needs to respond to a software event and scan
the DP port for changes manually.

Thanks to Heikki's great work on the DisplayPort altmode support in the
typec subsys, we now correctly tell the dongle to switch to DP altmode
and we correctly set the mux and orientation switches to connect the
DP lines to the Type-C connector.

This just leaves sending an out-of-band hotplug event from the Type-C
subsystem to the i915 driver and then we've fully working DP over Type-C
on these devices.

This series implements this. The first patch adds a generic mechanism
for oob hotplug events to be send to the drm subsys, the second patch
adds support for this mechanism to the i915 driver and the third patch
makes the typec displayport_altmode driver send these events.

The commit message of the first patch explains why I've chosen to things
the way these patches do them.

Regards,

Hans

Comments

Heikki Krogerus Feb. 27, 2019, 10:55 a.m. UTC | #1
Hi Hans,

On Mon, Feb 25, 2019 at 02:20:34PM +0100, Hans de Goede wrote:
> Hi All,
> 
> On some Cherry Trail devices, DisplayPort over Type-C is supported through
> a USB-PD microcontroller (e.g. a fusb302) + a mux to switch the superspeed
> datalines between USB-3 and DP (e.g. a pi3usb30532). The kernel in this
> case does the PD/alt-mode negotiation itself, rather then everything being
> handled in firmware.
> 
> So the kernel itself picks an alt-mode, tells the Type-C "dongle" to switch
> to DP mode and sets the mux accordingly. In this setup the HPD pin is not
> connected, so the i915 driver needs to respond to a software event and scan
> the DP port for changes manually.
> 
> Thanks to Heikki's great work on the DisplayPort altmode support in the
> typec subsys, we now correctly tell the dongle to switch to DP altmode
> and we correctly set the mux and orientation switches to connect the
> DP lines to the Type-C connector.
> 
> This just leaves sending an out-of-band hotplug event from the Type-C
> subsystem to the i915 driver and then we've fully working DP over Type-C
> on these devices.
> 
> This series implements this. The first patch adds a generic mechanism
> for oob hotplug events to be send to the drm subsys, the second patch
> adds support for this mechanism to the i915 driver and the third patch
> makes the typec displayport_altmode driver send these events.
> 
> The commit message of the first patch explains why I've chosen to things
> the way these patches do them.

One thing that this series does not consider is the DP lane count
problem. The GPU drivers (i915 in this case) does not know is four,
two or one DP lanes in use.

I guess that is not a critical issue since there is a workaround (I
think) where the driver basically does trial and error, but ideally we
should be able to tell i915 also the pin assignment that was
negotiated with the partner device so it knows the DP lane count.

My original idea was that we pass that struct typec_displayport_data
as payload in the event. From the Configuration VDO the GPU drivers
can then see the negotiated DP pin assignment and determine the lane
count.


thanks,
Jani Nikula Feb. 27, 2019, 11:16 a.m. UTC | #2
On Wed, 27 Feb 2019, Heikki Krogerus <heikki.krogerus@linux.intel.com> wrote:
> One thing that this series does not consider is the DP lane count
> problem. The GPU drivers (i915 in this case) does not know is four,
> two or one DP lanes in use.

Also, orientation.

> I guess that is not a critical issue since there is a workaround (I
> think) where the driver basically does trial and error, but ideally we
> should be able to tell i915 also the pin assignment that was
> negotiated with the partner device so it knows the DP lane count.

Yeah, if the information is there, we'd like to know. With the
orientation, there's a worst case of sixth attempt of finding out
there's just one lane in a certain orientation. Couple that with link
rate selection (did it not work because too high link rate or because
the lanes are just not there?) we get pretty confused about what we
should try.

BR,
Jani.
Heikki Krogerus Feb. 27, 2019, 11:49 a.m. UTC | #3
On Wed, Feb 27, 2019 at 01:16:27PM +0200, Jani Nikula wrote:
> On Wed, 27 Feb 2019, Heikki Krogerus <heikki.krogerus@linux.intel.com> wrote:
> > One thing that this series does not consider is the DP lane count
> > problem. The GPU drivers (i915 in this case) does not know is four,
> > two or one DP lanes in use.
> 
> Also, orientation.
> 
> > I guess that is not a critical issue since there is a workaround (I
> > think) where the driver basically does trial and error, but ideally we
> > should be able to tell i915 also the pin assignment that was
> > negotiated with the partner device so it knows the DP lane count.
> 
> Yeah, if the information is there, we'd like to know. With the
> orientation, there's a worst case of sixth attempt of finding out
> there's just one lane in a certain orientation. Couple that with link
> rate selection (did it not work because too high link rate or because
> the lanes are just not there?) we get pretty confused about what we
> should try.

The orientation is also considered in the alt mode API. We have a
function for that typec_altmode_get_orientation(), but it of course
requires that the caller has a handle to the alt mode object. So
basically we would again need tight coupling between the DP connector
and USB Type-C connector.

Hans, I'm not so sure we should, or can, rule out the "tight coupling"
option after all.


thanks,
Hans de Goede Feb. 27, 2019, 3:45 p.m. UTC | #4
Hi,

On 27-02-19 12:16, Jani Nikula wrote:
> On Wed, 27 Feb 2019, Heikki Krogerus <heikki.krogerus@linux.intel.com> wrote:
>> One thing that this series does not consider is the DP lane count
>> problem. The GPU drivers (i915 in this case) does not know is four,
>> two or one DP lanes in use.
> 
> Also, orientation.

The orientation should simply be correct with Type-C over DP. The mux /
orientation-switch used will take care of (physically) swapping the
lanes if the connector is inserted upside-down.

>> I guess that is not a critical issue since there is a workaround (I
>> think) where the driver basically does trial and error, but ideally we
>> should be able to tell i915 also the pin assignment that was
>> negotiated with the partner device so it knows the DP lane count.
> 
> Yeah, if the information is there, we'd like to know.

So far machines actually using a setup where the kernel does the
USB-PD / Type-C negotiation rather then this being handled in firmware
in say the Alpine Ridge controller, are very rare.

AFAIK in the Alpine Ridge controller case, there is no communication
with the i915 driver, the only thing the Alpine Ridge controller does
which the everything done in the kernel approach does not, is that
it actually has a pin connected to the HDP pin of the displayport in
question.  But that just lets the i915 driver know about hotplug-events,
not how many lanes are used.

Currently I'm aware of only 2 x86 models which actually need the
hotplug event propagation from the Type-C subsystem to the i915 driver.
Do we really want to come up with a much more complex solution to
optimize for this corner case, while the much more common case
(Alpine Ridge controller) does not provide this info to the i915 driver?

To give some idea of the complexity, first of all we need some
mechanism to let the kernel know which drm_connector is connected
to which Type-C port. For the 2 models I know if which need this, this
info is not available and we would need to hardcode it in the kernel
based on e.g. DMI matching.

Then once we have this link, we need to start thinking about probe
ordering. Likely we need the typec framework to find the drm_connector,
since the typec-partner device is only created when there actually is
a DP capable "dongle" connected, making doing it the other way around
tricky. Then the typec-partner device needs to get a reference or some
such to make sure the drm_connector does not fgo away during the lifetime
of the typec-partner device.

I would really like to avoid this, so if we want to send more info to
the i915 driver, I suggest we create some event struct for this which
gets passed to the notifier, this could include a string to
describe the DP connector which the Type-C connector is connected to
when the mux is set to DP mode, e.g. "i915/DP-1" should be unique
or probably better, use the PCI device name, so: "0000:00:02.0/DP-1"

Then we still have a loose coupling avoiding lifetime issues, while
the receiving drm driver can check which connector the event is for
and we can then also include other info such as lane-count and orientation
in the event struct.

> With the orientation

As said, the orientation *should* be corrected by the mux switch,
it is corrected by the mux switch on the hardware I know about and
actually getting it wrong breaks the display output (we had a bug there),
so I guess that getting it wrong leads to the lines being swizzled in a way
which the i915 driver does not check for ...

Regards,

Hans
Heikki Krogerus Feb. 28, 2019, 9:15 a.m. UTC | #5
On Wed, Feb 27, 2019 at 04:45:32PM +0100, Hans de Goede wrote:
> Hi,
> 
> On 27-02-19 12:16, Jani Nikula wrote:
> > On Wed, 27 Feb 2019, Heikki Krogerus <heikki.krogerus@linux.intel.com> wrote:
> > > One thing that this series does not consider is the DP lane count
> > > problem. The GPU drivers (i915 in this case) does not know is four,
> > > two or one DP lanes in use.
> > 
> > Also, orientation.
> 
> The orientation should simply be correct with Type-C over DP. The mux /
> orientation-switch used will take care of (physically) swapping the
> lanes if the connector is inserted upside-down.
> 
> > > I guess that is not a critical issue since there is a workaround (I
> > > think) where the driver basically does trial and error, but ideally we
> > > should be able to tell i915 also the pin assignment that was
> > > negotiated with the partner device so it knows the DP lane count.
> > 
> > Yeah, if the information is there, we'd like to know.
> 
> So far machines actually using a setup where the kernel does the
> USB-PD / Type-C negotiation rather then this being handled in firmware
> in say the Alpine Ridge controller, are very rare.
> 
> AFAIK in the Alpine Ridge controller case, there is no communication
> with the i915 driver, the only thing the Alpine Ridge controller does
> which the everything done in the kernel approach does not, is that
> it actually has a pin connected to the HDP pin of the displayport in
> question.  But that just lets the i915 driver know about hotplug-events,
> not how many lanes are used.
> 
> Currently I'm aware of only 2 x86 models which actually need the
> hotplug event propagation from the Type-C subsystem to the i915 driver.
> Do we really want to come up with a much more complex solution to
> optimize for this corner case, while the much more common case
> (Alpine Ridge controller) does not provide this info to the i915 driver?

The HPD signal is often handled with a GPIO on Intel Platforms. Either
the PD controller or EC controller, after receiving the Attention
message, triggers the GPIO. On some systems though that GPIO method
could not be used, so instead a side channel communication is used:
the GFX device (so i915 driver) receives a specific custom interrupt.

Unfortunately it now appears that there may be products coming where
using the GPIO is not going to be possible, and also side channel
communication is going to be out of the question. I've started an
internal discussion inside Intel about the possibility to extend the
UCSI specification to be able to support that kind of products.

Alpine Ridge uses TI's Power Delivery controllers. The platforms that
have Alpine Ridge TBT controller(s) often expose the USB Type-C
connectors on them to the OS via UCSI, however, it appears the Alpine
Ridge actually allows direct access to the PD controllers from the OS.
That would mean we can supply the same information to the GPU drivers
that we will deliver on CHT also on every platform that uses Alpine
Ridge.

> To give some idea of the complexity, first of all we need some
> mechanism to let the kernel know which drm_connector is connected
> to which Type-C port. For the 2 models I know if which need this, this
> info is not available and we would need to hardcode it in the kernel
> based on e.g. DMI matching.

I've been thinking about this... Do we actually need to link the
correct drm_connector to the Type-C connector? Perhaps we can make
this work by just linking the GFX device to the Type-C connector.

> Then once we have this link, we need to start thinking about probe
> ordering. Likely we need the typec framework to find the drm_connector,
> since the typec-partner device is only created when there actually is
> a DP capable "dongle" connected, making doing it the other way around
> tricky. Then the typec-partner device needs to get a reference or some
> such to make sure the drm_connector does not fgo away during the lifetime
> of the typec-partner device.

No! We must not link the partner device with anything other than the
Type-C connector. We link the USB Type-C connector to the DisplayPort,
and we link the USB Type-C connector to the partner. The Type-C
connector is the proxy here.

> I would really like to avoid this, so if we want to send more info to
> the i915 driver, I suggest we create some event struct for this which
> gets passed to the notifier, this could include a string to
> describe the DP connector which the Type-C connector is connected to
> when the mux is set to DP mode, e.g. "i915/DP-1" should be unique
> or probably better, use the PCI device name, so: "0000:00:02.0/DP-1"
> 
> Then we still have a loose coupling avoiding lifetime issues, while
> the receiving drm driver can check which connector the event is for
> and we can then also include other info such as lane-count and orientation
> in the event struct.

Well, I don't think we can deny the GPU driver (in this case) the
information that we have and that is relevant to it, just because it
seems difficult to deliver that information to the right location.

I'm not sure we have checked all the options we have yet. Perhaps
there is a simpler way of doing this.


thanks,
Hans de Goede Feb. 28, 2019, 11:24 a.m. UTC | #6
Hi,

On 28-02-19 10:15, Heikki Krogerus wrote:
> On Wed, Feb 27, 2019 at 04:45:32PM +0100, Hans de Goede wrote:
>> Hi,
>>
>> On 27-02-19 12:16, Jani Nikula wrote:
>>> On Wed, 27 Feb 2019, Heikki Krogerus <heikki.krogerus@linux.intel.com> wrote:
>>>> One thing that this series does not consider is the DP lane count
>>>> problem. The GPU drivers (i915 in this case) does not know is four,
>>>> two or one DP lanes in use.
>>>
>>> Also, orientation.
>>
>> The orientation should simply be correct with Type-C over DP. The mux /
>> orientation-switch used will take care of (physically) swapping the
>> lanes if the connector is inserted upside-down.
>>
>>>> I guess that is not a critical issue since there is a workaround (I
>>>> think) where the driver basically does trial and error, but ideally we
>>>> should be able to tell i915 also the pin assignment that was
>>>> negotiated with the partner device so it knows the DP lane count.
>>>
>>> Yeah, if the information is there, we'd like to know.
>>
>> So far machines actually using a setup where the kernel does the
>> USB-PD / Type-C negotiation rather then this being handled in firmware
>> in say the Alpine Ridge controller, are very rare.
>>
>> AFAIK in the Alpine Ridge controller case, there is no communication
>> with the i915 driver, the only thing the Alpine Ridge controller does
>> which the everything done in the kernel approach does not, is that
>> it actually has a pin connected to the HDP pin of the displayport in
>> question.  But that just lets the i915 driver know about hotplug-events,
>> not how many lanes are used.
>>
>> Currently I'm aware of only 2 x86 models which actually need the
>> hotplug event propagation from the Type-C subsystem to the i915 driver.
>> Do we really want to come up with a much more complex solution to
>> optimize for this corner case, while the much more common case
>> (Alpine Ridge controller) does not provide this info to the i915 driver?
> 
> The HPD signal is often handled with a GPIO on Intel Platforms. Either
> the PD controller or EC controller, after receiving the Attention
> message, triggers the GPIO. On some systems though that GPIO method
> could not be used, so instead a side channel communication is used:
> the GFX device (so i915 driver) receives a specific custom interrupt.
> 
> Unfortunately it now appears that there may be products coming where
> using the GPIO is not going to be possible, and also side channel
> communication is going to be out of the question. I've started an
> internal discussion inside Intel about the possibility to extend the
> UCSI specification to be able to support that kind of products.
> 
> Alpine Ridge uses TI's Power Delivery controllers. The platforms that
> have Alpine Ridge TBT controller(s) often expose the USB Type-C
> connectors on them to the OS via UCSI, however, it appears the Alpine
> Ridge actually allows direct access to the PD controllers from the OS.
> That would mean we can supply the same information to the GPU drivers
> that we will deliver on CHT also on every platform that uses Alpine
> Ridge.

Ok.

>> To give some idea of the complexity, first of all we need some
>> mechanism to let the kernel know which drm_connector is connected
>> to which Type-C port. For the 2 models I know if which need this, this
>> info is not available and we would need to hardcode it in the kernel
>> based on e.g. DMI matching.
> 
> I've been thinking about this... Do we actually need to link the
> correct drm_connector to the Type-C connector? Perhaps we can make
> this work by just linking the GFX device to the Type-C connector.

What use is it to the kms driver if it gets an event there is a DP
hotplug with x lanes and orientation foo, if we are not telling it
on which DP port it is ? kms devices already have multiple DP ports
and more then one could be hooked-up to type-c connectors.

>> Then once we have this link, we need to start thinking about probe
>> ordering. Likely we need the typec framework to find the drm_connector,
>> since the typec-partner device is only created when there actually is
>> a DP capable "dongle" connected, making doing it the other way around
>> tricky. Then the typec-partner device needs to get a reference or some
>> such to make sure the drm_connector does not fgo away during the lifetime
>> of the typec-partner device.
> 
> No! We must not link the partner device with anything other than the
> Type-C connector. We link the USB Type-C connector to the DisplayPort,
> and we link the USB Type-C connector to the partner. The Type-C
> connector is the proxy here.

Maybe, but even then we still need one side of the link to have a
reference on the other, having a proxy in between does not change
anything.

>> I would really like to avoid this, so if we want to send more info to
>> the i915 driver, I suggest we create some event struct for this which
>> gets passed to the notifier, this could include a string to
>> describe the DP connector which the Type-C connector is connected to
>> when the mux is set to DP mode, e.g. "i915/DP-1" should be unique
>> or probably better, use the PCI device name, so: "0000:00:02.0/DP-1"
>>
>> Then we still have a loose coupling avoiding lifetime issues, while
>> the receiving drm driver can check which connector the event is for
>> and we can then also include other info such as lane-count and orientation
>> in the event struct.
> 
> Well, I don't think we can deny the GPU driver (in this case) the
> information that we have and that is relevant to it, just because it
> seems difficult to deliver that information to the right location.

Right, but this does not require a tight-coupling. My original
proposal can do this if we pass a data struct with an identifier
for the DP port for which the event is to the notifier. I suggest using
a string for identifier, something like: "0000:00:02.0/DP-1" this
event struct could then also contain all the info we want to pass.

> I'm not sure we have checked all the options we have yet. Perhaps
> there is a simpler way of doing this.

As a result of writing this patches I've been thinking that we really
have a need for some sort of in kernel event mechanism, think something
pub/sub ish, a bit like mqtt.

I'm thinking a global event-queue with an API like this:

struct kernel_event {
	enum kernel_event_type type;
	char source_id[32];
	char dest_id[32];
	union data {
		kernel_event_type_foo foo;
		kernel_event_type_bar bar;
	};
}

Where drivers interested in events can then specify that they
only want events of a certain type and optionally also filter
on source / dest id.

Note that setting dest_id would be optional for event generators,
since not all event generators will know this.

Looking at all the extcon and power_supply notifications we
already have going on with the Type-C PD support, all using their
own private notifier solutions, I think something generic like this,
which does not depend on one device getting some sort of reference
on another device, might in the end be better.

This would also avoid a lot of PROBE_DEFER handling in various places,
which in some cases gets rather tricky wrt ordering.

Regards,

Hans
Heikki Krogerus Feb. 28, 2019, 2:47 p.m. UTC | #7
Hi Hans,

On Thu, Feb 28, 2019 at 12:24:25PM +0100, Hans de Goede wrote:
> Hi,
> 
> On 28-02-19 10:15, Heikki Krogerus wrote:
> > On Wed, Feb 27, 2019 at 04:45:32PM +0100, Hans de Goede wrote:
> > > Hi,
> > > 
> > > On 27-02-19 12:16, Jani Nikula wrote:
> > > > On Wed, 27 Feb 2019, Heikki Krogerus <heikki.krogerus@linux.intel.com> wrote:
> > > > > One thing that this series does not consider is the DP lane count
> > > > > problem. The GPU drivers (i915 in this case) does not know is four,
> > > > > two or one DP lanes in use.
> > > > 
> > > > Also, orientation.
> > > 
> > > The orientation should simply be correct with Type-C over DP. The mux /
> > > orientation-switch used will take care of (physically) swapping the
> > > lanes if the connector is inserted upside-down.
> > > 
> > > > > I guess that is not a critical issue since there is a workaround (I
> > > > > think) where the driver basically does trial and error, but ideally we
> > > > > should be able to tell i915 also the pin assignment that was
> > > > > negotiated with the partner device so it knows the DP lane count.
> > > > 
> > > > Yeah, if the information is there, we'd like to know.
> > > 
> > > So far machines actually using a setup where the kernel does the
> > > USB-PD / Type-C negotiation rather then this being handled in firmware
> > > in say the Alpine Ridge controller, are very rare.
> > > 
> > > AFAIK in the Alpine Ridge controller case, there is no communication
> > > with the i915 driver, the only thing the Alpine Ridge controller does
> > > which the everything done in the kernel approach does not, is that
> > > it actually has a pin connected to the HDP pin of the displayport in
> > > question.  But that just lets the i915 driver know about hotplug-events,
> > > not how many lanes are used.
> > > 
> > > Currently I'm aware of only 2 x86 models which actually need the
> > > hotplug event propagation from the Type-C subsystem to the i915 driver.
> > > Do we really want to come up with a much more complex solution to
> > > optimize for this corner case, while the much more common case
> > > (Alpine Ridge controller) does not provide this info to the i915 driver?
> > 
> > The HPD signal is often handled with a GPIO on Intel Platforms. Either
> > the PD controller or EC controller, after receiving the Attention
> > message, triggers the GPIO. On some systems though that GPIO method
> > could not be used, so instead a side channel communication is used:
> > the GFX device (so i915 driver) receives a specific custom interrupt.
> > 
> > Unfortunately it now appears that there may be products coming where
> > using the GPIO is not going to be possible, and also side channel
> > communication is going to be out of the question. I've started an
> > internal discussion inside Intel about the possibility to extend the
> > UCSI specification to be able to support that kind of products.
> > 
> > Alpine Ridge uses TI's Power Delivery controllers. The platforms that
> > have Alpine Ridge TBT controller(s) often expose the USB Type-C
> > connectors on them to the OS via UCSI, however, it appears the Alpine
> > Ridge actually allows direct access to the PD controllers from the OS.
> > That would mean we can supply the same information to the GPU drivers
> > that we will deliver on CHT also on every platform that uses Alpine
> > Ridge.
> 
> Ok.
> 
> > > To give some idea of the complexity, first of all we need some
> > > mechanism to let the kernel know which drm_connector is connected
> > > to which Type-C port. For the 2 models I know if which need this, this
> > > info is not available and we would need to hardcode it in the kernel
> > > based on e.g. DMI matching.
> > 
> > I've been thinking about this... Do we actually need to link the
> > correct drm_connector to the Type-C connector? Perhaps we can make
> > this work by just linking the GFX device to the Type-C connector.
> 
> What use is it to the kms driver if it gets an event there is a DP
> hotplug with x lanes and orientation foo, if we are not telling it
> on which DP port it is ? kms devices already have multiple DP ports
> and more then one could be hooked-up to type-c connectors.

I was looking at this series. You walk trough every DP port in the
system when the DP alt mode driver broadcasts the event, but maybe
that's different. Never mind.

> > > Then once we have this link, we need to start thinking about probe
> > > ordering. Likely we need the typec framework to find the drm_connector,
> > > since the typec-partner device is only created when there actually is
> > > a DP capable "dongle" connected, making doing it the other way around
> > > tricky. Then the typec-partner device needs to get a reference or some
> > > such to make sure the drm_connector does not fgo away during the lifetime
> > > of the typec-partner device.
> > 
> > No! We must not link the partner device with anything other than the
> > Type-C connector. We link the USB Type-C connector to the DisplayPort,
> > and we link the USB Type-C connector to the partner. The Type-C
> > connector is the proxy here.
> 
> Maybe, but even then we still need one side of the link to have a
> reference on the other, having a proxy in between does not change
> anything.
> 
> > > I would really like to avoid this, so if we want to send more info to
> > > the i915 driver, I suggest we create some event struct for this which
> > > gets passed to the notifier, this could include a string to
> > > describe the DP connector which the Type-C connector is connected to
> > > when the mux is set to DP mode, e.g. "i915/DP-1" should be unique
> > > or probably better, use the PCI device name, so: "0000:00:02.0/DP-1"
> > > 
> > > Then we still have a loose coupling avoiding lifetime issues, while
> > > the receiving drm driver can check which connector the event is for
> > > and we can then also include other info such as lane-count and orientation
> > > in the event struct.
> > 
> > Well, I don't think we can deny the GPU driver (in this case) the
> > information that we have and that is relevant to it, just because it
> > seems difficult to deliver that information to the right location.
> 
> Right, but this does not require a tight-coupling. My original
> proposal can do this if we pass a data struct with an identifier
> for the DP port for which the event is to the notifier. I suggest using
> a string for identifier, something like: "0000:00:02.0/DP-1" this
> event struct could then also contain all the info we want to pass.

I do agree that we should not tie the objects (device entries)
representing these components in kernel together, but I assume that we
agree now that the connection between the two - the USB Type-C
connector and the DisplayPort - must be described somewhere, either in
firmware or build-in? So I guess we are talking implementation details
here, right?

If that is the case...

That string identifier you proposed would basically provide the
details about the connection, so if we know those details, we might as
well use "normal" ways to describe the connection and just extract
them in runtime in the function that our DP alt mode driver calls. I
think the connection has to be defined in i915 on CHT in any case.

The DP alt mode driver should definitely not need to pass anything
else to the notifier other than handle to itself (actually, handle
straight to the port device would be better) as an identifier. The
notifier function needs to be the one that determines the actual
connection using that handle. Even if the target DP is described using
a string like you propose, then that string has to come from
somewhere, most likely from a device property. The notifier function
can just as well extract it, we don't need to pass it separately.

Here's my suggestion for function prototype:

int drm_typec_dp_notification(struct device *typec_port_dev,
                              struct typec_displayport_data *data);

So that function finds the connection between typec_port_dev and the
correct DP in runtime, possibly by letting i915 (or what ever GPU
driver) to do that. Once the function is done, it decrements any ref
counts that it incremented before returning.

That struct typec_displayport_data has all the information we have -
the current pin assignment from the Configure VDO, HPD IRQ from the
last Status Update, etc. - so it needs to be passed as payload to the
notifier.

> > I'm not sure we have checked all the options we have yet. Perhaps
> > there is a simpler way of doing this.
> 
> As a result of writing this patches I've been thinking that we really
> have a need for some sort of in kernel event mechanism, think something
> pub/sub ish, a bit like mqtt.
> 
> I'm thinking a global event-queue with an API like this:
> 
> struct kernel_event {
> 	enum kernel_event_type type;
> 	char source_id[32];
> 	char dest_id[32];
> 	union data {
> 		kernel_event_type_foo foo;
> 		kernel_event_type_bar bar;
> 	};
> }
> 
> Where drivers interested in events can then specify that they
> only want events of a certain type and optionally also filter
> on source / dest id.
> 
> Note that setting dest_id would be optional for event generators,
> since not all event generators will know this.
> 
> Looking at all the extcon and power_supply notifications we
> already have going on with the Type-C PD support, all using their
> own private notifier solutions, I think something generic like this,
> which does not depend on one device getting some sort of reference
> on another device, might in the end be better.
> 
> This would also avoid a lot of PROBE_DEFER handling in various places,
> which in some cases gets rather tricky wrt ordering.

Interesting proposal. Something like that could be useful.


thanks,
Hans de Goede Feb. 28, 2019, 4:54 p.m. UTC | #8
Hi Heikki,

On 28-02-19 15:47, Heikki Krogerus wrote:
> Hi Hans,
> 
> On Thu, Feb 28, 2019 at 12:24:25PM +0100, Hans de Goede wrote:
>> Hi,
>>
>> On 28-02-19 10:15, Heikki Krogerus wrote:

<snip>

>>> I've been thinking about this... Do we actually need to link the
>>> correct drm_connector to the Type-C connector? Perhaps we can make
>>> this work by just linking the GFX device to the Type-C connector.
>>
>> What use is it to the kms driver if it gets an event there is a DP
>> hotplug with x lanes and orientation foo, if we are not telling it
>> on which DP port it is ? kms devices already have multiple DP ports
>> and more then one could be hooked-up to type-c connectors.
> 
> I was looking at this series. You walk trough every DP port in the
> system when the DP alt mode driver broadcasts the event, but maybe
> that's different. Never mind.

Right, my "simple / naive" solution simply tells the kms driver to
check all DP ports for connection state changes, similar to how
running "xrandr" under Xorg causes the kms driver to re-check the
connection status of all ports. Actually running xrandr under Xorg
after plugging in the cable, is how I did my initial DP over Type-C
testing on the GPD win.

But once we start passing extra-info, I believe the kms driver needs
to know to which connector that info belongs.

<snip>

>>> Well, I don't think we can deny the GPU driver (in this case) the
>>> information that we have and that is relevant to it, just because it
>>> seems difficult to deliver that information to the right location.
>>
>> Right, but this does not require a tight-coupling. My original
>> proposal can do this if we pass a data struct with an identifier
>> for the DP port for which the event is to the notifier. I suggest using
>> a string for identifier, something like: "0000:00:02.0/DP-1" this
>> event struct could then also contain all the info we want to pass.
> 
> I do agree that we should not tie the objects (device entries)
> representing these components in kernel together, but I assume that we
> agree now that the connection between the two - the USB Type-C
> connector and the DisplayPort - must be described somewhere, either in
> firmware or build-in? So I guess we are talking implementation details
> here, right?

Right.

> If that is the case...
> 
> That string identifier you proposed would basically provide the
> details about the connection, so if we know those details, we might as
> well use "normal" ways to describe the connection and just extract
> them in runtime in the function that our DP alt mode driver calls. I
> think the connection has to be defined in i915 on CHT in any case.

Interesting, I think the connection should be described in the fwnode
for the fusb302 device for the CHT/GPD win case. Specifically I think
this fits well as a property of the dp altmode.

> The DP alt mode driver should definitely not need to pass anything
> else to the notifier other than handle to itself (actually, handle
> straight to the port device would be better) as an identifier. The
> notifier function needs to be the one that determines the actual
> connection using that handle. Even if the target DP is described using
> a string like you propose, then that string has to come from
> somewhere, most likely from a device property. The notifier function
> can just as well extract it, we don't need to pass it separately.
> 
> Here's my suggestion for function prototype:
> 
> int drm_typec_dp_notification(struct device *typec_port_dev,
>                                struct typec_displayport_data *data);

How about instead of the port_dev we pass in the altmode object and
we have a method to get the fwnode for the altmode? Then the
drm_typec_dp_notification() function can get info from that fwnode
to implement the connection finding you describe below:

> So that function finds the connection between typec_port_dev and the
> correct DP in runtime, possibly by letting i915 (or what ever GPU
> driver) to do that. Once the function is done, it decrements any ref
> counts that it incremented before returning.
> 
> That struct typec_displayport_data has all the information we have -
> the current pin assignment from the Configure VDO, HPD IRQ from the
> last Status Update, etc. - so it needs to be passed as payload to the
> notifier.

Ack.

So I believe that this discussion ties into the discussion from the:
"[PATCH 0/2] platform/x86: intel_cht_int33fe: Start using software nodes"

Mail thread. As discussed there I agree that adding a usb_connector
child fwnode to the fwnode for the fusb302 to describe things like
sink- and source-pdos is a good idea.

Our last few mails were discussing describing supported alt-modes on
the connector by adding altmode child-nodes to the usb_connector node.

I think it is best to continue that discussion here, as the 2 discussions
tie into one another.

So my last proposal in that thread was adding the following to:

Documentation/devicetree/bindings/connector/usb-connector.txt:

"""
Optionally an "usb-c-connector" can have child nodes, describing
supported alt-modes.

Required properties for usb-c-connector altmode child-nodes:
compatible:        "usb-type-c-altmode"
svid:              integer, Standard or Vendor ID for the altmode (u16 stored in an u32) property and an u32
vdo:               integer, Vendor Data Object, VDO describing the altmode capabilies, SVID specific
"""

Since we now want to have the kernel know which DP connector belongs to
the usb_connector being in DP altmode I suggest additionally adding
the following:

"""
Optional properties for DisplayPort (svid==0xff01) altmode child-nodes.

linux,dp-connector String in the form of "device-name/connector-name" describing the
                    DisplayPort connector on the GPU which is used when the usb-c-connector
                    is in DisplayPort altmode, e.g. "0000:00:02.0/DP-1"
"""

This to me feels like it is the most logical place to store the connection info,
at least for the CHT/GPD win case.  For other cases we may very-well need something
different. Since on the CHT/GPD win case both the producer and consumer of this
property will be in kernel, I think it is best to just go with this for now.
If we then later get a different solution for other cases and that solution turns
out to be generic enough that it will also work on the GPD win we can always move
the GPD win (and pocket) over to the new solution. Just like we are moving it
over to the usb_connector fwnode now.

Regards,

Hans
Heikki Krogerus March 4, 2019, 3:17 p.m. UTC | #9
Hi Hans,

On Thu, Feb 28, 2019 at 05:54:21PM +0100, Hans de Goede wrote:
> Hi Heikki,
> 
> On 28-02-19 15:47, Heikki Krogerus wrote:
> > Hi Hans,
> > 
> > On Thu, Feb 28, 2019 at 12:24:25PM +0100, Hans de Goede wrote:
> > > Hi,
> > > 
> > > On 28-02-19 10:15, Heikki Krogerus wrote:
> 
> <snip>
> 
> > > > I've been thinking about this... Do we actually need to link the
> > > > correct drm_connector to the Type-C connector? Perhaps we can make
> > > > this work by just linking the GFX device to the Type-C connector.
> > > 
> > > What use is it to the kms driver if it gets an event there is a DP
> > > hotplug with x lanes and orientation foo, if we are not telling it
> > > on which DP port it is ? kms devices already have multiple DP ports
> > > and more then one could be hooked-up to type-c connectors.
> > 
> > I was looking at this series. You walk trough every DP port in the
> > system when the DP alt mode driver broadcasts the event, but maybe
> > that's different. Never mind.
> 
> Right, my "simple / naive" solution simply tells the kms driver to
> check all DP ports for connection state changes, similar to how
> running "xrandr" under Xorg causes the kms driver to re-check the
> connection status of all ports. Actually running xrandr under Xorg
> after plugging in the cable, is how I did my initial DP over Type-C
> testing on the GPD win.
> 
> But once we start passing extra-info, I believe the kms driver needs
> to know to which connector that info belongs.
> 
> <snip>
> 
> > > > Well, I don't think we can deny the GPU driver (in this case) the
> > > > information that we have and that is relevant to it, just because it
> > > > seems difficult to deliver that information to the right location.
> > > 
> > > Right, but this does not require a tight-coupling. My original
> > > proposal can do this if we pass a data struct with an identifier
> > > for the DP port for which the event is to the notifier. I suggest using
> > > a string for identifier, something like: "0000:00:02.0/DP-1" this
> > > event struct could then also contain all the info we want to pass.
> > 
> > I do agree that we should not tie the objects (device entries)
> > representing these components in kernel together, but I assume that we
> > agree now that the connection between the two - the USB Type-C
> > connector and the DisplayPort - must be described somewhere, either in
> > firmware or build-in? So I guess we are talking implementation details
> > here, right?
> 
> Right.
> 
> > If that is the case...
> > 
> > That string identifier you proposed would basically provide the
> > details about the connection, so if we know those details, we might as
> > well use "normal" ways to describe the connection and just extract
> > them in runtime in the function that our DP alt mode driver calls. I
> > think the connection has to be defined in i915 on CHT in any case.
> 
> Interesting, I think the connection should be described in the fwnode
> for the fusb302 device for the CHT/GPD win case. Specifically I think
> this fits well as a property of the dp altmode.

OK, you are correct. I was stupidly still thinking about the driver
loading order, but the order does not matter.

> > The DP alt mode driver should definitely not need to pass anything
> > else to the notifier other than handle to itself (actually, handle
> > straight to the port device would be better) as an identifier. The
> > notifier function needs to be the one that determines the actual
> > connection using that handle. Even if the target DP is described using
> > a string like you propose, then that string has to come from
> > somewhere, most likely from a device property. The notifier function
> > can just as well extract it, we don't need to pass it separately.
> > 
> > Here's my suggestion for function prototype:
> > 
> > int drm_typec_dp_notification(struct device *typec_port_dev,
> >                                struct typec_displayport_data *data);
> 
> How about instead of the port_dev we pass in the altmode object and
> we have a method to get the fwnode for the altmode? Then the
> drm_typec_dp_notification() function can get info from that fwnode
> to implement the connection finding you describe below:

We can pass the altmode object, np, but let's not decide which fwnode
we'll ultimately use. I'm still leaning towards the connector node.

> > So that function finds the connection between typec_port_dev and the
> > correct DP in runtime, possibly by letting i915 (or what ever GPU
> > driver) to do that. Once the function is done, it decrements any ref
> > counts that it incremented before returning.
> > 
> > That struct typec_displayport_data has all the information we have -
> > the current pin assignment from the Configure VDO, HPD IRQ from the
> > last Status Update, etc. - so it needs to be passed as payload to the
> > notifier.
> 
> Ack.
> 
> So I believe that this discussion ties into the discussion from the:
> "[PATCH 0/2] platform/x86: intel_cht_int33fe: Start using software nodes"
> 
> Mail thread. As discussed there I agree that adding a usb_connector
> child fwnode to the fwnode for the fusb302 to describe things like
> sink- and source-pdos is a good idea.
> 
> Our last few mails were discussing describing supported alt-modes on
> the connector by adding altmode child-nodes to the usb_connector node.
> 
> I think it is best to continue that discussion here, as the 2 discussions
> tie into one another.
> 
> So my last proposal in that thread was adding the following to:
> 
> Documentation/devicetree/bindings/connector/usb-connector.txt:
> 
> """
> Optionally an "usb-c-connector" can have child nodes, describing
> supported alt-modes.
> 
> Required properties for usb-c-connector altmode child-nodes:
> compatible:        "usb-type-c-altmode"
> svid:              integer, Standard or Vendor ID for the altmode (u16 stored in an u32) property and an u32
> vdo:               integer, Vendor Data Object, VDO describing the altmode capabilies, SVID specific
> """
> 
> Since we now want to have the kernel know which DP connector belongs to
> the usb_connector being in DP altmode I suggest additionally adding
> the following:
> 
> """
> Optional properties for DisplayPort (svid==0xff01) altmode child-nodes.
> 
> linux,dp-connector String in the form of "device-name/connector-name" describing the
>                    DisplayPort connector on the GPU which is used when the usb-c-connector
>                    is in DisplayPort altmode, e.g. "0000:00:02.0/DP-1"
> """
> 
> This to me feels like it is the most logical place to store the connection info,
> at least for the CHT/GPD win case.  For other cases we may very-well need something
> different. Since on the CHT/GPD win case both the producer and consumer of this
> property will be in kernel, I think it is best to just go with this for now.
> If we then later get a different solution for other cases and that solution turns
> out to be generic enough that it will also work on the GPD win we can always move
> the GPD win (and pocket) over to the new solution. Just like we are moving it
> over to the usb_connector fwnode now.

I don't have a problem with your proposal of using a string like that
at this point, but don't document it. I want to at least see if it's
possible to use real reference instead of a string. I'm also still
not sure should that be placed under the altmode node or should go
under the connector node.

So please don't add it to the usb-connector.txt at this point, even as
an optional property.


thanks,
Hans de Goede March 5, 2019, 7:45 a.m. UTC | #10
Hi,

On 04-03-19 16:17, Heikki Krogerus wrote:
> Hi Hans,
> 
> On Thu, Feb 28, 2019 at 05:54:21PM +0100, Hans de Goede wrote:
>> Hi Heikki,
>>
>> On 28-02-19 15:47, Heikki Krogerus wrote:
>>> Hi Hans,
>>>
>>> On Thu, Feb 28, 2019 at 12:24:25PM +0100, Hans de Goede wrote:
>>>> Hi,
>>>>
>>>> On 28-02-19 10:15, Heikki Krogerus wrote:
>>
>> <snip>
>>
>>>>> I've been thinking about this... Do we actually need to link the
>>>>> correct drm_connector to the Type-C connector? Perhaps we can make
>>>>> this work by just linking the GFX device to the Type-C connector.
>>>>
>>>> What use is it to the kms driver if it gets an event there is a DP
>>>> hotplug with x lanes and orientation foo, if we are not telling it
>>>> on which DP port it is ? kms devices already have multiple DP ports
>>>> and more then one could be hooked-up to type-c connectors.
>>>
>>> I was looking at this series. You walk trough every DP port in the
>>> system when the DP alt mode driver broadcasts the event, but maybe
>>> that's different. Never mind.
>>
>> Right, my "simple / naive" solution simply tells the kms driver to
>> check all DP ports for connection state changes, similar to how
>> running "xrandr" under Xorg causes the kms driver to re-check the
>> connection status of all ports. Actually running xrandr under Xorg
>> after plugging in the cable, is how I did my initial DP over Type-C
>> testing on the GPD win.
>>
>> But once we start passing extra-info, I believe the kms driver needs
>> to know to which connector that info belongs.
>>
>> <snip>
>>
>>>>> Well, I don't think we can deny the GPU driver (in this case) the
>>>>> information that we have and that is relevant to it, just because it
>>>>> seems difficult to deliver that information to the right location.
>>>>
>>>> Right, but this does not require a tight-coupling. My original
>>>> proposal can do this if we pass a data struct with an identifier
>>>> for the DP port for which the event is to the notifier. I suggest using
>>>> a string for identifier, something like: "0000:00:02.0/DP-1" this
>>>> event struct could then also contain all the info we want to pass.
>>>
>>> I do agree that we should not tie the objects (device entries)
>>> representing these components in kernel together, but I assume that we
>>> agree now that the connection between the two - the USB Type-C
>>> connector and the DisplayPort - must be described somewhere, either in
>>> firmware or build-in? So I guess we are talking implementation details
>>> here, right?
>>
>> Right.
>>
>>> If that is the case...
>>>
>>> That string identifier you proposed would basically provide the
>>> details about the connection, so if we know those details, we might as
>>> well use "normal" ways to describe the connection and just extract
>>> them in runtime in the function that our DP alt mode driver calls. I
>>> think the connection has to be defined in i915 on CHT in any case.
>>
>> Interesting, I think the connection should be described in the fwnode
>> for the fusb302 device for the CHT/GPD win case. Specifically I think
>> this fits well as a property of the dp altmode.
> 
> OK, you are correct. I was stupidly still thinking about the driver
> loading order, but the order does not matter.
> 
>>> The DP alt mode driver should definitely not need to pass anything
>>> else to the notifier other than handle to itself (actually, handle
>>> straight to the port device would be better) as an identifier. The
>>> notifier function needs to be the one that determines the actual
>>> connection using that handle. Even if the target DP is described using
>>> a string like you propose, then that string has to come from
>>> somewhere, most likely from a device property. The notifier function
>>> can just as well extract it, we don't need to pass it separately.
>>>
>>> Here's my suggestion for function prototype:
>>>
>>> int drm_typec_dp_notification(struct device *typec_port_dev,
>>>                                 struct typec_displayport_data *data);
>>
>> How about instead of the port_dev we pass in the altmode object and
>> we have a method to get the fwnode for the altmode? Then the
>> drm_typec_dp_notification() function can get info from that fwnode
>> to implement the connection finding you describe below:
> 
> We can pass the altmode object, np, but let's not decide which fwnode
> we'll ultimately use. I'm still leaning towards the connector node.
> 
>>> So that function finds the connection between typec_port_dev and the
>>> correct DP in runtime, possibly by letting i915 (or what ever GPU
>>> driver) to do that. Once the function is done, it decrements any ref
>>> counts that it incremented before returning.
>>>
>>> That struct typec_displayport_data has all the information we have -
>>> the current pin assignment from the Configure VDO, HPD IRQ from the
>>> last Status Update, etc. - so it needs to be passed as payload to the
>>> notifier.
>>
>> Ack.
>>
>> So I believe that this discussion ties into the discussion from the:
>> "[PATCH 0/2] platform/x86: intel_cht_int33fe: Start using software nodes"
>>
>> Mail thread. As discussed there I agree that adding a usb_connector
>> child fwnode to the fwnode for the fusb302 to describe things like
>> sink- and source-pdos is a good idea.
>>
>> Our last few mails were discussing describing supported alt-modes on
>> the connector by adding altmode child-nodes to the usb_connector node.
>>
>> I think it is best to continue that discussion here, as the 2 discussions
>> tie into one another.
>>
>> So my last proposal in that thread was adding the following to:
>>
>> Documentation/devicetree/bindings/connector/usb-connector.txt:
>>
>> """
>> Optionally an "usb-c-connector" can have child nodes, describing
>> supported alt-modes.
>>
>> Required properties for usb-c-connector altmode child-nodes:
>> compatible:        "usb-type-c-altmode"
>> svid:              integer, Standard or Vendor ID for the altmode (u16 stored in an u32) property and an u32
>> vdo:               integer, Vendor Data Object, VDO describing the altmode capabilies, SVID specific
>> """
>>
>> Since we now want to have the kernel know which DP connector belongs to
>> the usb_connector being in DP altmode I suggest additionally adding
>> the following:
>>
>> """
>> Optional properties for DisplayPort (svid==0xff01) altmode child-nodes.
>>
>> linux,dp-connector String in the form of "device-name/connector-name" describing the
>>                     DisplayPort connector on the GPU which is used when the usb-c-connector
>>                     is in DisplayPort altmode, e.g. "0000:00:02.0/DP-1"
>> """
>>
>> This to me feels like it is the most logical place to store the connection info,
>> at least for the CHT/GPD win case.  For other cases we may very-well need something
>> different. Since on the CHT/GPD win case both the producer and consumer of this
>> property will be in kernel, I think it is best to just go with this for now.
>> If we then later get a different solution for other cases and that solution turns
>> out to be generic enough that it will also work on the GPD win we can always move
>> the GPD win (and pocket) over to the new solution. Just like we are moving it
>> over to the usb_connector fwnode now.
> 
> I don't have a problem with your proposal of using a string like that
> at this point, but don't document it. I want to at least see if it's
> possible to use real reference instead of a string. I'm also still
> not sure should that be placed under the altmode node or should go
> under the connector node.
> 
> So please don't add it to the usb-connector.txt at this point, even as
> an optional property.

Ok, I will give the discussed approach a try and then post a new version of
the patchset. I hope to get around to this this weekend (as you know this is a side /
spare-time project for me).

Regards,

Hans