linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Peter Maydell <peter.maydell@linaro.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Alexander Graf <graf@amazon.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <bartekgola@gmail.com>,
	Magnus Damm <magnus.damm@gmail.com>
Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org,
	linux-gpio@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH QEMU v2 0/5] Add a GPIO backend
Date: Thu, 23 Apr 2020 11:01:13 +0200	[thread overview]
Message-ID: <20200423090118.11199-1-geert+renesas@glider.be> (raw)

	Hi all,

This patch series adds a GPIO controller backend, to connect virtual
GPIOs on the guest to physical GPIOs on the host, and enables support
for this using user-creatable PL061 GPIO controller instances.  This
allows the guest to control any external device connected to the
physical GPIOs.

While this can be used with an upstream Linux kernel (e.g. using a
dedicated GPIO controller connected to an external bus), proper
isolation and assignment of GPIOs to virtual machines depends on the
GPIO Aggregator[1], which has not been accepted in Linux upstream yet.
Aggregating GPIOs and exposing them as a new gpiochip was suggested in
response to my proof-of-concept for GPIO virtualization with QEMU[2][3].

Features and limitations:
  - The backend uses libgpiod on Linux,
  - For now only GPIO outputs are supported,
  - The number of GPIO lines mapped is limited to the number of GPIO
    lines available on the virtual GPIO controller (i.e. 8 on PL061).

Future work:
  - GPIO inputs,
  - GPIO line configuration,
  - Optimizations for controlling multiple GPIO lines at once,
  - ...

This series contains 5 patches:
  - The first two patches refactor the existing code for reuse,
  - The third patch adds a gneric GPIO backend using libgpiod,
  - The fourth patch adds gpiodev support to the PL061 driver,
  - The fifth patch adds dynamic PL061 support to ARM virt.

Changes compared to v1[2]:
  - Drop vgpios and gpios parameters, and map the full gpiochip instead,
  - Replace the single hardcoded PL061 instance (created by ARM virt) by
    multiple dynamically created instances, one per imported GPIO
    controller.

For testing, I have pushed this series to the topic/gpio-backend-v2
branch of my git repository at https://github.com/geertu/qemu.git.

Sample session on the Renesas Salvator-XS development board:

  - Unbind keyboard (shared with LEDs) from gpio-keys driver:

        host$ echo keys > /sys/bus/platform/drivers/gpio-keys/unbind

  - Aggregate GPIO lines connected to LEDs into a new virtual GPIO chip:

        host$ echo e6055400.gpio 11-13 \
              > /sys/bus/platform/drivers/gpio-aggregator/new_device

        gpio-aggregator gpio-aggregator.0: 0 => gpio-371
        gpio-aggregator gpio-aggregator.0: 1 => gpio-372
        gpio-aggregator gpio-aggregator.0: 2 => gpio-373
        gpiochip_find_base: found new base at 343
        gpio gpiochip10: (gpio-aggregator.0): added GPIO chardev (254:10)
        gpiochip_setup_dev: registered GPIOs 343 to 345 on device: gpiochip10 (gpio-aggregator.0)

  - Adjust permissions on /dev/gpiochip10 (optional)

  - Launch QEMU:

        host$ aarch64-softmmu/qemu-system-aarch64 -enable-kvm -M virt \
              -cpu cortex-a57 -m 1024 -nographic -kernel /path/to/Image \
              -device pl061,host=gpio-aggregator.0

        ...
        pl061_gpio c000000.gpio: PL061 GPIO chip registered
        ...

  - Control LEDs:

        guest$ gpioset gpiochip0 0=0 1=1 # LED4 OFF, LED5 ON
        guest$ gpioset gpiochip0 0=1 1=0 # LED4 ON, LED5 OFF

Thanks for your comments!

[1] "[PATCH v6 0/8] gpio: Add GPIO Aggregator"
    (https://lore.kernel.org/linux-gpio/20200324135328.5796-1-geert+renesas@glider.be/)
[2] "[PATCH QEMU POC] Add a GPIO backend"
    (https://lore.kernel.org/linux-gpio/20181003152521.23144-1-geert+renesas@glider.be/)
[3] "Getting To Blinky: Virt Edition / Making device pass-through work
     on embedded ARM"
    (https://fosdem.org/2019/schedule/event/vai_getting_to_blinky/)

Geert Uytterhoeven (5):
  ARM: PL061: Move TYPE_PL061 to hw/gpio/pl061.h
  ARM: PL061: Extract pl061_create_fdt()
  Add a GPIO backend using libgpiod
  ARM: PL061: Add gpiodev support
  hw/arm/virt: Add dynamic PL061 GPIO support

 MAINTAINERS              |  7 +++
 backends/Makefile.objs   |  2 +
 backends/gpiodev.c       | 94 ++++++++++++++++++++++++++++++++++++++++
 configure                | 28 ++++++++++++
 hw/arm/sysbus-fdt.c      | 18 ++++++++
 hw/arm/virt.c            | 21 ++-------
 hw/gpio/pl061.c          | 79 ++++++++++++++++++++++++++++++++-
 include/hw/gpio/pl061.h  | 23 ++++++++++
 include/sysemu/gpiodev.h | 12 +++++
 qemu-options.hx          |  9 ++++
 10 files changed, 275 insertions(+), 18 deletions(-)
 create mode 100644 backends/gpiodev.c
 create mode 100644 include/hw/gpio/pl061.h
 create mode 100644 include/sysemu/gpiodev.h

-- 
2.17.1

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

             reply	other threads:[~2020-04-23  9:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-23  9:01 Geert Uytterhoeven [this message]
2020-04-23  9:01 ` [PATCH QEMU v2 1/5] ARM: PL061: Move TYPE_PL061 to hw/gpio/pl061.h Geert Uytterhoeven
2020-04-23  9:22   ` Philippe Mathieu-Daudé
2020-04-23  9:01 ` [PATCH QEMU v2 2/5] ARM: PL061: Extract pl061_create_fdt() Geert Uytterhoeven
2020-04-23  9:23   ` Philippe Mathieu-Daudé
2020-04-23  9:01 ` [PATCH QEMU v2 3/5] Add a GPIO backend using libgpiod Geert Uytterhoeven
2020-04-23  9:28   ` Philippe Mathieu-Daudé
2020-04-23  9:41     ` Geert Uytterhoeven
2020-04-23 10:06       ` Philippe Mathieu-Daudé
2020-04-23  9:01 ` [PATCH QEMU v2 4/5] ARM: PL061: Add gpiodev support Geert Uytterhoeven
2020-04-23  9:33   ` Philippe Mathieu-Daudé
2020-04-23 10:08     ` Philippe Mathieu-Daudé
2020-07-16 14:10       ` Geert Uytterhoeven
2020-04-23  9:01 ` [PATCH QEMU v2 5/5] hw/arm/virt: Add dynamic PL061 GPIO support Geert Uytterhoeven
2020-04-23  9:13 ` [PATCH QEMU v2 0/5] Add a GPIO backend no-reply
2020-04-23  9:34 ` no-reply
2020-04-23  9:40 ` no-reply

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=20200423090118.11199-1-geert+renesas@glider.be \
    --to=geert+renesas@glider.be \
    --cc=bartekgola@gmail.com \
    --cc=graf@amazon.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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;
as well as URLs for NNTP newsgroup(s).