From nobody Fri Nov 29 03:39:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1652162741; cv=none; d=zohomail.com; s=zohoarc; b=UIE88DLlv8lDDoiHZWWAFVmMhicrtTtbyV8sjzqODm0PSdXFBKFvDUceW0pY6tevQhXDEOJb1aI6aIfgOcWoubLGvssesDggFVDMgOJx+d/HybeOu2EH00p5OGzwV2pA7CUUY1VC4RIQnpIdE8YPYHYnA3X4NSIkJTlK7RTOXuM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652162741; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HyzuOp/tvITGfFX9GJge8V/26LSsI0eF8GbficmNu7U=; b=YQUlbMWUUGE8bN7Q5fy0lOsfk2OrF1ZDmrDG3MlppV72gVlXdjL7k9kFtG/icgVeSzoG0sxWCtj6q7IVcoWIhqP8azOtJl012L4NoFH11s4cRaZVBwIXmu2PujJCa+oG3KBXfJOs0l7MkGpgEkjjPIOSrd9EnK6OSW7084r20Yg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1652162741545624.2742033780613; Mon, 9 May 2022 23:05:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.325178.547648 (Exim 4.92) (envelope-from ) id 1noIzf-0008LN-Qk; Tue, 10 May 2022 06:05:11 +0000 Received: by outflank-mailman (output) from mailman id 325178.547648; Tue, 10 May 2022 06:05:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1noIzf-0008LG-M0; Tue, 10 May 2022 06:05:11 +0000 Received: by outflank-mailman (input) for mailman id 325178; Tue, 10 May 2022 06:05:10 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1noIzd-0007ob-TE for xen-devel@lists.xen.org; Tue, 10 May 2022 06:05:10 +0000 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [2607:f8b0:4864:20::52b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 23aae201-d027-11ec-a406-831a346695d4; Tue, 10 May 2022 08:05:07 +0200 (CEST) Received: by mail-pg1-x52b.google.com with SMTP id s16so3726784pgs.3 for ; Mon, 09 May 2022 23:05:07 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id u67-20020a626046000000b0050dc762814esm9751334pfb.40.2022.05.09.23.05.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 23:05:05 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 23aae201-d027-11ec-a406-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HyzuOp/tvITGfFX9GJge8V/26LSsI0eF8GbficmNu7U=; b=M67x4/R6jdy471wEvDx2Ve38kbtBlyYrBJXglB/TFrMRgV1dBgfFZK8iIqQ2Ket3VS o67j+LHFwD4JxoM/NhqQPry9PFxr/pl/XwgRMbtjL9Nrf+Vw+B5M0cD6ci0s4AIzivSW yfVNhsjgLuC0EQEO/jiBjc+2WTTyyOzDrPt2HlsYie06sDeQ2Sep8PIrpw8vg/dqokJv FPbfmcUcqOsI/N7aYBrgLoZZxMMwSwpDAMON4qftJbqCheNLaO52rp+n2JbyMNc/e/vd tP61jErQOkjzzzaQhtbfyPWKkYKihCuPZIKM6KJiQwztqUKRK65kXFOVw+Wy/VDJ3G/S pxBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HyzuOp/tvITGfFX9GJge8V/26LSsI0eF8GbficmNu7U=; b=cjDOYvihfifQCsuXZtg8Ux1nBAQYqSJVna0qhV4SjKQcWt5Whc/LyVTpiG0KEsTuH2 NfVQwIF3ip8r1qsj/feexYokyoxZkMmoynFzoe8kc3vhePa4NlJfxI9bkGjucQMN2XgU Tagp2+YZqJi/VPpjeLaXSdf1yu6iQmA7KKFxr0GHznbmG51wISR+s9QZCgTBqRA9cfZS 32QT3dYzkOnG7dVL/ClFfEPG7Pnr4+yopcJkworfIqrVmMPt/djV6Dt56lZ4QlNRDVsT No8RSVbeWD1sQSqOWC/0BBjQBpQBzhsgyX8WkYNmhWYSQMcriuJPJWmicqzMV1/okTXf nzhg== X-Gm-Message-State: AOAM533YI6yLlidOK+8AOqMP2wXM4gmgF37pUdBz2lxskLFag/aiSHzl aJN0U6iM0ueeE8c3tcCYI6uG43zcufE25Q== X-Google-Smtp-Source: ABdhPJyNA//hYlvOjkaQBC1aLhOM4ZNdmASuAYyWnwX7TpT86LK5x4woDWmunCqOZS2h/Fm76aQWUQ== X-Received: by 2002:a63:e155:0:b0:3c6:7514:6c0d with SMTP id h21-20020a63e155000000b003c675146c0dmr11777055pgk.249.1652162705486; Mon, 09 May 2022 23:05:05 -0700 (PDT) From: Viresh Kumar To: xen-devel@lists.xen.org Cc: Viresh Kumar , Vincent Guittot , stratos-dev@op-lists.linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Stefano Stabellini , Mathieu Poirier , Mike Holmes , Oleksandr Tyshchenko , Wei Liu , Juergen Gross , Julien Grall Subject: [PATCH V2 2/6] libxl: Add support for Virtio GPIO device Date: Tue, 10 May 2022 11:34:47 +0530 Message-Id: <48d5e96ab0f1c1e85f77144e31ca199e04c00e9b.1652162646.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1652162743719100007 Content-Type: text/plain; charset="utf-8" This patch adds basic support for configuring and assisting virtio-mmio based virtio-gpio backend (emualator) which is intended to run out of Qemu and could be run in any domain. An example of domain configuration for Virtio Gpio: gpio =3D [ "" ] Please note, this patch is not enough for virtio-gpio to work on Xen (Arm), as for every Virtio device we need to allocate Virtio MMIO params (IRQ and memory region) and pass them to the backend, also update Guest device-tree. A subsequent patch will add these missing bits. For the current patch, the default "irq" and "base" are just written to the Xenstore. Signed-off-by: Viresh Kumar --- tools/golang/xenlight/helpers.gen.go | 110 ++++++++++ tools/golang/xenlight/types.gen.go | 27 +++ tools/include/libxl.h | 32 +++ tools/include/libxl_utils.h | 3 + tools/libs/light/Makefile | 1 + tools/libs/light/libxl_create.c | 13 ++ tools/libs/light/libxl_dm.c | 17 +- tools/libs/light/libxl_gpio.c | 236 ++++++++++++++++++++++ tools/libs/light/libxl_internal.h | 1 + tools/libs/light/libxl_types.idl | 26 +++ tools/libs/light/libxl_types_internal.idl | 1 + tools/ocaml/libs/xl/genwrap.py | 1 + tools/ocaml/libs/xl/xenlight_stubs.c | 1 + tools/xl/Makefile | 2 +- tools/xl/xl.h | 3 + tools/xl/xl_cmdtable.c | 15 ++ tools/xl/xl_gpio.c | 143 +++++++++++++ tools/xl/xl_parse.c | 80 ++++++++ tools/xl/xl_parse.h | 1 + tools/xl/xl_sxp.c | 2 + 20 files changed, 713 insertions(+), 2 deletions(-) create mode 100644 tools/libs/light/libxl_gpio.c create mode 100644 tools/xl/xl_gpio.c diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/h= elpers.gen.go index ad23b0969abd..ed880cad3fa7 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -1215,6 +1215,9 @@ x.Usbdevice =3D C.GoString(tmp.usbdevice) if err :=3D x.VkbDevice.fromC(&tmp.vkb_device);err !=3D nil { return fmt.Errorf("converting field VkbDevice: %v", err) } +if err :=3D x.GpioDevice.fromC(&tmp.gpio_device);err !=3D nil { +return fmt.Errorf("converting field GpioDevice: %v", err) +} if err :=3D x.I2cDevice.fromC(&tmp.i2c_device);err !=3D nil { return fmt.Errorf("converting field I2cDevice: %v", err) } @@ -1535,6 +1538,9 @@ hvm.usbdevice =3D C.CString(tmp.Usbdevice)} if err :=3D tmp.VkbDevice.toC(&hvm.vkb_device); err !=3D nil { return fmt.Errorf("converting field VkbDevice: %v", err) } +if err :=3D tmp.GpioDevice.toC(&hvm.gpio_device); err !=3D nil { +return fmt.Errorf("converting field GpioDevice: %v", err) +} if err :=3D tmp.I2cDevice.toC(&hvm.i2c_device); err !=3D nil { return fmt.Errorf("converting field I2cDevice: %v", err) } @@ -1728,6 +1734,46 @@ xc.multi_touch_num_contacts =3D C.uint32_t(x.MultiTo= uchNumContacts) return nil } =20 +// NewDeviceGpio returns an instance of DeviceGpio initialized with defaul= ts. +func NewDeviceGpio() (*DeviceGpio, error) { +var ( +x DeviceGpio +xc C.libxl_device_gpio) + +C.libxl_device_gpio_init(&xc) +defer C.libxl_device_gpio_dispose(&xc) + +if err :=3D x.fromC(&xc); err !=3D nil { +return nil, err } + +return &x, nil} + +func (x *DeviceGpio) fromC(xc *C.libxl_device_gpio) error { + x.BackendDomid =3D Domid(xc.backend_domid) +x.BackendDomname =3D C.GoString(xc.backend_domname) +x.Devid =3D Devid(xc.devid) +x.BackendType =3D GpioBackend(xc.backend_type) +x.Irq =3D uint32(xc.irq) +x.Base =3D uint64(xc.base) + + return nil} + +func (x *DeviceGpio) toC(xc *C.libxl_device_gpio) (err error){defer func(){ +if err !=3D nil{ +C.libxl_device_gpio_dispose(xc)} +}() + +xc.backend_domid =3D C.libxl_domid(x.BackendDomid) +if x.BackendDomname !=3D "" { +xc.backend_domname =3D C.CString(x.BackendDomname)} +xc.devid =3D C.libxl_devid(x.Devid) +xc.backend_type =3D C.libxl_gpio_backend(x.BackendType) +xc.irq =3D C.uint32_t(x.Irq) +xc.base =3D C.uint64_t(x.Base) + + return nil + } + // NewDeviceI2c returns an instance of DeviceI2c initialized with defaults. func NewDeviceI2c() (*DeviceI2c, error) { var ( @@ -2881,6 +2927,15 @@ if err :=3D x.Vkbs[i].fromC(&v); err !=3D nil { return fmt.Errorf("converting field Vkbs: %v", err) } } } +x.Gpios =3D nil +if n :=3D int(xc.num_gpios); n > 0 { +cGpios :=3D (*[1<<28]C.libxl_device_gpio)(unsafe.Pointer(xc.gpios))[:n:n] +x.Gpios =3D make([]DeviceGpio, n) +for i, v :=3D range cGpios { +if err :=3D x.Gpios[i].fromC(&v); err !=3D nil { +return fmt.Errorf("converting field Gpios: %v", err) } +} +} x.I2cs =3D nil if n :=3D int(xc.num_i2cs); n > 0 { cI2cs :=3D (*[1<<28]C.libxl_device_i2c)(unsafe.Pointer(xc.i2cs))[:n:n] @@ -3051,6 +3106,16 @@ return fmt.Errorf("converting field Vkbs: %v", err) } } } +if numGpios :=3D len(x.Gpios); numGpios > 0 { +xc.gpios =3D (*C.libxl_device_gpio)(C.malloc(C.ulong(numGpios)*C.sizeof_li= bxl_device_gpio)) +xc.num_gpios =3D C.int(numGpios) +cGpios :=3D (*[1<<28]C.libxl_device_gpio)(unsafe.Pointer(xc.gpios))[:numGp= ios:numGpios] +for i,v :=3D range x.Gpios { +if err :=3D v.toC(&cGpios[i]); err !=3D nil { +return fmt.Errorf("converting field Gpios: %v", err) +} +} +} if numI2cs :=3D len(x.I2cs); numI2cs > 0 { xc.i2cs =3D (*C.libxl_device_i2c)(C.malloc(C.ulong(numI2cs)*C.sizeof_libxl= _device_i2c)) xc.num_i2cs =3D C.int(numI2cs) @@ -3748,6 +3813,51 @@ if err !=3D nil{ C.libxl_vkbinfo_dispose(xc)} }() =20 +if x.Backend !=3D "" { +xc.backend =3D C.CString(x.Backend)} +xc.backend_id =3D C.uint32_t(x.BackendId) +if x.Frontend !=3D "" { +xc.frontend =3D C.CString(x.Frontend)} +xc.frontend_id =3D C.uint32_t(x.FrontendId) +xc.devid =3D C.libxl_devid(x.Devid) +xc.state =3D C.int(x.State) +xc.evtch =3D C.int(x.Evtch) +xc.rref =3D C.int(x.Rref) + + return nil + } + +// NewGpioinfo returns an instance of Gpioinfo initialized with defaults. +func NewGpioinfo() (*Gpioinfo, error) { +var ( +x Gpioinfo +xc C.libxl_gpioinfo) + +C.libxl_gpioinfo_init(&xc) +defer C.libxl_gpioinfo_dispose(&xc) + +if err :=3D x.fromC(&xc); err !=3D nil { +return nil, err } + +return &x, nil} + +func (x *Gpioinfo) fromC(xc *C.libxl_gpioinfo) error { + x.Backend =3D C.GoString(xc.backend) +x.BackendId =3D uint32(xc.backend_id) +x.Frontend =3D C.GoString(xc.frontend) +x.FrontendId =3D uint32(xc.frontend_id) +x.Devid =3D Devid(xc.devid) +x.State =3D int(xc.state) +x.Evtch =3D int(xc.evtch) +x.Rref =3D int(xc.rref) + + return nil} + +func (x *Gpioinfo) toC(xc *C.libxl_gpioinfo) (err error){defer func(){ +if err !=3D nil{ +C.libxl_gpioinfo_dispose(xc)} +}() + if x.Backend !=3D "" { xc.backend =3D C.CString(x.Backend)} xc.backend_id =3D C.uint32_t(x.BackendId) diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/typ= es.gen.go index c232e4811ac3..cb959d5fa87a 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -241,6 +241,11 @@ VkbBackendQemu VkbBackend =3D 1 VkbBackendLinux VkbBackend =3D 2 ) =20 +type GpioBackend int +const( +GpioBackendVirtio GpioBackend =3D 0 +) + type I2cBackend int const( I2cBackendVirtio I2cBackend =3D 0 @@ -573,6 +578,7 @@ Usb Defbool Usbversion int Usbdevice string VkbDevice Defbool +GpioDevice Defbool I2cDevice Defbool Soundhw string XenPlatformPci Defbool @@ -636,6 +642,15 @@ MultiTouchHeight uint32 MultiTouchNumContacts uint32 } =20 +type DeviceGpio struct { +BackendDomid Domid +BackendDomname string +Devid Devid +BackendType GpioBackend +Irq uint32 +Base uint64 +} + type DeviceI2c struct { BackendDomid Domid BackendDomname string @@ -928,6 +943,7 @@ Rdms []DeviceRdm Dtdevs []DeviceDtdev Vfbs []DeviceVfb Vkbs []DeviceVkb +Gpios []DeviceGpio I2cs []DeviceI2c Vtpms []DeviceVtpm P9S []DeviceP9 @@ -1083,6 +1099,17 @@ Evtch int Rref int } =20 +type Gpioinfo struct { +Backend string +BackendId uint32 +Frontend string +FrontendId uint32 +Devid Devid +State int +Evtch int +Rref int +} + type I2cinfo struct { Backend string BackendId uint32 diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 4d19194c3dc2..f2fe616dee18 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -800,6 +800,15 @@ typedef struct libxl__ctx libxl_ctx; */ #define LIBXL_HAVE_BUILDINFO_VKB_DEVICE 1 =20 +/* + * LIBXL_HAVE_BUILDINFO_GPIO_DEVICE + * + * If this is defined, then the libxl_domain_build_info structure will + * contain a boolean hvm.gpio_device which instructs libxl whether to incl= ude + * a gpio at build time or not. + */ +#define LIBXL_HAVE_BUILDINFO_GPIO_DEVICE 1 + /* * LIBXL_HAVE_BUILDINFO_I2C_DEVICE * @@ -2377,6 +2386,29 @@ int libxl_device_vkb_getinfo(libxl_ctx *ctx, uint32_= t domid, libxl_vkbinfo *vkbinfo) LIBXL_EXTERNAL_CALLERS_ONLY; =20 +/* GPIO */ +int libxl_device_gpio_add(libxl_ctx *ctx, uint32_t domid, libxl_device_gpi= o *gpio, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_device_gpio_remove(libxl_ctx *ctx, uint32_t domid, + libxl_device_gpio *gpio, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_device_gpio_destroy(libxl_ctx *ctx, uint32_t domid, + libxl_device_gpio *gpio, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; + +libxl_device_gpio *libxl_device_gpio_list(libxl_ctx *ctx, + uint32_t domid, int *num) + LIBXL_EXTERNAL_CALLERS_ONLY; +void libxl_device_gpio_list_free(libxl_device_gpio* list, int num) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_device_gpio_getinfo(libxl_ctx *ctx, uint32_t domid, + const libxl_device_gpio *gpio, + libxl_gpioinfo *gpioinfo) + LIBXL_EXTERNAL_CALLERS_ONLY; + /* I2C */ int libxl_device_i2c_add(libxl_ctx *ctx, uint32_t domid, libxl_device_i2c = *i2c, const libxl_asyncop_how *ao_how) diff --git a/tools/include/libxl_utils.h b/tools/include/libxl_utils.h index 72b7796b7e4b..91f5c68172cb 100644 --- a/tools/include/libxl_utils.h +++ b/tools/include/libxl_utils.h @@ -83,6 +83,9 @@ int libxl_devid_to_device_usbctrl(libxl_ctx *ctx, uint32_= t domid, int libxl_devid_to_device_vkb(libxl_ctx *ctx, uint32_t domid, int devid, libxl_device_vkb *vkb); =20 +int libxl_devid_to_device_gpio(libxl_ctx *ctx, uint32_t domid, + int devid, libxl_device_gpio *gpio); + int libxl_devid_to_device_i2c(libxl_ctx *ctx, uint32_t domid, int devid, libxl_device_i2c *i2c); =20 diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile index dca46846e586..6caa15cc1148 100644 --- a/tools/libs/light/Makefile +++ b/tools/libs/light/Makefile @@ -112,6 +112,7 @@ SRCS-y +=3D libxl_vdispl.c SRCS-y +=3D libxl_pvcalls.c SRCS-y +=3D libxl_vsnd.c SRCS-y +=3D libxl_vkb.c +SRCS-y +=3D libxl_gpio.c SRCS-y +=3D libxl_i2c.c SRCS-y +=3D libxl_genid.c SRCS-y +=3D _libxl_types.c diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_creat= e.c index d604171e504c..836d43bd3f03 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -363,6 +363,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, libxl_defbool_setdefault(&b_info->u.hvm.altp2m, false); libxl_defbool_setdefault(&b_info->u.hvm.usb, false); libxl_defbool_setdefault(&b_info->u.hvm.vkb_device, true); + libxl_defbool_setdefault(&b_info->u.hvm.gpio_device, true); libxl_defbool_setdefault(&b_info->u.hvm.i2c_device, true); libxl_defbool_setdefault(&b_info->u.hvm.xen_platform_pci, true); =20 @@ -1756,6 +1757,7 @@ static void domcreate_launch_dm(libxl__egc *egc, libx= l__multidev *multidev, libxl__device_console console; libxl__device device; libxl_device_vkb vkb; + libxl_device_gpio gpio; libxl_device_i2c i2c; =20 init_console_info(gc, &console, 0); @@ -1769,6 +1771,12 @@ static void domcreate_launch_dm(libxl__egc *egc, lib= xl__multidev *multidev, libxl_device_vkb_dispose(&vkb); } =20 + if (libxl_defbool_val(d_config->b_info.u.hvm.gpio_device)) { + libxl_device_gpio_init(&gpio); + libxl__device_add(gc, domid, &libxl__gpio_devtype, &gpio); + libxl_device_gpio_dispose(&gpio); + } + if (libxl_defbool_val(d_config->b_info.u.hvm.i2c_device)) { libxl_device_i2c_init(&i2c); libxl__device_add(gc, domid, &libxl__i2c_devtype, &i2c); @@ -1807,6 +1815,11 @@ static void domcreate_launch_dm(libxl__egc *egc, lib= xl__multidev *multidev, &d_config->vkbs[i]); } =20 + for (i =3D 0; i < d_config->num_gpios; i++) { + libxl__device_add(gc, domid, &libxl__gpio_devtype, + &d_config->gpios[i]); + } + for (i =3D 0; i < d_config->num_i2cs; i++) { libxl__device_add(gc, domid, &libxl__i2c_devtype, &d_config->i2cs[i]); diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c index 9340ae4628a2..124b73f1dd00 100644 --- a/tools/libs/light/libxl_dm.c +++ b/tools/libs/light/libxl_dm.c @@ -2096,6 +2096,7 @@ static int libxl__vfb_and_vkb_from_hvm_guest_config(l= ibxl__gc *gc, const libxl_domain_config *guest_c= onfig, libxl_device_vfb *vfb, libxl_device_vkb *vkb, + libxl_device_gpio *gpio, libxl_device_i2c *i2c) { const libxl_domain_build_info *b_info =3D &guest_config->b_info; @@ -2105,6 +2106,7 @@ static int libxl__vfb_and_vkb_from_hvm_guest_config(l= ibxl__gc *gc, =20 libxl_device_vfb_init(vfb); libxl_device_vkb_init(vkb); + libxl_device_gpio_init(gpio); libxl_device_i2c_init(i2c); =20 vfb->backend_domid =3D 0; @@ -2116,6 +2118,9 @@ static int libxl__vfb_and_vkb_from_hvm_guest_config(l= ibxl__gc *gc, vkb->backend_domid =3D 0; vkb->devid =3D 0; =20 + gpio->backend_domid =3D 0; + gpio->devid =3D 0; + i2c->backend_domid =3D 0; i2c->devid =3D 0; =20 @@ -2281,6 +2286,7 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stu= b_dm_spawn_state *sdss) int ret; libxl_device_vfb *vfb; libxl_device_vkb *vkb; + libxl_device_gpio *gpio; libxl_device_i2c *i2c; char **args; struct xs_permissions perm[2]; @@ -2354,12 +2360,15 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__s= tub_dm_spawn_state *sdss) || libxl_defbool_val(guest_config->b_info.u.hvm.sdl.enable)) { GCNEW(vfb); GCNEW(vkb); + GCNEW(gpio); GCNEW(i2c); - libxl__vfb_and_vkb_from_hvm_guest_config(gc, guest_config, vfb, vk= b, i2c); + libxl__vfb_and_vkb_from_hvm_guest_config(gc, guest_config, vfb, vk= b, gpio, i2c); dm_config->vfbs =3D vfb; dm_config->num_vfbs =3D 1; dm_config->vkbs =3D vkb; dm_config->num_vkbs =3D 1; + dm_config->gpios =3D gpio; + dm_config->num_gpios =3D 1; dm_config->i2cs =3D i2c; dm_config->num_i2cs =3D 1; } @@ -2503,6 +2512,12 @@ static void spawn_stub_launch_dm(libxl__egc *egc, if (ret) goto out; } =20 + if (dm_config->num_gpios) { + ret =3D libxl__device_add(gc, dm_domid, &libxl__gpio_devtype, + &dm_config->gpios[0]); + if (ret) goto out; + } + if (dm_config->num_i2cs) { ret =3D libxl__device_add(gc, dm_domid, &libxl__i2c_devtype, &dm_config->i2cs[0]); diff --git a/tools/libs/light/libxl_gpio.c b/tools/libs/light/libxl_gpio.c new file mode 100644 index 000000000000..2bf68deb3850 --- /dev/null +++ b/tools/libs/light/libxl_gpio.c @@ -0,0 +1,236 @@ +/* + * Copyright (C) 2022 Linaro Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include "libxl_internal.h" + +#include + +static int libxl__device_gpio_setdefault(libxl__gc *gc, uint32_t domid, + libxl_device_gpio *gpio, bool hotp= lug) +{ + if (gpio->backend_type !=3D LIBXL_GPIO_BACKEND_VIRTIO) { + gpio->backend_type =3D LIBXL_GPIO_BACKEND_VIRTIO; + } + + return libxl__resolve_domid(gc, gpio->backend_domname, &gpio->backend_= domid); +} + +static int libxl__device_gpio_dm_needed(void *e, uint32_t domid) +{ + libxl_device_gpio *elem =3D e; + + return elem->backend_type =3D=3D LIBXL_GPIO_BACKEND_VIRTIO; +} + +static int libxl__set_xenstore_gpio(libxl__gc *gc, uint32_t domid, + libxl_device_gpio *gpio, + flexarray_t *back, flexarray_t *front, + flexarray_t *ro_front) +{ + flexarray_append_pair(back, "irq", GCSPRINTF("%u", gpio->irq)); + flexarray_append_pair(back, "base", GCSPRINTF("%lu", gpio->base)); + + flexarray_append_pair(front, "irq", GCSPRINTF("%u", gpio->irq)); + flexarray_append_pair(front, "base", GCSPRINTF("%lu", gpio->base)); + + return 0; +} + +static int libxl__gpio_from_xenstore(libxl__gc *gc, const char *libxl_path, + libxl_devid devid, + libxl_device_gpio *gpio) +{ + const char *be_path, *fe_path, *tmp; + libxl__device dev; + int rc; + + gpio->devid =3D devid; + + rc =3D libxl__xs_read_mandatory(gc, XBT_NULL, + GCSPRINTF("%s/backend", libxl_path), + &be_path); + if (rc) goto out; + + rc =3D libxl__xs_read_mandatory(gc, XBT_NULL, + GCSPRINTF("%s/frontend", libxl_path), + &fe_path); + if (rc) goto out; + + rc =3D libxl__backendpath_parse_domid(gc, be_path, &gpio->backend_domi= d); + if (rc) goto out; + + rc =3D libxl__parse_backend_path(gc, be_path, &dev); + if (rc) goto out; + + gpio->backend_type =3D LIBXL_GPIO_BACKEND_VIRTIO; + + rc =3D libxl__xs_read_checked(gc, XBT_NULL, + GCSPRINTF("%s/irq", be_path), &tmp); + if (rc) goto out; + + if (tmp) { + gpio->irq =3D strtoul(tmp, NULL, 0); + } + + rc =3D libxl__xs_read_checked(gc, XBT_NULL, + GCSPRINTF("%s/base", be_path), &tmp); + if (rc) goto out; + + if (tmp) { + gpio->base =3D strtoul(tmp, NULL, 0); + } + + rc =3D 0; + +out: + + return rc; +} + +static int libxl__device_from_gpio(libxl__gc *gc, uint32_t domid, + libxl_device_gpio *type, libxl__device *= device) +{ + device->backend_devid =3D type->devid; + device->backend_domid =3D type->backend_domid; + device->backend_kind =3D LIBXL__DEVICE_KIND_GPIO; + device->devid =3D type->devid; + device->domid =3D domid; + device->kind =3D LIBXL__DEVICE_KIND_GPIO; + + return 0; +} + +int libxl_device_gpio_add(libxl_ctx *ctx, uint32_t domid, libxl_device_gpi= o *gpio, + const libxl_asyncop_how *ao_how) +{ + AO_CREATE(ctx, domid, ao_how); + int rc; + + rc =3D libxl__device_add(gc, domid, &libxl__gpio_devtype, gpio); + if (rc) { + LOGD(ERROR, domid, "Unable to add gpio device"); + goto out; + } + +out: + libxl__ao_complete(egc, ao, rc); + return AO_INPROGRESS; +} + +int libxl_devid_to_device_gpio(libxl_ctx *ctx, uint32_t domid, + int devid, libxl_device_gpio *gpio) +{ + GC_INIT(ctx); + + libxl_device_gpio *gpios =3D NULL; + int n, i; + int rc; + + libxl_device_gpio_init(gpio); + + gpios =3D libxl__device_list(gc, &libxl__gpio_devtype, domid, &n); + + if (!gpios) { rc =3D ERROR_NOTFOUND; goto out; } + + for (i =3D 0; i < n; ++i) { + if (devid =3D=3D gpios[i].devid) { + libxl_device_gpio_copy(ctx, gpio, &gpios[i]); + rc =3D 0; + goto out; + } + } + + rc =3D ERROR_NOTFOUND; + +out: + + if (gpios) + libxl__device_list_free(&libxl__gpio_devtype, gpios, n); + + GC_FREE; + return rc; +} + +int libxl_device_gpio_getinfo(libxl_ctx *ctx, uint32_t domid, + const libxl_device_gpio *gpio, + libxl_gpioinfo *info) +{ + GC_INIT(ctx); + char *libxl_path, *dompath, *devpath; + char *val; + int rc; + + libxl_gpioinfo_init(info); + dompath =3D libxl__xs_get_dompath(gc, domid); + info->devid =3D gpio->devid; + + devpath =3D libxl__domain_device_frontend_path(gc, domid, info->devid, + LIBXL__DEVICE_KIND_GPIO); + libxl_path =3D libxl__domain_device_libxl_path(gc, domid, info->devid, + LIBXL__DEVICE_KIND_GPIO); + + info->backend =3D xs_read(ctx->xsh, XBT_NULL, + GCSPRINTF("%s/backend", libxl_path), + NULL); + if (!info->backend) { rc =3D ERROR_FAIL; goto out; } + + rc =3D libxl__backendpath_parse_domid(gc, info->backend, &info->backen= d_id); + if (rc) goto out; + + val =3D libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/state", devpath)); + info->state =3D val ? strtoul(val, NULL, 10) : -1; + + info->frontend =3D xs_read(ctx->xsh, XBT_NULL, + GCSPRINTF("%s/frontend", libxl_path), + NULL); + info->frontend_id =3D domid; + + val =3D libxl__xs_read(gc, XBT_NULL, + GCSPRINTF("%s/"XENKBD_FIELD_EVT_CHANNEL, devpath)); + info->evtch =3D val ? strtoul(val, NULL, 10) : -1; + + val =3D libxl__xs_read(gc, XBT_NULL, + GCSPRINTF("%s/"XENKBD_FIELD_RING_GREF, devpath)); + info->rref =3D val ? strtoul(val, NULL, 10) : -1; + + rc =3D 0; + +out: + GC_FREE; + return rc; +} + +static LIBXL_DEFINE_UPDATE_DEVID(gpio) + +#define libxl__add_gpios NULL +#define libxl_device_gpio_compare NULL + +LIBXL_DEFINE_DEVICE_LIST(gpio) +LIBXL_DEFINE_DEVICE_REMOVE(gpio) + +DEFINE_DEVICE_TYPE_STRUCT(gpio, GPIO, gpios, + .skip_attach =3D 1, + .dm_needed =3D libxl__device_gpio_dm_needed, + .set_xenstore_config =3D (device_set_xenstore_config_fn_t) + libxl__set_xenstore_gpio, + .from_xenstore =3D (device_from_xenstore_fn_t)libxl__gpio_from_xenstore +); + +/* + * Local variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index b4dfbe7e5db1..7bbd9601ea7c 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -4001,6 +4001,7 @@ static inline int *libxl__device_type_get_num( =20 extern const libxl__device_type libxl__vfb_devtype; extern const libxl__device_type libxl__vkb_devtype; +extern const libxl__device_type libxl__gpio_devtype; extern const libxl__device_type libxl__i2c_devtype; extern const libxl__device_type libxl__disk_devtype; extern const libxl__device_type libxl__nic_devtype; diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index e9454e669224..b5a5cb99c2b4 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -266,6 +266,10 @@ libxl_vkb_backend =3D Enumeration("vkb_backend", [ (2, "LINUX") ]) =20 +libxl_gpio_backend =3D Enumeration("gpio_backend", [ + (0, "VIRTIO") + ]) + libxl_i2c_backend =3D Enumeration("i2c_backend", [ (0, "VIRTIO") ]) @@ -618,6 +622,7 @@ libxl_domain_build_info =3D Struct("domain_build_info",[ # - "mouse" for PS/2 protocol relat= ive mouse ("usbdevice", string), ("vkb_device", libxl_defbool), + ("gpio_device", libxl_defbool= ), ("i2c_device", libxl_defbool), ("soundhw", string), ("xen_platform_pci", libxl_defbool), @@ -696,6 +701,15 @@ libxl_device_vkb =3D Struct("device_vkb", [ ("multi_touch_num_contacts", uint32) ]) =20 +libxl_device_gpio =3D Struct("device_gpio", [ + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("devid", libxl_devid), + ("backend_type", libxl_gpio_backend), + ("irq", uint32), + ("base", uint64) + ]) + libxl_device_i2c =3D Struct("device_i2c", [ ("backend_domid", libxl_domid), ("backend_domname", string), @@ -974,6 +988,7 @@ libxl_domain_config =3D Struct("domain_config", [ ("dtdevs", Array(libxl_device_dtdev, "num_dtdevs")), ("vfbs", Array(libxl_device_vfb, "num_vfbs")), ("vkbs", Array(libxl_device_vkb, "num_vkbs")), + ("gpios", Array(libxl_device_gpio, "num_gpios")), ("i2cs", Array(libxl_device_i2c, "num_i2cs")), ("vtpms", Array(libxl_device_vtpm, "num_vtpms")), ("p9s", Array(libxl_device_p9, "num_p9s")), @@ -1136,6 +1151,17 @@ libxl_vkbinfo =3D Struct("vkbinfo", [ ("rref", integer) ], dir=3DDIR_OUT) =20 +libxl_gpioinfo =3D Struct("gpioinfo", [ + ("backend", string), + ("backend_id", uint32), + ("frontend", string), + ("frontend_id", uint32), + ("devid", libxl_devid), + ("state", integer), + ("evtch", integer), + ("rref", integer) + ], dir=3DDIR_OUT) + libxl_i2cinfo =3D Struct("i2cinfo", [ ("backend", string), ("backend_id", uint32), diff --git a/tools/libs/light/libxl_types_internal.idl b/tools/libs/light/l= ibxl_types_internal.idl index 1b87d1480bf9..3bb79c2a063a 100644 --- a/tools/libs/light/libxl_types_internal.idl +++ b/tools/libs/light/libxl_types_internal.idl @@ -33,6 +33,7 @@ libxl__device_kind =3D Enumeration("device_kind", [ (15, "VSND"), (16, "VINPUT"), (17, "I2C"), + (18, "GPIO"), ]) =20 libxl__console_backend =3D Enumeration("console_backend", [ diff --git a/tools/ocaml/libs/xl/genwrap.py b/tools/ocaml/libs/xl/genwrap.py index a9db0b97d80f..ffab4b362d2a 100644 --- a/tools/ocaml/libs/xl/genwrap.py +++ b/tools/ocaml/libs/xl/genwrap.py @@ -36,6 +36,7 @@ DEVICE_LIST =3D [ ("list", ["ctx", "domid"= , "t list"]), functions =3D { # ( name , [type1,type2,....] ) "device_vfb": DEVICE_FUNCTIONS, "device_vkb": DEVICE_FUNCTIONS, + "device_gpio": DEVICE_FUNCTIONS, "device_i2c": DEVICE_FUNCTIONS, "device_disk": DEVICE_FUNCTIONS + DEVICE_LIST + [ ("insert", ["ctx", "t", "domid", "?async:'= a", "unit", "unit"]), diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xen= light_stubs.c index cdf473f4ed57..0114cc22a1b6 100644 --- a/tools/ocaml/libs/xl/xenlight_stubs.c +++ b/tools/ocaml/libs/xl/xenlight_stubs.c @@ -707,6 +707,7 @@ DEVICE_ADDREMOVE(disk) DEVICE_ADDREMOVE(nic) DEVICE_ADDREMOVE(vfb) DEVICE_ADDREMOVE(vkb) +DEVICE_ADDREMOVE(gpio) DEVICE_ADDREMOVE(i2c) DEVICE_ADDREMOVE(pci) _DEVICE_ADDREMOVE(disk, cdrom, insert) diff --git a/tools/xl/Makefile b/tools/xl/Makefile index 06801962f11e..34ff203bfd86 100644 --- a/tools/xl/Makefile +++ b/tools/xl/Makefile @@ -23,7 +23,7 @@ XL_OBJS +=3D xl_vtpm.o xl_block.o xl_nic.o xl_usb.o XL_OBJS +=3D xl_sched.o xl_pci.o xl_vcpu.o xl_cdrom.o xl_mem.o XL_OBJS +=3D xl_info.o xl_console.o xl_misc.o XL_OBJS +=3D xl_vmcontrol.o xl_saverestore.o xl_migrate.o -XL_OBJS +=3D xl_vdispl.o xl_vsnd.o xl_vkb.o xl_i2c.o +XL_OBJS +=3D xl_vdispl.o xl_vsnd.o xl_vkb.o xl_gpio.o xl_i2c.o =20 $(XL_OBJS): CFLAGS +=3D $(CFLAGS_libxentoollog) $(XL_OBJS): CFLAGS +=3D $(CFLAGS_XL) diff --git a/tools/xl/xl.h b/tools/xl/xl.h index 210bc1b6d47a..b2110b125ae4 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -177,6 +177,9 @@ int main_vsnddetach(int argc, char **argv); int main_vkbattach(int argc, char **argv); int main_vkblist(int argc, char **argv); int main_vkbdetach(int argc, char **argv); +int main_gpioattach(int argc, char **argv); +int main_gpiolist(int argc, char **argv); +int main_gpiodetach(int argc, char **argv); int main_i2cattach(int argc, char **argv); int main_i2clist(int argc, char **argv); int main_i2cdetach(int argc, char **argv); diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 30bd614fc275..20bfedb74a7b 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -406,6 +406,21 @@ const struct cmd_spec cmd_table[] =3D { "Destroy a domain's virtual keyboard device", " ", }, + { "gpio-attach", + &main_gpioattach, 1, 1, + "Create a new virtual gpio device", + " ...", + }, + { "gpio-list", + &main_gpiolist, 0, 0, + "List virtual gpio devices for a domain", + "", + }, + { "gpio-detach", + &main_gpiodetach, 0, 1, + "Destroy a domain's virtual gpio device", + " ", + }, { "i2c-attach", &main_i2cattach, 1, 1, "Create a new virtual i2c device", diff --git a/tools/xl/xl_gpio.c b/tools/xl/xl_gpio.c new file mode 100644 index 000000000000..85c0b25411c7 --- /dev/null +++ b/tools/xl/xl_gpio.c @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2022 Linaro Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include + +#include +#include +#include + +#include "xl.h" +#include "xl_utils.h" +#include "xl_parse.h" + +int main_gpioattach(int argc, char **argv) +{ + int opt; + int rc; + uint32_t domid; + libxl_device_gpio gpio; + + SWITCH_FOREACH_OPT(opt, "", NULL, "gpio-attach", 2) { + /* No options */ + } + + libxl_device_gpio_init(&gpio); + domid =3D find_domain(argv[optind++]); + + for (argv +=3D optind, argc -=3D optind; argc > 0; ++argv, --argc) { + rc =3D parse_gpio_config(&gpio, *argv); + if (rc) goto out; + } + + if (dryrun_only) { + char *json =3D libxl_device_gpio_to_json(ctx, &gpio); + printf("gpio: %s\n", json); + free(json); + goto done; + } + + if (libxl_device_gpio_add(ctx, domid, &gpio, 0)) { + fprintf(stderr, "libxl_device_gpio_add failed.\n"); + rc =3D ERROR_FAIL; goto out; + } + +done: + rc =3D 0; + +out: + libxl_device_gpio_dispose(&gpio); + return rc; +} + +int main_gpiolist(int argc, char **argv) +{ + int opt; + libxl_device_gpio *gpios; + libxl_gpioinfo gpioinfo; + int nb, i; + + SWITCH_FOREACH_OPT(opt, "", NULL, "gpio-list", 1) { + /* No options */ + } + + /* Idx BE Hdl Sta evch ref ID BE-type BE-path */ + printf("%-3s %-2s %-6s %-5s %-6s %6s %-10s %-10s %-30s\n", + "Idx", "BE", "handle", "state", "evt-ch", "ref", + "ID", "BE-type", "BE-path"); + for (argv +=3D optind, argc -=3D optind; argc > 0; --argc, ++argv) { + uint32_t domid =3D find_domain(*argv); + gpios =3D libxl_device_gpio_list(ctx, domid, &nb); + if (!gpios) { + continue; + } + for (i =3D 0; i < nb; ++i) { + if (libxl_device_gpio_getinfo(ctx, domid, &gpios[i], &gpioinfo= ) =3D=3D 0) { + printf("%-3d %-2d %6d %5d %6d %6d %-10s %-30s\n", + gpioinfo.devid, gpioinfo.backend_id, + gpioinfo.devid, gpioinfo.state, gpioinfo.evtch, + gpioinfo.rref, + libxl_gpio_backend_to_string(gpios[i].backend_type), + gpioinfo.backend); + libxl_gpioinfo_dispose(&gpioinfo); + } + } + libxl_device_gpio_list_free(gpios, nb); + } + return 0; +} + +int main_gpiodetach(int argc, char **argv) +{ + uint32_t domid, devid; + int opt, rc; + libxl_device_gpio gpio; + + SWITCH_FOREACH_OPT(opt, "", NULL, "gpio-detach", 2) { + /* No options */ + } + + domid =3D find_domain(argv[optind++]); + devid =3D atoi(argv[optind++]); + + libxl_device_gpio_init(&gpio); + + if (libxl_devid_to_device_gpio(ctx, domid, devid, &gpio)) { + fprintf(stderr, "Error: Device %d not connected.\n", devid); + rc =3D ERROR_FAIL; + goto out; + } + + rc =3D libxl_device_gpio_remove(ctx, domid, &gpio, 0); + if (rc) { + fprintf(stderr, "libxl_device_gpio_remove failed.\n"); + rc =3D ERROR_FAIL; + goto out; + } + + rc =3D 0; + +out: + libxl_device_gpio_dispose(&gpio); + return rc; +} + + +/* + * Local variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 95483e551c38..7ab4f22821c4 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1204,6 +1204,74 @@ static void parse_vkb_list(const XLU_Config *config, if (rc) exit(EXIT_FAILURE); } =20 +int parse_gpio_config(libxl_device_gpio *gpio, char *token) +{ + char *oparg; + + if (MATCH_OPTION("backend", token, oparg)) { + gpio->backend_domname =3D strdup(oparg); + } else if (MATCH_OPTION("backend-type", token, oparg)) { + libxl_gpio_backend backend_type; + if (libxl_gpio_backend_from_string(oparg, &backend_type)) { + fprintf(stderr, "Unknown backend_type \"%s\" in gpio spec\n", + oparg); + return -1; + } + gpio->backend_type =3D backend_type; + } else if (MATCH_OPTION("irq", token, oparg)) { + gpio->irq =3D strtoul(oparg, NULL, 0); + } else if (MATCH_OPTION("base", token, oparg)) { + gpio->base =3D strtoul(oparg, NULL, 0); + } else { + fprintf(stderr, "Unknown string \"%s\" in gpio spec\n", token); + return -1; + } + + return 0; +} + +static void parse_gpio_list(const XLU_Config *config, + libxl_domain_config *d_config) +{ + XLU_ConfigList *gpios; + const char *item; + char *buf =3D NULL; + int rc; + + if (!xlu_cfg_get_list (config, "gpio", &gpios, 0, 0)) { + int entry =3D 0; + while ((item =3D xlu_cfg_get_listitem(gpios, entry)) !=3D NULL) { + libxl_device_gpio *gpio; + char *p; + + gpio =3D ARRAY_EXTEND_INIT(d_config->gpios, + d_config->num_gpios, + libxl_device_gpio_init); + + buf =3D strdup(item); + + p =3D strtok (buf, ","); + while (p !=3D NULL) + { + while (*p =3D=3D ' ') p++; + + rc =3D parse_gpio_config(gpio, p); + if (rc) goto out; + + p =3D strtok (NULL, ","); + } + + entry++; + } + } + + rc =3D 0; + +out: + free(buf); + if (rc) exit(EXIT_FAILURE); +} + int parse_i2c_config(libxl_device_i2c *i2c, char *token) { char *oparg; @@ -2373,15 +2441,18 @@ void parse_config_data(const char *config_source, =20 d_config->num_vfbs =3D 0; d_config->num_vkbs =3D 0; + d_config->num_gpios =3D 0; d_config->num_i2cs =3D 0; d_config->vfbs =3D NULL; d_config->vkbs =3D NULL; + d_config->gpios =3D NULL; d_config->i2cs =3D NULL; =20 if (!xlu_cfg_get_list (config, "vfb", &cvfbs, 0, 0)) { while ((buf =3D xlu_cfg_get_listitem (cvfbs, d_config->num_vfbs)) = !=3D NULL) { libxl_device_vfb *vfb; libxl_device_vkb *vkb; + libxl_device_gpio *gpio; libxl_device_i2c *i2c; =20 char *buf2 =3D strdup(buf); @@ -2393,6 +2464,9 @@ void parse_config_data(const char *config_source, vkb =3D ARRAY_EXTEND_INIT(d_config->vkbs, d_config->num_vkbs, libxl_device_vkb_init); =20 + gpio =3D ARRAY_EXTEND_INIT(d_config->gpios, d_config->num_gpio= s, + libxl_device_gpio_init); + i2c =3D ARRAY_EXTEND_INIT(d_config->i2cs, d_config->num_i2cs, libxl_device_i2c_init); =20 @@ -2653,6 +2727,7 @@ void parse_config_data(const char *config_source, if (vnc_enabled) { libxl_device_vfb *vfb; libxl_device_vkb *vkb; + libxl_device_gpio *gpio; libxl_device_i2c *i2c; =20 vfb =3D ARRAY_EXTEND_INIT(d_config->vfbs, d_config->num_vfbs, @@ -2661,6 +2736,9 @@ void parse_config_data(const char *config_source, vkb =3D ARRAY_EXTEND_INIT(d_config->vkbs, d_config->num_vkbs, libxl_device_vkb_init); =20 + gpio =3D ARRAY_EXTEND_INIT(d_config->gpios, d_config->num_gpio= s, + libxl_device_gpio_init); + i2c =3D ARRAY_EXTEND_INIT(d_config->i2cs, d_config->num_i2cs, libxl_device_i2c_init); =20 @@ -2778,6 +2856,7 @@ void parse_config_data(const char *config_source, exit(-ERROR_FAIL); } xlu_cfg_get_defbool(config, "vkb_device", &b_info->u.hvm.vkb_devic= e, 0); + xlu_cfg_get_defbool(config, "gpio_device", &b_info->u.hvm.gpio_dev= ice, 0); xlu_cfg_get_defbool(config, "i2c_device", &b_info->u.hvm.i2c_devic= e, 0); xlu_cfg_replace_string (config, "soundhw", &b_info->u.hvm.soundhw,= 0); xlu_cfg_get_defbool(config, "xen_platform_pci", @@ -2827,6 +2906,7 @@ void parse_config_data(const char *config_source, } =20 parse_vkb_list(config, d_config); + parse_gpio_list(config, d_config); parse_i2c_list(config, d_config); =20 xlu_cfg_get_defbool(config, "xend_suspend_evtchn_compat", diff --git a/tools/xl/xl_parse.h b/tools/xl/xl_parse.h index 4b972d525199..6e041abe5d50 100644 --- a/tools/xl/xl_parse.h +++ b/tools/xl/xl_parse.h @@ -36,6 +36,7 @@ int parse_nic_config(libxl_device_nic *nic, XLU_Config **= config, char *token); int parse_vdispl_config(libxl_device_vdispl *vdispl, char *token); int parse_vsnd_item(libxl_device_vsnd *vsnd, const char *spec); int parse_vkb_config(libxl_device_vkb *vkb, char *token); +int parse_gpio_config(libxl_device_gpio *gpio, char *token); int parse_i2c_config(libxl_device_i2c *i2c, char *token); =20 int match_option_size(const char *prefix, size_t len, diff --git a/tools/xl/xl_sxp.c b/tools/xl/xl_sxp.c index a44c765aa515..632e1f338d09 100644 --- a/tools/xl/xl_sxp.c +++ b/tools/xl/xl_sxp.c @@ -140,6 +140,8 @@ void printf_info_sexp(int domid, libxl_domain_config *d= _config, FILE *fh) fprintf(fh, "\t\t\t(usbdevice %s)\n", b_info->u.hvm.usbdevice); fprintf(fh, "\t\t\t(vkb_device %s)\n", libxl_defbool_to_string(b_info->u.hvm.vkb_device)); + fprintf(fh, "\t\t\t(gpio_device %s)\n", + libxl_defbool_to_string(b_info->u.hvm.gpio_device)); fprintf(fh, "\t\t\t(i2c_device %s)\n", libxl_defbool_to_string(b_info->u.hvm.i2c_device)); fprintf(fh, "\t\t)\n"); --=20 2.31.1.272.g89b43f80a514