From: "Christian A. Ehrhardt" <lk@c--e.de>
To: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Christian A. Ehrhardt" <lk@c--e.de>,
"Heikki Krogerus" <heikki.krogerus@linux.intel.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Samuel Čavoj" <samuel@cavoj.net>,
"Hans de Goede" <hdegoede@redhat.com>,
"Neil Armstrong" <neil.armstrong@linaro.org>,
"Prashanth K" <quic_prashk@quicinc.com>,
"Dmitry Baryshkov" <dmitry.baryshkov@linaro.org>,
"Saranya Gopal" <saranya.gopal@intel.com>,
"Haotien Hsu" <haotienh@nvidia.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Utkarsh Patel" <utkarsh.h.patel@intel.com>,
"Bjorn Andersson" <andersson@kernel.org>,
"Luca Weiss" <luca.weiss@fairphone.com>,
"Min-Hua Chen" <minhuadotchen@gmail.com>,
"Rob Herring" <robh@kernel.org>,
"Rajaram Regupathy" <rajaram.regupathy@intel.com>,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
"Abhishek Pandit-Subedi" <abhishekpandit@chromium.org>
Subject: [RFC PATCH 0/6] UCSI backend API refactoring
Date: Sun, 18 Feb 2024 23:20:33 +0100 [thread overview]
Message-ID: <20240218222039.822040-1-lk@c--e.de> (raw)
The (new) API for UCSI backends has some problems:
The UCSI spec assumes a mailbox style communication:
1. The OPM fills data (UCSI_MESSAGE_OUT and UCSI_CONTROL)
into the mailbox memory region. In the ACPI case these are
simple host memory accesses.
2. The OPM notifies the PPM that a command should be executed.
In the ACPI case this is a call the _DSM ACPI function.
Within that function the UCSI_CONTROL and the UCSI_MESSAGE_OUT
data is transferred to something like the embedded controller
and then the PPM is notified e.g. by an SMI.
3. The PPM executes the command. As a result UCSI_MESSAGE_IN and
UCSI_CCI in the mailbox memory are updated and the OPM
is notified. In the ACPI case the notification is an SCI and
ACPI provides a handler that syncs UCSI_MESSAGE_IN and
UCSI_CCI from the EC into host memory before notifying the
OPM via the ACPI Notify() command.
The major problem is that steps 1 (update mailbox memory) and
step 2 (notify PPM and start command execution) are two different
steps. The current API only knows about a write function that
combines writing to mailbox memory and starting command execution.
This only works as long as the commands do not have arguments
that must be in UCSI_MESSAGE_OUT.
Additionally, Step 3 (at least in the ACPI case) above suggests
that UCSI_CCI and UCSI_MESSAGE_IN should generally be read from
mailbox memory. Except for some special cases the sync operation
via the _DSM-Read function in ACPI is not required and seems to
do more harm then good.
E.g. the zenbook quirks could be avoided if we didn't re-read the
UCSI_CCI and UCSI_MESSAGE_IN data from the embedded controller
on each read operation. The recent fix to the CCG backend seems
to address the same issue.
This change series proposes a new API with the following design
goals:
- Retain the nice features of the previous API redesign. In
particular the synchronous execution of commands in the
backend and the ability to handle quirks there.
- The API must still be able to handle all backends (obviously).
Thus each new API function is currently implemented in all
backends in the same change.
- Separate writing to mailbox data and starting command execution
to allow for commands with UCSI_MESSAGE_OUT data.
- Avoid hardware accesses (as opposed to mailbox memory accesses)
outside of the command execution context as much as possible.
- Avoid use of explicit mailbox offsets (that are subject to
change with later UCSI revisions) in the UCSI core.
The proposed new API features:
- read_data() and write_data() for access to the message data
fields. This is supposed to be a pure mailbox access that
even in the case of a write does not start a command.
- sync_cmd() and async_cmd() to write the command register and
start command execution.
- A cached version of the current contents of CCI in the core
UCSI structure. This value is only updated if a notification
is received from the hardware.
- poll_cci() to force an update of the cached CCI value from
hardware. This is required to poll for PPM reset completion.
CAVEATs:
- The series will certainly need more polishing etc. before
it can be accepted. I will do this provided that the series
is considered a good idea in general.
- The series compiles, passes smatch, sparse and checkpatch but
I only have ucsi_acpi hardware to test this. The other backends
(ccg, glink, stm32g0) will need testers and likely some fixes
as well.
So, what do you think?
Christian A. Ehrhardt (6):
usb: ucsi_glink: Fix endianness issues
ucsi_ccg: Cleanup endianness confusion
usb: typec: ucsi: Make Version a parameter to ucsi_register
usb: typec: ucsi: Cache current CCI value in struct ucsi
usb: typec: ucsi: Introdcue ->read_data and ->write_data
usb: typec: ucsi: Convert a?sync_write to a?sync_cmd
drivers/usb/typec/ucsi/ucsi.c | 53 ++++--------
drivers/usb/typec/ucsi/ucsi.h | 28 +++---
drivers/usb/typec/ucsi/ucsi_acpi.c | 119 ++++++++++++--------------
drivers/usb/typec/ucsi/ucsi_ccg.c | 107 ++++++++++++-----------
drivers/usb/typec/ucsi/ucsi_glink.c | 104 +++++++++++++++++-----
drivers/usb/typec/ucsi/ucsi_stm32g0.c | 80 ++++++++++++++---
6 files changed, 290 insertions(+), 201 deletions(-)
--
2.40.1
next reply other threads:[~2024-02-18 22:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-18 22:20 Christian A. Ehrhardt [this message]
2024-02-18 22:20 ` [RFC PATCH 1/6] usb: ucsi_glink: Fix endianness issues Christian A. Ehrhardt
2024-02-18 22:20 ` [RFC PATCH 2/6] ucsi_ccg: Cleanup endianness confusion Christian A. Ehrhardt
2024-02-18 22:20 ` [RFC PATCH 3/6] usb: typec: ucsi: Make Version a parameter to ucsi_register Christian A. Ehrhardt
2024-02-18 22:20 ` [RFC PATCH 4/6] usb: typec: ucsi: Cache current CCI value in struct ucsi Christian A. Ehrhardt
2024-02-18 22:20 ` [RFC PATCH 5/6] usb: typec: ucsi: Introdcue ->read_data and ->write_data Christian A. Ehrhardt
2024-02-18 22:20 ` [RFC PATCH 6/6] usb: typec: ucsi: Convert a?sync_write to a?sync_cmd Christian A. Ehrhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240218222039.822040-1-lk@c--e.de \
--to=lk@c--e.de \
--cc=abhishekpandit@chromium.org \
--cc=alexandre.torgue@foss.st.com \
--cc=andersson@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=dmitry.baryshkov@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=haotienh@nvidia.com \
--cc=hdegoede@redhat.com \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=linux-usb@vger.kernel.org \
--cc=luca.weiss@fairphone.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=minhuadotchen@gmail.com \
--cc=neil.armstrong@linaro.org \
--cc=quic_prashk@quicinc.com \
--cc=rajaram.regupathy@intel.com \
--cc=robh@kernel.org \
--cc=samuel@cavoj.net \
--cc=saranya.gopal@intel.com \
--cc=u.kleine-koenig@pengutronix.de \
--cc=utkarsh.h.patel@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®