Skip to contentSkip to conversation

virtio: Add specification for virtio-gpio

PATCH Superseded Viresh Kumar 3 participants 18 messages Jul 28, 2021 – Jul 29, 2021

v7 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v7 cover virtio: Add specification for virtio-gpio

Hello,

This patchset adds virtio specification for GPIO devices. It supports basic GPIO line operations, along with optional interrupts on them (in a separate patch).

This is an *alternative implementation* of the virtio-gpio specification, a different version of it was earlier posted by Enrico [1].

I took back V4 of the specification I posted earlier (on June 17th), to allow Enrico to come up with something that is robust and works for everyone (as he started this thing last year), but it didn't go as expected. I couldn't see any of my review comments being incorporated (or any intentions of them getting in ever) in the three versions Enrico posted.

And so I am trying to present an alternative approach here to solve the problem, which I believe is more clear and robust. I am open to suggestions to improve it further.

I will let the virtio/gpio maintainers decide on its fate.

Key differences from Enrico's approach [1]:

- config structure is rearranged to remove everything apart from number of gpios and size of the gpio_names_field.

- Request/free is merged with set-direction itself.

- Interrupt implementation handled with feature bit 0. Either the interrupts are fully supported or not at all.

- All non-interrupt traffic happens on a single virtqueue, requestq. Interrupt traffic goes over eventq.

- Doesn't add any ordering restrictions on the device for different GPIO lines, it can respond earlier to the second request, while still processing the first one.

Version history of the specification I sent:

V6 -> V7:
- Drop Activate/Deactivate requests and merge them with set-direction one.
- Dropped separate calls to set direction to input or output (with a value), with a single call to set-direction (input, output, or none). Note that the driver needs to call set-value before calling set-direction-out now.
- Allow multiple messages for a GPIO line to be sent together, they must be processed in order though.
- The gpio-line names aren't required to be set for all the lines now, it is optional and can be present only for a subset of lines. Provided example as well.
- Merge irq-set/mask/unmask to a single set-irq-type message.
- We have only 6 message types now instead of 11 in v6.
- Mentioned about non-atomic nature of the these messages in commit log for patch 1/2.
- Improved spec content overall.

V5 -> V6:
- All non-interrupt traffic happens on a single virtqueue, requestq. Interrupt traffic goes over eventq now.
- Many fields dropped from the config structure.
- Separate message type to get gpio-names, added more description about how the names should be.
- Much clearer message flows, both non-irq messages and irq-messages.
- Parallelism supported for all type of messages, for different GPIO pins.
- All references to POSIX errors dropped, just reply pass or fail.
- request/free renamed to activate/deactivate, as that's what we will end up doing there, activate or deactivate a GPIO line.
- General purpose IO as I/O or Input/Output instead.
- Hopefully I didn't miss any review comments.

V4 -> V5:
- Split into two patches, irq stuff in patch 2.
- Use separate virtqueue for sending data from device/driver.
- Allow parallel processing of requests for different GPIOs, only one request at a time for the same GPIO line.
- Same goes for interrupt side, only one interrupt request per GPIO line.
- Improved formatting in general.
- Add new sections explaining message flow sequence.

V3 -> V4:
- The GPIO line names must be unique within a device.
- The gpio_names[0] field is dropped and gpio_names_offset field is added in place of the 2 bytes of padding.
- New interrupts must not be initiated by the device, without a response for the previous one.

V2 -> V3:
- Unused char in name string should be marked 0 now.
- s/host/device/ and s/guest/driver/
- Added a new feature for IRQ mode, VIRTIO_GPIO_F_IRQ.
- A new feature should be added for Version information if required later on.

V1 -> V2:
- gpio_names_size is 32 bit.
- gpio field is 16 bit.
- padding added 16 bit.
- Added packed attribute to few structures
- Add the missing 'type' field to the request
- Dropped to _nodata request/responses to simplify a bit, updated related text.

--
Viresh

[1] https://lists.oasis-open.org/archives/virtio-dev/202106/msg00030.html

Viresh Kumar (2):
virtio-gpio: Add the device specification
virtio-gpio: Add support for interrupts

 conformance.tex |  30 ++-
 content.tex     |   1 +
 virtio-gpio.tex | 528 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 555 insertions(+), 4 deletions(-)
 create mode 100644 virtio-gpio.tex
Signature · 1 line
2.31.1.272.g89b43f80a514
#1 lore raw

PATCH v7 1/2 virtio-gpio: Add the device specification

virtio-gpio is a virtual GPIO controller. It provides a way to flexibly communicate with the host GPIO controllers from the guest.

Note that the current implementation doesn't provide atomic APIs for GPIO configurations. i.e. the driver (guest) would need to implement sleep-able versions of the APIs as the guest will respond asynchronously over the virtqueue.

This patch adds the specification for it.

Based on the initial work posted by:
"Enrico Weigelt, metux IT consult" <[email protected]>.

---
 conformance.tex |  28 +++-
 content.tex     |   1 +
 virtio-gpio.tex | 339 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 364 insertions(+), 4 deletions(-)
 create mode 100644 virtio-gpio.tex
conformance.tex +24 -4
index 94d7a06db899..c52f1a40be2d 100644
@@ -30,8 +30,9 @@ \section{Conformance Targets}\label{sec:Conformance / Conformance Targets}
 \ref{sec:Conformance / Driver Conformance / IOMMU Driver Conformance},
 \ref{sec:Conformance / Driver Conformance / Sound Driver Conformance},
 \ref{sec:Conformance / Driver Conformance / Memory Driver Conformance},
-\ref{sec:Conformance / Driver Conformance / I2C Adapter Driver Conformance} or
-\ref{sec:Conformance / Driver Conformance / SCMI Driver Conformance}.
+\ref{sec:Conformance / Driver Conformance / I2C Adapter Driver Conformance},
+\ref{sec:Conformance / Driver Conformance / SCMI Driver Conformance} or
+\ref{sec:Conformance / Driver Conformance / GPIO Driver Conformance}.
 
     \item Clause \ref{sec:Conformance / Legacy Interface: Transitional Device and Transitional Driver Conformance}.
   \end{itemize}
@@ -54,8 +55,9 @@ \section{Conformance Targets}\label{sec:Conformance / Conformance Targets}
 \ref{sec:Conformance / Device Conformance / IOMMU Device Conformance},
 \ref{sec:Conformance / Device Conformance / Sound Device Conformance},
 \ref{sec:Conformance / Device Conformance / Memory Device Conformance},
-\ref{sec:Conformance / Device Conformance / I2C Adapter Device Conformance} or
-\ref{sec:Conformance / Device Conformance / SCMI Device Conformance}.
+\ref{sec:Conformance / Device Conformance / I2C Adapter Device Conformance},
+\ref{sec:Conformance / Device Conformance / SCMI Device Conformance} or
+\ref{sec:Conformance / Device Conformance / GPIO Device Conformance}.
 
     \item Clause \ref{sec:Conformance / Legacy Interface: Transitional Device and Transitional Driver Conformance}.
   \end{itemize}
@@ -301,6 +303,15 @@ \section{Conformance Targets}\label{sec:Conformance / Conformance Targets}
 \item \ref{drivernormative:Device Types / SCMI Device / Device Operation / Setting Up eventq Buffers}
 \end{itemize}
 
+\conformance{\subsection}{GPIO Driver Conformance}\label{sec:Conformance / Driver Conformance / GPIO Driver Conformance}
+
+A General Purpose Input/Output (GPIO) driver MUST conform to the following
+normative statements:
+
+\begin{itemize}
+\item \ref{drivernormative:Device Types / GPIO Device / requestq Operation}
+\end{itemize}
+
 \conformance{\section}{Device Conformance}\label{sec:Conformance / Device Conformance}
 
 A device MUST conform to the following normative statements:
@@ -550,6 +561,15 @@ \section{Conformance Targets}\label{sec:Conformance / Conformance Targets}
 \item \ref{devicenormative:Device Types / SCMI Device / Device Operation / Shared Memory Operation}
 \end{itemize}
 
+\conformance{\subsection}{GPIO Device Conformance}\label{sec:Conformance / Device Conformance / GPIO Device Conformance}
+
+A General Purpose Input/Output (GPIO) device MUST conform to the following
+normative statements:
+
+\begin{itemize}
+\item \ref{devicenormative:Device Types / GPIO Device / requestq Operation}
+\end{itemize}
+
 \conformance{\section}{Legacy Interface: Transitional Device and Transitional Driver Conformance}\label{sec:Conformance / Legacy Interface: Transitional Device and Transitional Driver Conformance}
 A conformant implementation MUST be either transitional or
 non-transitional, see \ref{intro:Legacy
content.tex +1 -0
index 31b02e1dca0e..0008727a80df 100644
@@ -6583,6 +6583,7 @@ \subsubsection{Legacy Interface: Framing Requirements}\label{sec:Device
 \input{virtio-mem.tex}
 \input{virtio-i2c.tex}
 \input{virtio-scmi.tex}
+\input{virtio-gpio.tex}
 
 \chapter{Reserved Feature Bits}\label{sec:Reserved Feature Bits}
 
virtio-gpio.tex new file +339 -0

339 lines not on this page · raw message

Signature · 6 lines
2.31.1.272.g89b43f80a514


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Reviewed-by on v7 1/2
#2 lore raw

Re: [PATCH V7 1/2] virtio-gpio: Add the device specification

Quoted 9 lines · Viresh Kumar

virtio-gpio is a virtual GPIO controller. It provides a way to flexibly communicate with the host GPIO controllers from the guest.

Note that the current implementation doesn't provide atomic APIs for GPIO configurations. i.e. the driver (guest) would need to implement sleep-able versions of the APIs as the guest will respond asynchronously over the virtqueue.

Quoted 7 lines

This patch adds the specification for it.

Based on the initial work posted by:
"Enrico Weigelt, metux IT consult" <[email protected]>.

I found one detail that could be improved if you can come up with a better way, or you just leave it:

Quoted 13 lines

+\begin{lstlisting}

virtio-gpio.tex new file +12 -0
+struct virtio_gpio_response {
+    u8 status;
+    u8 value[N];
+};
+
+/* Possible values of the status field */
+#define VIRTIO_GPIO_STATUS_OK                   0x0
+#define VIRTIO_GPIO_STATUS_ERR                  0x1
+\end{lstlisting}
+
+All the fields of this structure are set by the device and read by the driver.
+

virtio-gpio.tex line 100

Quoted 10 lines
virtio-gpio.tex new file +10 -0
+\begin{description}
+\item[\field{status}] of the GPIO message,
+    \field{VIRTIO_GPIO_STATUS_OK} on success and \field{VIRTIO_GPIO_STATUS_ERR}
+    on failure.
+
+\item[\field{value}] is a message specific defined value. The value of N (i.e.
+    size of the \field{value} buffer in bytes) is 1 for most of the messages,
+    except \field{VIRTIO_GPIO_MSG_GET_LINE_NAMES}, where it is set to the value
+    of \field{gpio_names_size} field.
+\end{description}

I think the structure layout here is good, but I wonder if the description would be clearer
if you define two separate structures, with a fixed-length structure for normal requests, and the variable-length structure for VIRTIO_GPIO_MSG_GET_LINE_NAMES.

Arnd

#3 lore raw

Re: [PATCH V7 1/2] virtio-gpio: Add the device specification

Quoted 4 lines · Arnd Bergmann

I think the structure layout here is good, but I wonder if the description would be clearer
if you define two separate structures, with a fixed-length structure for normal requests, and the variable-length structure for VIRTIO_GPIO_MSG_GET_LINE_NAMES.

Sure.

Signature · 1 line
viresh
Reviewed-by on v7 1/2
#4 lore raw

Re: [PATCH V7 1/2] virtio-gpio: Add the device specification

In reply to Viresh Kumar

Hi Viresh,

overall this looks good, with the minor nits pointed out:

Quoted 10 lines · Viresh Kumar

+\subsubsection{requestq Operation: Get Direction}\label{sec:Device Types / GPIO Device / requestq Operation / Get Direction}

virtio-gpio.tex new file +9 -0
+
+The driver sends this message to request the device to return a line's
+configured direction.
+
+\begin{tabularx}{\textwidth}{ |l||X|X|X| }
+\hline
+\textbf{Request} & \field{type} & \field{gpio} & \field{value} \\
+\hline
+& \field{VIRTIO_GPIO_MSG_GET_DIRECTION} & line number & 0 \\

virtio-gpio.tex line 192

Quoted 10 lines
virtio-gpio.tex new file +10 -0
+\hline
+\end{tabularx}
+
+\begin{tabularx}{\textwidth}{ |l||X|X|X| }
+\hline
+\textbf{Response} & \field{status} & \field{value[N]} & \field{Where N is} \\
+\hline
+    & \field{VIRTIO_GPIO_STATUS_*} & \field{VIRTIO_GPIO_DIRECTION_*} & 1 \\
+\hline
+\end{tabularx}

Is it clearly defined which value of VIRTIO_GPIO_DIRECTION_[IN|OUT] mean "input" and which value means "output"? Else add some text clarifying this.

Quoted 7 lines

+\begin{tabularx}{\textwidth}{ |l||X|X|X| }
+\hline
+\textbf{Response} & \field{status} & \field{value[N]} & \field{Where N is} \\
+\hline
+& \field{VIRTIO_GPIO_STATUS_*} & 0 = low, 1 = high & 1 \\
+\hline
+\end{tabularx}

Here, for example it is clearly defined.

Yours,
Linus Walleij

#5 lore raw

Re: [PATCH V7 1/2] virtio-gpio: Add the device specification

Quoted 2 lines · Linus Walleij

overall this looks good, with the minor nits pointed out:

Thanks.

Quoted 18 lines · Viresh Kumar
Quoted 17 lines

+\subsubsection{requestq Operation: Get Direction}\label{sec:Device Types / GPIO Device / requestq Operation / Get Direction}

virtio-gpio.tex new file +15 -0
+
+The driver sends this message to request the device to return a line's
+configured direction.
+
+\begin{tabularx}{\textwidth}{ |l||X|X|X| }
+\hline
+\textbf{Request} & \field{type} & \field{gpio} & \field{value} \\
+\hline
+& \field{VIRTIO_GPIO_MSG_GET_DIRECTION} & line number & 0 \\
+\hline
+\end{tabularx}
+
+\begin{tabularx}{\textwidth}{ |l||X|X|X| }
+\hline
+\textbf{Response} & \field{status} & \field{value[N]} & \field{Where N is} \\
Quoted 8 lines
Quoted 4 lines

+\hline
+ & \field{VIRTIO_GPIO_STATUS_*} & \field{VIRTIO_GPIO_DIRECTION_*} & 1 \\
+\hline
+\end{tabularx}

Is it clearly defined which value of VIRTIO_GPIO_DIRECTION_[IN|OUT] mean "input" and which value means "output"? Else add some text clarifying this.

+/* GPIO Direction types */

+#define VIRTIO_GPIO_DIRECTION_NONE              0x00
+#define VIRTIO_GPIO_DIRECTION_OUT               0x01
+#define VIRTIO_GPIO_DIRECTION_IN                0x02

Not sure if you missed this.

Were you looking for this or some text saying "VIRTIO_GPIO_DIRECTION_IN means direction-input", which looked self explanatory to me at least, though I can surely add it anyway.

Signature · 1 line
viresh
#6 lore raw

Re: [PATCH V7 1/2] virtio-gpio: Add the device specification

Quoted 38 lines · Viresh Kumar
Quoted 2 lines · Linus Walleij

overall this looks good, with the minor nits pointed out:

Thanks.

Quoted 26 lines · Viresh Kumar
Quoted 11 lines

+\subsubsection{requestq Operation: Get Direction}\label{sec:Device Types / GPIO Device / requestq Operation / Get Direction}

virtio-gpio.tex new file +9 -0
+
+The driver sends this message to request the device to return a line's
+configured direction.
+
+\begin{tabularx}{\textwidth}{ |l||X|X|X| }
+\hline
+\textbf{Request} & \field{type} & \field{gpio} & \field{value} \\
+\hline
+& \field{VIRTIO_GPIO_MSG_GET_DIRECTION} & line number & 0 \\

virtio-gpio.tex line 192

Quoted 10 lines
virtio-gpio.tex new file +10 -0
+\hline
+\end{tabularx}
+
+\begin{tabularx}{\textwidth}{ |l||X|X|X| }
+\hline
+\textbf{Response} & \field{status} & \field{value[N]} & \field{Where N is} \\
+\hline
+    & \field{VIRTIO_GPIO_STATUS_*} & \field{VIRTIO_GPIO_DIRECTION_*} & 1 \\
+\hline
+\end{tabularx}

Is it clearly defined which value of VIRTIO_GPIO_DIRECTION_[IN|OUT] mean "input" and which value means "output"? Else add some text clarifying this.

virtio-gpio.tex new file +4 -0
+/* GPIO Direction types */
+#define VIRTIO_GPIO_DIRECTION_NONE              0x00
+#define VIRTIO_GPIO_DIRECTION_OUT               0x01
+#define VIRTIO_GPIO_DIRECTION_IN                0x02
Quoted 5 lines

Not sure if you missed this.

Were you looking for this or some text saying "VIRTIO_GPIO_DIRECTION_IN means direction-input", which looked self explanatory to me at least, though I can surely add it anyway.

I just mean that the #define for the directions is elsewhere so maybe the actual numeric value should be mentioned here as well.

Nevermind, it's such a small nit.

Yours,
Linus Walleij

#7 lore raw

PATCH v7 2/2 virtio-gpio: Add support for interrupts

In reply to Viresh Kumar

This patch adds support for interrupts to the virtio-gpio specification. This uses the feature bit 0 for the same.

---
 conformance.tex |   2 +
 virtio-gpio.tex | 191 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 192 insertions(+), 1 deletion(-)
conformance.tex +2 -0
index c52f1a40be2d..64bcc12d1199 100644
@@ -310,6 +310,7 @@ \section{Conformance Targets}\label{sec:Conformance / Conformance Targets}
 
 \begin{itemize}
 \item \ref{drivernormative:Device Types / GPIO Device / requestq Operation}
+\item \ref{drivernormative:Device Types / GPIO Device / eventq Operation}
 \end{itemize}
 
 \conformance{\section}{Device Conformance}\label{sec:Conformance / Device Conformance}
@@ -568,6 +569,7 @@ \section{Conformance Targets}\label{sec:Conformance / Conformance Targets}
 
 \begin{itemize}
 \item \ref{devicenormative:Device Types / GPIO Device / requestq Operation}
+\item \ref{devicenormative:Device Types / GPIO Device / eventq Operation}
 \end{itemize}
 
 \conformance{\section}{Legacy Interface: Transitional Device and Transitional Driver Conformance}\label{sec:Conformance / Legacy Interface: Transitional Device and Transitional Driver Conformance}
virtio-gpio.tex +190 -1

233 lines not on this page · raw message

Signature · 1 line
2.31.1.272.g89b43f80a514
#8 lore raw

Re: [PATCH V7 2/2] virtio-gpio: Add support for interrupts

Quoted 6 lines · Viresh Kumar

This patch adds support for interrupts to the virtio-gpio specification. This uses the feature bit 0 for the same.

This also looks good to me overall, I have a few idea for clarifications below, but none of them are likely to change the actual behavior.

More importantly though, I would like to see a review by the linux irqchip maintainers (Marc Zyngier and/or Thomas Gleixner, both added to Cc here) before this gets merged into the virtio specification. I have a basic understanding
of the subsystem but probably got something wrong myself.

That review is probably easier once you post the driver code for it but if Thomas or Marc want to comment on the spec before seeing the driver, the patch is available at [1], along with the base virtio-gpio spec.

virtio-gpio.tex \subsubsection{requestq Operation: Set Value}\label{sec:Device Types / GPIO Devi · line 301

Quoted 13 lines

+\subsubsection{requestq Operation: Set IRQ Type}\label{sec:Device Types / GPIO Device / requestq Operation / Set IRQ Type}

virtio-gpio.tex +12 -0
+
+The driver sends this message to request the device to set the IRQ trigger type,
+to one of the \field{VIRTIO_GPIO_IRQ_TYPE_*} values, for a line configured for
+input.
+
+This request is only allowed if the \field{VIRTIO_GPIO_F_IRQ} feature is
+enabled by the device.
+
+The device MUST mask the interrupt for a GPIO line, if the trigger type is set
+to \field{VIRTIO_GPIO_IRQ_TYPE_NONE} and also discard any latched interrupt
+status associated with the line. The device MUST unmask the interrupt for any
+other value of the trigger type.

I think the last sentence here is somewhat ambiguous, I'm not sure what it actually
means to unmask a level triggered line if the driver has not queued an event request
for that line.

For an edge triggered interrupt, I think it makes sense to unmask the interrupt at
the device level and latch any incoming events until a request gets queued on the
eventq.

virtio-gpio.tex \subsubsection{requestq Operation: Message Flow}\label{sec:Device Types / GPIO D · line 372

Quoted 4 lines

+\item The driver MUST set the IRQ trigger type to

virtio-gpio.tex +2 -0
+    \field{VIRTIO_GPIO_IRQ_TYPE_NONE} once it is done using the GPIO line,
+    previously configured for a different trigger type.
 \end{itemize}

I'm not entirely sure why this "MUST" be done. Can't the device clean up the irq when the line is set back to direction=none or the queues are shut down?

virtio-gpio.tex \subsubsection{requestq Operation: Message Flow}\label{sec:Device Types / GPIO D · line 459

Quoted 9 lines

+\item The driver queues a pair of buffers, interrupt-request and

virtio-gpio.tex +8 -0
+    interrupt-response, to the \field{eventq} virtqueue for the GPIO line.
+
+\item The driver notifies the device of the presence of new buffers on the
+    \field{eventq} virtqueue.
+
+\item The driver sends the \field{VIRTIO_GPIO_MSG_SET_IRQ_TYPE} message over the
+    \field{requestq} virtqueue and the device configures the GPIO line for the
+    requested trigger type and unmasks the interrupt.

Ah, I guess that explains the flow. I was expecting the reverse order (first set-irq-type, then queue event request), but I suppose it works either way.

virtio-gpio.tex \subsubsection{requestq Operation: Message Flow}\label{sec:Device Types / GPIO D · line 487

Quoted 6 lines

+\item The driver on receiving the notification from the device, processes the

virtio-gpio.tex +5 -0
+    interrupt. The driver may try to update the trigger-type of the interrupt
+    for the GPIO line over the \field{requestq} virtqueue.
+
+\item The driver may again queue, same or new, pair of buffers for that GPIO
+    line and notify the device.

I feel there needs to be another step between these two, as this is where some of the magic happens that guarantees we don't get too many or not enough interrupts. How about:

\item In a typical guest operating system kernel, the virtio-gpio
driver notifies another device driver that is associated with this gpio line to process the event.

\item In the case of a level triggered interrupt, the secondary device
driver must fully process and acknowledge the event at its source to return the line to its inactive state.

Arnd

[1] https://lists.oasis-open.org/archives/virtio-dev/202107/msg00206.html

#9 lore raw

Re: [PATCH V7 2/2] virtio-gpio: Add support for interrupts

Quoted 10 lines · Arnd Bergmann

On Wed, Jul 28, 2021 at 1:11 PM Viresh Kumar <[email protected]> wrote:

This also looks good to me overall, I have a few idea for clarifications below, but none of them are likely to change the actual behavior.

More importantly though, I would like to see a review by the linux irqchip maintainers (Marc Zyngier and/or Thomas Gleixner, both added to Cc here) before this gets merged into the virtio specification. I have a basic understanding
of the subsystem but probably got something wrong myself.

Thanks for adding them.

Quoted 15 lines

That review is probably easier once you post the driver code for it but if Thomas or Marc want to comment on the spec before seeing the driver, the patch is available at [1], along with the base virtio-gpio spec.

Quoted 11 lines

+\subsubsection{requestq Operation: Set IRQ Type}\label{sec:Device Types / GPIO Device / requestq Operation / Set IRQ Type}

virtio-gpio.tex +10 -0
+
+The driver sends this message to request the device to set the IRQ trigger type,
+to one of the \field{VIRTIO_GPIO_IRQ_TYPE_*} values, for a line configured for
+input.
+
+This request is only allowed if the \field{VIRTIO_GPIO_F_IRQ} feature is
+enabled by the device.
+
+The device MUST mask the interrupt for a GPIO line, if the trigger type is set
+to \field{VIRTIO_GPIO_IRQ_TYPE_NONE} and also discard any latched interrupt
Quoted 8 lines

virtio-gpio.tex \subsubsection{requestq Operation: Set Value}\label{sec:Device Types / GPIO Devi · line 301

Quoted 2 lines
virtio-gpio.tex +2 -0
+status associated with the line. The device MUST unmask the interrupt for any
+other value of the trigger type.

I think the last sentence here is somewhat ambiguous, I'm not sure what it actually
means to unmask a level triggered line if the driver has not queued an event request
for that line.

(For everyone to follow, device == host, driver == guest)

There are two different situation where the interrupt can come and I believe the behavior should be different.

- The driver has requested for the trigger-type to be set and unmasking of the interrupt. The device MUST unmask the interrupt even if the buffer isn't queued over eventq, and so it must latch the interrupt value and report it as soon as the buffer is made available.

This behavior should be same for both edge or level interrupts.

- Once the interrupt is reported by the device, by returning the buffer over the eventq, the _level_ interrupt must be masked by the device until the time the buffer is re-queued by the driver, else it will end up reporting the same interrupt again as the line would have stayed at the same level until the interrupt handler had a chance to run and service the interrupt.

This is not the case for edge interrupt of course, where we need to latch value as that counts for a new interrupt.

Quoted 5 lines

For an edge triggered interrupt, I think it makes sense to unmask the interrupt at
the device level and latch any incoming events until a request gets queued on the
eventq.

I think the same holds true for level interrupts too.

Quoted 7 lines

virtio-gpio.tex \subsubsection{requestq Operation: Message Flow}\label{sec:Device Types / GPIO D · line 372

Quoted 4 lines

+\item The driver MUST set the IRQ trigger type to

virtio-gpio.tex +2 -0
+    \field{VIRTIO_GPIO_IRQ_TYPE_NONE} once it is done using the GPIO line,
+    previously configured for a different trigger type.
 \end{itemize}

I'm not entirely sure why this "MUST" be done. Can't the device clean up the irq when the line is set back to direction=none or the queues are shut down?

Yes we can infer that from direction=none as well, but even then the device needs to return the unused buffers over the eventq. And I thought it maybe better to explicitly mark this to be done and not mix with other operations like direction=none.

For the queues being shut case, I see that as a crash or hard stop. The device may want to handle things in that case by its own way, but the spec must try to avoid that case entirely and not encourage people to do things that way :)

Quoted 4 lines
Quoted 4 lines

+\item The driver queues a pair of buffers, interrupt-request and

virtio-gpio.tex +3 -0
+    interrupt-response, to the \field{eventq} virtqueue for the GPIO line.
+
+\item The driver notifies the device of the presence of new buffers on the
Quoted 8 lines

virtio-gpio.tex \subsubsection{requestq Operation: Message Flow}\label{sec:Device Types / GPIO D · line 459

Quoted 5 lines
virtio-gpio.tex +5 -0
+    \field{eventq} virtqueue.
+
+\item The driver sends the \field{VIRTIO_GPIO_MSG_SET_IRQ_TYPE} message over the
+    \field{requestq} virtqueue and the device configures the GPIO line for the
+    requested trigger type and unmasks the interrupt.

Ah, I guess that explains the flow. I was expecting the reverse order (first set-irq-type, then queue event request), but I suppose it works either way.

Whatever the flow is here at the driver, the device may observe these differently as these are two different virtqueues here. The device should always provide the buffer before requesting the device to enable to interrupt IMO.

Quoted 11 lines

virtio-gpio.tex \subsubsection{requestq Operation: Message Flow}\label{sec:Device Types / GPIO D · line 487

Quoted 6 lines

+\item The driver on receiving the notification from the device, processes the

virtio-gpio.tex +5 -0
+    interrupt. The driver may try to update the trigger-type of the interrupt
+    for the GPIO line over the \field{requestq} virtqueue.
+
+\item The driver may again queue, same or new, pair of buffers for that GPIO
+    line and notify the device.

I feel there needs to be another step between these two, as this is where some of the magic happens that guarantees we don't get too many or not enough interrupts. How about:

Quoted 7 lines

\item In a typical guest operating system kernel, the virtio-gpio
driver notifies another device driver that is associated with this gpio line to process the event.

\item In the case of a level triggered interrupt, the secondary device
driver must fully process and acknowledge the event at its source to return the line to its inactive state.

Sure, they can be added. Will do.

Signature · 1 line
viresh
#10 lore raw

Re: [PATCH V7 2/2] virtio-gpio: Add support for interrupts

Quoted 16 lines · Viresh Kumar
Quoted 8 lines · Arnd Bergmann

virtio-gpio.tex \subsubsection{requestq Operation: Set Value}\label{sec:Device Types / GPIO Devi · line 301

Quoted 4 lines
virtio-gpio.tex +4 -0
+The device MUST mask the interrupt for a GPIO line, if the trigger type is set
+to \field{VIRTIO_GPIO_IRQ_TYPE_NONE} and also discard any latched interrupt
+status associated with the line. The device MUST unmask the interrupt for any
+other value of the trigger type.

I think the last sentence here is somewhat ambiguous, I'm not sure what it actually means to unmask a level triggered line if the driver has not queued an event request for that line.

(For everyone to follow, device == host, driver == guest)

There are two different situation where the interrupt can come and I believe the behavior should be different.

Quoted 7 lines

- The driver has requested for the trigger-type to be set and unmasking of the interrupt. The device MUST unmask the interrupt even if the buffer isn't queued over eventq, and so it must latch the interrupt value and report it as soon as the buffer is made available.

This behavior should be same for both edge or level interrupts.

I think they are fundamentally different here, see below:

Quoted 7 lines

- Once the interrupt is reported by the device, by returning the buffer over the eventq, the _level_ interrupt must be masked by the device until the time the buffer is re-queued by the driver, else it will end up reporting the same interrupt again as the line would have stayed at the same level until the interrupt handler had a chance to run and service the interrupt.

Quoted 8 lines

This is not the case for edge interrupt of course, where we need to latch value as that counts for a new interrupt.

Quoted 3 lines

For an edge triggered interrupt, I think it makes sense to unmask the interrupt at the device level and latch any incoming events until a request gets queued on the eventq.

I think the same holds true for level interrupts too.

Wouldn't that cause the virtio-gpio device to send a second spurious interrupt reply for every hardware event?

During probe time, the level may be active if the device connected to the gpio has latched an event itself. When that device gets initialized, its driver would clear the status and bring the line to 'inactive' state before enabling interrupts. If the virtio-gpio device latches the state of the line having been active in the past, you get a first spurious reply. The driver will know how to deal with it, but it can be avoided.

For the later operation, the gpio client device signals an event by making the line active again, at this point the virtio-gpio device (in the host) gets signaled and queues the reply. If it then looks at the line, it is still active, so with your model it would have to latch another event. The gpio slave driver in the guest then processes the event and deactivates the line in order to not get woken up again until something new happens.

If the virtio-gpio device has already latched another event, this logic fails and you get woken up again directly at the end-of-interrupt (i.e. requeueing the eventq message) even if the line is currently inactive.

Quoted 13 lines
Quoted 7 lines

virtio-gpio.tex \subsubsection{requestq Operation: Message Flow}\label{sec:Device Types / GPIO D · line 372

Quoted 4 lines

+\item The driver MUST set the IRQ trigger type to

virtio-gpio.tex +2 -0
+    \field{VIRTIO_GPIO_IRQ_TYPE_NONE} once it is done using the GPIO line,
+    previously configured for a different trigger type.
 \end{itemize}

I'm not entirely sure why this "MUST" be done. Can't the device clean up the irq when the line is set back to direction=none or the queues are shut down?

Yes we can infer that from direction=none as well, but even then the device needs to return the unused buffers over the eventq. And I thought it maybe better to explicitly mark this to be done and not mix with other operations like direction=none.

Quoted 4 lines

For the queues being shut case, I see that as a crash or hard stop. The device may want to handle things in that case by its own way, but the spec must try to avoid that case entirely and not encourage people to do things that way :)

This still sounds like a "SHOULD" instead of "MUST" to me though, but I don't remember the exact definitions of these.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines

+\item The driver queues a pair of buffers, interrupt-request and

virtio-gpio.tex +3 -0
+    interrupt-response, to the \field{eventq} virtqueue for the GPIO line.
+
+\item The driver notifies the device of the presence of new buffers on the
Quoted 8 lines

virtio-gpio.tex \subsubsection{requestq Operation: Message Flow}\label{sec:Device Types / GPIO D · line 459

Quoted 5 lines
virtio-gpio.tex +5 -0
+    \field{eventq} virtqueue.
+
+\item The driver sends the \field{VIRTIO_GPIO_MSG_SET_IRQ_TYPE} message over the
+    \field{requestq} virtqueue and the device configures the GPIO line for the
+    requested trigger type and unmasks the interrupt.

Ah, I guess that explains the flow. I was expecting the reverse order (first set-irq-type, then queue event request), but I suppose it works either way.

Quoted 4 lines

Whatever the flow is here at the driver, the device may observe these differently as these are two different virtqueues here. The device should always provide the buffer before requesting the device to enable to interrupt IMO.

Fair enough, I don't care too much about this one, I was just thinking we'd expect it to do it the other way round since that is more consistent with the continued operation after the interrupts remain enabled and we go back and forth requeing new eventq requests without turning them off again.

Arnd

#11 lore raw

Re: [PATCH V7 2/2] virtio-gpio: Add support for interrupts

Quoted 5 lines · Arnd Bergmann

Wouldn't that cause the virtio-gpio device to send a second spurious interrupt reply for every hardware event?

During probe time, the level may be active if the device connected to the gpio has latched an event itself.

At this time the trigger type should be set to NONE by default and no latching of the line's value must be performed by the device. The device should look for interrupts only after the interrupt is explicitly unmasked (irq-type set to non-NONE value) by the driver.

Quoted 4 lines

When that device gets initialized, its
driver would clear the status and bring the line to 'inactive' state before enabling interrupts. If the virtio-gpio device latches the state of the line having been active in the past, you get a first spurious reply.

And so this shouldn't happen.

Quoted 8 lines

The driver
will know how to deal with it, but it can be avoided.

For the later operation, the gpio client device signals an event by making the line active again, at this point the virtio-gpio device (in the host) gets signaled and queues the reply. If it then looks at the line, it is still active, so with your model it would have to latch another event.

No, since interrupt-handling is being performed at this time, the device MUST NOT latch a value for trigger type _level_. This is very explicitly stated in the current version of specs.

Quoted 8 lines

The gpio slave driver in the guest then processes the event and deactivates the line in order to not get woken up again until something new happens.

If the virtio-gpio device has already latched another event, this logic fails and you get woken up again directly at the end-of-interrupt (i.e. requeueing the eventq message) even if the line is currently inactive.

This shouldn't happen, but I now find the reliance on the request buffer being available or not a bit confusing with respect to masking or unmasking of the interrupt. More on this later..

Quoted 13 lines
Quoted 13 lines
Quoted 7 lines

virtio-gpio.tex \subsubsection{requestq Operation: Message Flow}\label{sec:Device Types / GPIO D · line 372

Quoted 4 lines

+\item The driver MUST set the IRQ trigger type to

virtio-gpio.tex +2 -0
+    \field{VIRTIO_GPIO_IRQ_TYPE_NONE} once it is done using the GPIO line,
+    previously configured for a different trigger type.
 \end{itemize}

I'm not entirely sure why this "MUST" be done. Can't the device clean up the irq when the line is set back to direction=none or the queues are shut down?

Yes we can infer that from direction=none as well, but even then the device needs to return the unused buffers over the eventq. And I thought it maybe better to explicitly mark this to be done and not mix with other operations like direction=none.

Quoted 7 lines
Quoted 4 lines

For the queues being shut case, I see that as a crash or hard stop. The device may want to handle things in that case by its own way, but the spec must try to avoid that case entirely and not encourage people to do things that way :)

This still sounds like a "SHOULD" instead of "MUST" to me though, but I don't remember the exact definitions of these.

Sure, I can make that a SHOULD :)

Quoted 4 lines

Fair enough, I don't care too much about this one, I was just thinking we'd expect it to do it the other way round since that is more consistent with the continued operation after the interrupts remain enabled and we go back and forth requeing new eventq requests without turning them off again.

Coming back to the confusing part here. I think we should make the interrupt controller (device) dumb here and leave all intelligence at the users (driver).

What about defining the sequence of events like this:

For edge interrupt:

- driver sets trigger type to EDGE (falling/rising).
- device enables the interrupt line, latches a value only after this point.
- driver queues a buffer over eventq (here or before setting trigger type).
- Once buffer is available over eventq, device returns it back and latches the next interrupt as soon as it happens.
- driver on receiving the buffer, re-queues the buffer and handles the interrupt by calling client's handler. Though queuing the buffer it after handling the request won't make a huge difference (and may be better for simpler driver code) as the next interrupt is latched anyway by the device and can be processed only after this one is done at the driver (some locking will be there to make sure only one interrupt gets processed per line at a time).
- Note that in this sequence we don't mask/unmask the interrupt at all. That's what kernel will also do in handle_edge_irq() if I understood it correctly.

For level interrupt:

- driver sets trigger type to LEVEL (high/low).
- device enables the interrupt line, latches a value only after this point.
- driver queues a buffer over eventq (here or before setting trigger type).
- Once buffer is available over eventq, device returns it back and latches the next interrupt as soon as it happens. Its okay.
- The driver on receiving the buffer, passes control to irq-core which masks the interrupt by calling driver to set the trigger type to NONE.
- The device masks the interrupt and discards any latched value.
- The irq-core handles the interrupt by calling client's handler.
- The irq-core unmasks the interrupt by calling the driver to set the trigger type to LEVEL.
- The device unmasks the interrupt and latches any new value from here on.
- The driver queues the buffer again.

How does that sound ? This removes any logical dependency between availability of the buffer and the interrupt being masked or unmasked.

One thing I am not very clear about is where do .irq_bus_lock()/unlock() come in this picture. Are they called during interrupt handling time too or just during setting of the interrupt (i.e. request_irq()).

Signature · 1 line
viresh
#12 lore raw

Re: [PATCH V7 2/2] virtio-gpio: Add support for interrupts

Quoted 13 lines · Viresh Kumar
Quoted 4 lines

Fair enough, I don't care too much about this one, I was just thinking we'd expect it to do it the other way round since that is more consistent with the continued operation after the interrupts remain enabled and we go back and forth requeing new eventq requests without turning them off again.

Coming back to the confusing part here. I think we should make the interrupt controller (device) dumb here and leave all intelligence at the users (driver).

What about defining the sequence of events like this:

For edge interrupt:

Quoted 16 lines

- driver sets trigger type to EDGE (falling/rising).
- device enables the interrupt line, latches a value only after this point.
- driver queues a buffer over eventq (here or before setting trigger type).
- Once buffer is available over eventq, device returns it back and latches the next interrupt as soon as it happens.
- driver on receiving the buffer, re-queues the buffer and handles the interrupt by calling client's handler. Though queuing the buffer it after handling the request won't make a huge difference (and may be better for simpler driver code) as the next interrupt is latched anyway by the device and can be processed only after this one is done at the driver (some locking will be there to make sure only one interrupt gets processed per line at a time).
- Note that in this sequence we don't mask/unmask the interrupt at all. That's what kernel will also do in handle_edge_irq() if I understood it correctly.

Maybe this is where we misunderstood each other: I was thinking of it in terms of handle_fasteoi_irq() control flow, not handle_edge_irq().

For the edge interrupt, it doesn't make much of a difference, but for the level case, I think we really want handle_fasteoi_irq(), and as I understand it, the driver side should work the same way here.

Quoted 19 lines

For level interrupt:

- driver sets trigger type to LEVEL (high/low).
- device enables the interrupt line, latches a value only after this point.
- driver queues a buffer over eventq (here or before setting trigger type).
- Once buffer is available over eventq, device returns it back and latches the next interrupt as soon as it happens. Its okay.
- The driver on receiving the buffer, passes control to irq-core which masks the interrupt by calling driver to set the trigger type to NONE.
- The device masks the interrupt and discards any latched value.
- The irq-core handles the interrupt by calling client's handler.
- The irq-core unmasks the interrupt by calling the driver to set the trigger type to LEVEL.
- The device unmasks the interrupt and latches any new value from here on.
- The driver queues the buffer again.

Quoted 2 lines

How does that sound ? This removes any logical dependency between availability of the buffer and the interrupt being masked or unmasked.

I think having to mask/unmask the level interrupt explicitly adds way too much complexity here, in particular when these are both blocking operations. With the fasteoi flow, the irq core never has to mask it, but only atomically requeue the buffer at the end.

Arnd

#13 lore raw

Re: [PATCH V7 2/2] virtio-gpio: Add support for interrupts

In reply to Arnd Bergmann
Quoted 5 lines · Arnd Bergmann

I think the last sentence here is somewhat ambiguous, I'm not sure what it actually
means to unmask a level triggered line if the driver has not queued an event request
for that line.

I think I now understand what you meant by this, I wasn't thinking of fasteoi earlier :)

What about following diff over this patch:

virtio-gpio.tex +41 -17
index ffc89b98f34e..0085708151d7 100644
@@ -288,17 +288,31 @@ \subsubsection{requestq Operation: Set Value}\label{sec:Device Types / GPIO Devi
 
 \subsubsection{requestq Operation: Set IRQ Type}\label{sec:Device Types / GPIO Device / requestq Operation / Set IRQ Type}
 
+This request is only allowed if the \field{VIRTIO_GPIO_F_IRQ} feature is enabled
+by the device.
+
 The driver sends this message to request the device to set the IRQ trigger type,
 to one of the \field{VIRTIO_GPIO_IRQ_TYPE_*} values, for a line configured for
 input.
 
-This request is only allowed if the \field{VIRTIO_GPIO_F_IRQ} feature is
-enabled by the device.
+The device notifies the driver of an interrupt event using the per GPIO line
+buffers provided by the driver on the \field{eventq} virtqueue.
 
 The device MUST mask the interrupt for a GPIO line, if the trigger type is set
 to \field{VIRTIO_GPIO_IRQ_TYPE_NONE} and also discard any latched interrupt
-status associated with the line. The device MUST unmask the interrupt for any
-other value of the trigger type.
+event associated with the line. The device MUST NOT notify the driver of an
+interrupt event if the trigger type is set to \field{VIRTIO_GPIO_IRQ_TYPE_NONE}
+for the GPIO line.
+
+The device MUST unmask the interrupt for any other value of the trigger type and
+notify the driver of an interrupt event once the corresponding buffers are
+available.
+
+For edge trigger type, the device MUST latch the interrupt event from this point
+onward and report it to the driver as soon as a buffers are available.
+
+For level trigger type, the device only reports an interrupt if the
+corresponding interrupt level was sensed when the buffers are received.
 
 \begin{tabularx}{\textwidth}{ |l||X|X|X| }
 \hline
@@ -366,7 +380,7 @@ \subsubsection{requestq Operation: Message Flow}\label{sec:Device Types / GPIO D
 \item The driver MUST NOT send IRQ messages if the \field{VIRTIO_GPIO_F_IRQ}
     feature is not enabled by the device.
 
-\item The driver MUST set the IRQ trigger type to
+\item The driver SHOULD set the IRQ trigger type to
     \field{VIRTIO_GPIO_IRQ_TYPE_NONE} once it is done using the GPIO line,
     previously configured for a different trigger type.
 \end{itemize}
@@ -445,19 +459,19 @@ \subsection{Device Operation: eventq}\label{sec:Device Types / GPIO Device / eve
 \subsubsection{eventq Operation: Message Flow}\label{sec:Device Types / GPIO Device / eventq Operation / Message Flow}
 
 \begin{itemize}
-\item The driver is requested by a user to enable interrupt for a GPIO and
+\item The driver is requested by a client to enable interrupt for a GPIO and
     configure it for a particular trigger type.
 
+\item The driver sends the \field{VIRTIO_GPIO_MSG_SET_IRQ_TYPE} message over the
+    \field{requestq} virtqueue and the device configures the GPIO line for the
+    requested trigger type and unmasks the interrupt.
+
 \item The driver queues a pair of buffers, interrupt-request and
     interrupt-response, to the \field{eventq} virtqueue for the GPIO line.
 
 \item The driver notifies the device of the presence of new buffers on the
     \field{eventq} virtqueue.
 
-\item The driver sends the \field{VIRTIO_GPIO_MSG_SET_IRQ_TYPE} message over the
-    \field{requestq} virtqueue and the device configures the GPIO line for the
-    requested trigger type and unmasks the interrupt.
-
 \item The interrupt is fully configured at this point.
 
 \item The device, on sensing an interrupt on a GPIO line, finds the matching
@@ -469,19 +483,29 @@ \subsubsection{eventq Operation: Message Flow}\label{sec:Device Types / GPIO Dev
 \item The device notifies the driver of the presence of new buffers on the
     \field{eventq} virtqueue.
 
-\item If the GPIO line is configured for Level interrupts, the device MUST mask
-    the interrupts for this GPIO line, until the time the buffers are made
-    available again by the driver.
+\item If the GPIO line is configured for level interrupts, the device MUST
+    ignore the interrupts for this GPIO line, until the time the buffers are
+    made available again by the driver. Once the buffers are available again,
+    and the interrupt on the line is still active, the device can again notify
+    the driver of an interrupt event.
 
-\item If the GPIO line is configured for Edge interrupts, the device MUST latch
+\item If the GPIO line is configured for edge interrupts, the device MUST latch
     the latest interrupt received for this GPIO line, until the time the buffers
     are made available again by the driver. At that point, the device can again
-    return the buffers for the line if an interrupt was received while the
-    device was waiting for the buffers to be made available by the driver.
+    notify the driver if an interrupt was received while the device was waiting
+    for the buffers to be made available by the driver.
 
 \item The driver on receiving the notification from the device, processes the
     interrupt. The driver may try to update the trigger-type of the interrupt
-    for the GPIO line over the \field{requestq} virtqueue.
+    for the GPIO line over the \field{requestq} virtqueue at this point.
+
+\item In a typical guest operating system kernel, the virtio-gpio driver
+    notifies the client driver that is associated with this gpio line to process
+    the event.
+
+\item In the case of a level triggered interrupt, the client driver must fully
+    process and acknowledge the event at its source to return the line to its
+    inactive state.
 
 \item The driver may again queue, same or new, pair of buffers for that GPIO
     line and notify the device.
#14 lore raw

Re: [PATCH V7 2/2] virtio-gpio: Add support for interrupts

Quoted 13 lines · Viresh Kumar
Quoted 3 lines · Arnd Bergmann

I think the last sentence here is somewhat ambiguous, I'm not sure what it actually means to unmask a level triggered line if the driver has not queued an event request for that line.

I think I now understand what you meant by this, I wasn't thinking of fasteoi earlier :)

What about following diff over this patch:

The device MUST mask the interrupt for a GPIO line, if the trigger type is set to \field{VIRTIO_GPIO_IRQ_TYPE_NONE} and also discard any latched interrupt

virtio-gpio.tex \subsubsection{requestq Operation: Set Value}\label{sec:Device Types / GPIO Devi · line 305

Quoted 5 lines
virtio-gpio.tex +3 -2
-status associated with the line. The device MUST unmask the interrupt for any
-other value of the trigger type.
+event associated with the line. The device MUST NOT notify the driver of an
+interrupt event if the trigger type is set to \field{VIRTIO_GPIO_IRQ_TYPE_NONE}
+for the GPIO line.

I actually thought that setting VIRTIO_GPIO_IRQ_TYPE_NONE would return the buffer to the driver, with status indicating that no event has happened.

virtio-gpio.tex \subsubsection{requestq Operation: Set Value}\label{sec:Device Types / GPIO Devi · line 315

Quoted 2 lines
virtio-gpio.tex +2 -0
+For level trigger type, the device only reports an interrupt if the
+corresponding interrupt level was sensed when the buffers are received.

I think you mean the right thing, but this part is very misleading: we clearly want
to be notified if the line was active when the buffer is received and also as soon as it becomes active afterwards, just not when it was active in the past.

Quoted 18 lines

+\item The driver sends the \field{VIRTIO_GPIO_MSG_SET_IRQ_TYPE} message over the

virtio-gpio.tex +3 -4
+    \field{requestq} virtqueue and the device configures the GPIO line for the
+    requested trigger type and unmasks the interrupt.
+
 \item The driver queues a pair of buffers, interrupt-request and
     interrupt-response, to the \field{eventq} virtqueue for the GPIO line.
 
 \item The driver notifies the device of the presence of new buffers on the
     \field{eventq} virtqueue.
 
-\item The driver sends the \field{VIRTIO_GPIO_MSG_SET_IRQ_TYPE} message over the
-    \field{requestq} virtqueue and the device configures the GPIO line for the
-    requested trigger type and unmasks the interrupt.
-
 \item The interrupt is fully configured at this point.
 
 \item The device, on sensing an interrupt on a GPIO line, finds the matching

virtio-gpio.tex \subsubsection{eventq Operation: Message Flow}\label{sec:Device Types / GPIO Dev · line 487

Quoted 8 lines
virtio-gpio.tex +2 -3
@@ -469,19 +483,29 @@ \subsubsection{eventq Operation: Message Flow}\label{sec:Device Types / GPIO Dev
 \item The device notifies the driver of the presence of new buffers on the
     \field{eventq} virtqueue.
 
-\item If the GPIO line is configured for Level interrupts, the device MUST mask
-    the interrupts for this GPIO line, until the time the buffers are made
-    available again by the driver.
+\item If the GPIO line is configured for level interrupts, the device MUST
+    ignore the interrupts for this GPIO line, until the time the buffers are

Maybe change

s/the interrupts for/an active interrupt signaled on/

virtio-gpio.tex \subsubsection{eventq Operation: Message Flow}\label{sec:Device Types / GPIO Dev · line 496

Quoted 12 lines
virtio-gpio.tex +6 -3
+    made available again by the driver. Once the buffers are available again,
+    and the interrupt on the line is still active, the device can again notify
+    the driver of an interrupt event.
 
-\item If the GPIO line is configured for Edge interrupts, the device MUST latch
+\item If the GPIO line is configured for edge interrupts, the device MUST latch
     the latest interrupt received for this GPIO line, until the time the buffers
     are made available again by the driver. At that point, the device can again
-    return the buffers for the line if an interrupt was received while the
-    device was waiting for the buffers to be made available by the driver.
+    notify the driver if an interrupt was received while the device was waiting
+    for the buffers to be made available by the driver.

I think this needs to be

s/the device can/the device MUST/

signaling the interrupt is not optional ;-)

The rest looks good to me now, but it's a little hard to read in diff form. Are you able to post the driver soon? I think our understanding of how this should work has converged enough that I'd review that next.

Arnd

#15 lore raw

Re: [PATCH V7 2/2] virtio-gpio: Add support for interrupts

Quoted 12 lines · Arnd Bergmann
Quoted 11 lines · Viresh Kumar
Quoted 3 lines · Arnd Bergmann

I think the last sentence here is somewhat ambiguous, I'm not sure what it actually means to unmask a level triggered line if the driver has not queued an event request for that line.

I think I now understand what you meant by this, I wasn't thinking of fasteoi earlier :)

What about following diff over this patch:

Quoted 11 lines

virtio-gpio.tex \subsubsection{requestq Operation: Set Value}\label{sec:Device Types / GPIO Devi · line 305

Quoted 7 lines

The device MUST mask the interrupt for a GPIO line, if the trigger type is set to \field{VIRTIO_GPIO_IRQ_TYPE_NONE} and also discard any latched interrupt

virtio-gpio.tex +3 -2
-status associated with the line. The device MUST unmask the interrupt for any
-other value of the trigger type.
+event associated with the line. The device MUST NOT notify the driver of an
+interrupt event if the trigger type is set to \field{VIRTIO_GPIO_IRQ_TYPE_NONE}
+for the GPIO line.

I actually thought that setting VIRTIO_GPIO_IRQ_TYPE_NONE would return the buffer to the driver, with status indicating that no event has happened.

Yeah, that is actually the case. What I meant here was that an interrupt must not be reported by the device in this case, but yes the buffer needs to be returned. Will clarify on that a bit here.

Quoted 7 lines

virtio-gpio.tex \subsubsection{requestq Operation: Set Value}\label{sec:Device Types / GPIO Devi · line 315

Quoted 2 lines
virtio-gpio.tex +2 -0
+For level trigger type, the device only reports an interrupt if the
+corresponding interrupt level was sensed when the buffers are received.

I think you mean the right thing, but this part is very misleading: we clearly want
to be notified if the line was active when the buffer is received and also as soon as it becomes active afterwards, just not when it was active in the past.

Right.

Quoted 3 lines

The rest looks good to me now, but it's a little hard to read in diff form. Are you able to post the driver soon? I think our understanding of how this should work has converged enough that I'd review that next.

I should be able to post that somewhere next week, making changes according to spec changes.

Signature · 1 line
viresh
Reviewed-by on v7 2/2
#16 lore raw

Re: [PATCH V7 2/2] virtio-gpio: Add support for interrupts

In reply to Viresh Kumar
Quoted 5 lines · Viresh Kumar

This patch adds support for interrupts to the virtio-gpio specification. This uses the feature bit 0 for the same.

From a GPIO point of view this looks good, so FWIW

It's best if you get feedback from the irqchip people too.

Yours,
Linus Walleij

#17 lore raw
In reply to Viresh Kumar
Quoted 18 lines · Viresh Kumar

Version history of the specification I sent:

V6 -> V7:
- Drop Activate/Deactivate requests and merge them with set-direction one.
- Dropped separate calls to set direction to input or output (with a value), with a single call to set-direction (input, output, or none). Note that the driver needs to call set-value before calling set-direction-out now.
- Allow multiple messages for a GPIO line to be sent together, they must be processed in order though.
- The gpio-line names aren't required to be set for all the lines now, it is optional and can be present only for a subset of lines. Provided example as well.
- Merge irq-set/mask/unmask to a single set-irq-type message.
- We have only 6 message types now instead of 11 in v6.
- Mentioned about non-atomic nature of the these messages in commit log for patch 1/2.
- Improved spec content overall.

Nice update, this all sounds good to me. I'll go through the two patches in more detail next, but don't expect to find much then.

Arnd