From nobody Fri Apr 4 05:08:08 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1742388847; cv=none; d=zohomail.com; s=zohoarc; b=DuXPFxNIWt+vt3EIb+OAA8DRSgaooUZ3lezoT6j1mqqBXgiMS5QBIZ7Ym7tnYOCONEm39WqVXBocvUKRl8fZp0kigAf9CtlI/m+g+V2fF7flE5pds3uXDY7eT7p9QKKIeduZhcEuBWkfO8EtlkmkaexxLyEPwtZRU4MisXNh9Co= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1742388847; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=TbLXloT6IlLt+KwRlJUn4y9q+aknET92PS6EnBB0tjw=; b=h2LCnJwkSpV3VKSSCywIk30LFvc7uUgxIFiW48WOOKAI9ymU6tKxNhEh6CCL21YTYiWVd8WQYdX2cXeP4oldsOt0zGnAVkN8qytUVWA0NHntG2sQHj9tYTZptXXO9lOkg3JSFtPOumC50Vl3HxSon5e6vv2T+LtojUxSLouypyw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1742388847552600.9887957381966; Wed, 19 Mar 2025 05:54:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tusrs-0000mo-B4; Wed, 19 Mar 2025 08:49:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tuoJU-0006GR-Vi; Wed, 19 Mar 2025 03:58:09 -0400 Received: from tor.source.kernel.org ([172.105.4.254]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tuoJQ-0003di-B2; Wed, 19 Mar 2025 03:58:08 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id D2B8261160; Wed, 19 Mar 2025 07:57:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id AE786C4CEF4; Wed, 19 Mar 2025 07:57:54 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A55AFC35FFF; Wed, 19 Mar 2025 07:57:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742371074; bh=pCiavkc0lCIP1XX9Y6CVBKB4HWoGnxvVV8ujV7FQAek=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=V0yTTDtb67aO3w4tLiU4f06iBiY39YbQUwU33y2IvzZzorm/g50RGOcDYHTBFxMrx kOSoi2myc/RvyO/jqVy1+N1BFYSjWxQbk+osmjtIL7kWKU5Gx8EYIR48TlpElPFa/p 1aee7YeolDyRXy6uSnj+qX2yQ9WeW9hpaQtKiFSVbU+wFq8hY6mPdoYwmQ45g4+NXz loVfGJQnRFqPzxmuDxaz99To1TfPRozQpYON9V7YJ6/PV5dWIC9TMw7S0mqeFhhFun GvxLe4ESrmE/CUfGeP3O+ovxPskRK0JqIAeaqlQWnLFsInR4ilS0b9pVC8f6Q7Xb+H 3mZelBMWsAuyg== From: Nikita Shubin via B4 Relay Date: Wed, 19 Mar 2025 10:57:54 +0300 Subject: [PATCH PoC 4/7] gpiodev: Add GPIO backend over chardev MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250319-gpiodev-v1-4-76da4e5800a1@yadro.com> References: <20250319-gpiodev-v1-0-76da4e5800a1@yadro.com> In-Reply-To: <20250319-gpiodev-v1-0-76da4e5800a1@yadro.com> To: qemu-devel@nongnu.org Cc: Linus Walleij , Bartosz Golaszewski , "Enrico Weigelt, metux IT consult" , Viresh Kumar , Eric Blake , Markus Armbruster , Michael Roth , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Eduardo Habkost , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Peter Maydell , Steven Lee , Troy Lee , Jamin Lin , Andrew Jeffery , Joel Stanley , qemu-arm@nongnu.org, Nikita Shubin , Nikita Shubin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1742371072; l=15807; i=n.shubin@yadro.com; s=20230718; h=from:subject:message-id; bh=5SgTiI0ydbYQARFNJTO+9VhaH4GQhgG0X6FDQsOgxCo=; b=9UpynEdIOObCM9wieZowdBFdaPH5tLSl2huhFW0MjhsIL4vTt/GqRF9PZSLNt+7QTe7rBaPXK gqh9X9ChwduD8EL+yS8gtXzsMSASjOhgpMTc1jo44g41GzGMqEEDMAN X-Developer-Key: i=n.shubin@yadro.com; a=ed25519; pk=vqf5YIUJ7BJv3EJFaNNxWZgGuMgDH6rwufTLflwU9ac= X-Endpoint-Received: by B4 Relay for n.shubin@yadro.com/20230718 with auth_id=161 X-Original-From: Nikita Shubin Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=172.105.4.254; envelope-from=devnull+n.shubin.yadro.com@kernel.org; helo=tor.source.kernel.org X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.332, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 19 Mar 2025 08:49:30 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: n.shubin@yadro.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1742388849388019100 From: Nikita Shubin Currently based on passing linux GPIO UAPI structs over UNIX socket. This is more a PoC than a real application, still this is something to start with. Signed-off-by: Nikita Shubin --- gpiodev/gpio-chardev.c | 479 +++++++++++++++++++++++++++++++++++++++++++++= ++++ gpiodev/meson.build | 1 + include/gpiodev/gpio.h | 2 + 3 files changed, 482 insertions(+) diff --git a/gpiodev/gpio-chardev.c b/gpiodev/gpio-chardev.c new file mode 100644 index 0000000000000000000000000000000000000000..5c2ae0373e6b447ea17ee08eacd= cb12fbaa13a9c --- /dev/null +++ b/gpiodev/gpio-chardev.c @@ -0,0 +1,479 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * QEMU GPIO Chardev based backend. + * + * Author: 2025 Nikita Shubin + * + */ +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "qemu/option.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "gpiodev/gpio.h" +#include "chardev/char.h" +#include "chardev/char-fe.h" + +#include + +/* Taken from include/linux/circ_buf.h */ + +/* + * Return count in buffer. + */ +#define CIRC_CNT(head, tail, size) (((head) - (tail)) & ((size) - 1)) + +/* + * Return space available, 0..size-1. We always leave one free char + * as a completely full buffer has head =3D=3D tail, which is the same as + * empty. + */ +#define CIRC_SPACE(head, tail, size) CIRC_CNT((tail), ((head) + 1), (size)) + +/* + * Return count up to the end of the buffer. Carefully avoid + * accessing head and tail more than once, so they can change + * underneath us without returning inconsistent results. + */ +#define CIRC_CNT_TO_END(head, tail, size) \ + ({int end =3D (size) - (tail); \ + int n =3D ((head) + end) & ((size) - 1); \ + n < end ? n : end; }) + +/* + * Return space available up to the end of the buffer. + */ +#define CIRC_SPACE_TO_END(head, tail, size) \ + ({int end =3D (size) - 1 - (head); \ + int n =3D (end + (tail)) & ((size) - 1); \ + n <=3D end ? n : end + 1; }) + + +typedef struct ChardevGpiodev { + Gpiodev parent; + + CharBackend chardev; + size_t size; + size_t prod; + size_t cons; + uint8_t *cbuf; + + struct gpio_v2_line_request last_request; + uint64_t mask; +} ChardevGpiodev; + +DECLARE_INSTANCE_CHECKER(ChardevGpiodev, GPIODEV_CHARDEV, + TYPE_GPIODEV_CHARDEV) + +static void gpio_chardev_line_event(Gpiodev *g, uint32_t offset, + QEMUGpioLineEvent event) +{ + ChardevGpiodev *d =3D GPIODEV_CHARDEV(g); + struct gpio_v2_line_event changed =3D { 0 }; + int ret; + + changed.timestamp_ns =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + changed.id =3D event; + changed.offset =3D offset; + + ret =3D qemu_chr_fe_write(&d->chardev, (uint8_t *)&changed, sizeof(cha= nged)); + if (ret !=3D sizeof(changed)) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: failed writing %d bytes\n", + __func__, ret); + } +} + +static void gpio_chardev_config_event(Gpiodev *g, uint32_t offset, + QEMUGpioConfigEvent event) +{ + ChardevGpiodev *d =3D GPIODEV_CHARDEV(g); + struct gpio_v2_line_info_changed changed =3D { 0 }; + int ret; + + changed.timestamp_ns =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + changed.event_type =3D event; + changed.info.offset =3D offset; + + ret =3D qemu_chr_fe_write(&d->chardev, (uint8_t *)&changed, sizeof(cha= nged)); + if (ret !=3D sizeof(changed)) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: failed writing %d bytes\n", + __func__, ret); + } +} + +static int gpio_chardev_can_read(void *opaque) +{ + ChardevGpiodev *s =3D GPIODEV_CHARDEV(opaque); + + return CIRC_SPACE(s->prod, s->cons, s->size); +} + +static int gpio_chardev_send_chip_info(ChardevGpiodev *d) +{ + struct gpiochip_info info =3D { 0 }; + int ret; + + qemu_gpio_chip_info(&d->parent, &info.lines, info.name, info.label); + ret =3D qemu_chr_fe_write(&d->chardev, (uint8_t *)&info, sizeof(info)); + if (ret !=3D sizeof(info)) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: failed writing %d bytes\n", + __func__, ret); + } + + return 8; +} + +static int gpio_chardev_unwatch_line(ChardevGpiodev *d, const uint8_t *buf, + size_t len) +{ + uint32_t offset; + + memcpy(&offset, &buf[8], sizeof(offset)); + qemu_gpio_clear_event_watch(&d->parent, offset, -1ULL); + + return 8 + 4; +} + +static int gpio_chardev_send_line_info(ChardevGpiodev *d, const uint8_t *b= uf, + size_t len) +{ + struct gpio_v2_line_info info =3D { 0 }; + gpio_line_info req =3D { 0 }; + int ret; + + if (len < sizeof(info) + 8) { + return -EAGAIN; + } + + memcpy(&info, &buf[8], sizeof(info)); + req.offset =3D info.offset; + qemu_gpio_line_info(&d->parent, &req); + + g_strlcpy(info.name, req.name, GPIO_MAX_NAME_SIZE); + info.flags =3D req.flags; + + ret =3D qemu_chr_fe_write(&d->chardev, (uint8_t *)&info, sizeof(info)); + if (ret !=3D sizeof(info)) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: failed writing %d bytes\n", + __func__, ret); + } + + return sizeof(info) + 8; +} + +static int gpio_chardev_line_watch(ChardevGpiodev *d, const uint8_t *buf, + size_t len) +{ + struct gpio_v2_line_info info =3D { 0 }; + int ret; + + if (len < sizeof(info) + 8) { + return -EAGAIN; + } + + memcpy(&info, &buf[8], sizeof(info)); + qemu_gpio_add_config_watch(&d->parent, info.offset); + + ret =3D qemu_chr_fe_write(&d->chardev, (uint8_t *)&info, sizeof(info)); + if (ret !=3D sizeof(info)) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: failed writing %d bytes\n", + __func__, ret); + } + + return sizeof(info) + 8; +} + +static uint64_t gpio_chardev_get_flags(const struct gpio_v2_line_request *= request) +{ + uint64_t req_flags =3D request->config.flags; + uint64_t flags =3D 0; + + if (req_flags & GPIO_V2_LINE_FLAG_EDGE_RISING) { + flags |=3D GPIO_EVENT_RISING_EDGE; + } + + if (req_flags & GPIO_V2_LINE_FLAG_EDGE_FALLING) { + flags |=3D GPIO_EVENT_FALLING_EDGE; + } + + return flags; +} + +static int gpio_chardev_line_request(ChardevGpiodev *d, const uint8_t *buf, + size_t len) +{ + struct gpio_v2_line_request *req =3D &d->last_request; + uint64_t flags; + int ret, i; + + if (len < sizeof(*req) + 8) { + return -EAGAIN; + } + + /* unwatch lines before proccessing new request */ + d->mask =3D 0; + for (i =3D 0; i < req->num_lines; i++) { + qemu_gpio_clear_event_watch(&d->parent, req->offsets[i], -1ULL); + } + + memcpy(req, &buf[8], sizeof(*req)); + flags =3D gpio_chardev_get_flags(req); + for (i =3D 0; i < req->num_lines; i++) { + qemu_gpio_add_event_watch(&d->parent, req->offsets[i], flags); + d->mask |=3D BIT_ULL(req->offsets[i]); + } + + ret =3D qemu_chr_fe_write(&d->chardev, (uint8_t *)req, sizeof(*req)); + if (ret !=3D sizeof(*req)) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: failed writing %d bytes\n", + __func__, ret); + } + + return sizeof(*req) + 8; +} + +static int gpio_chardev_get_line_values(ChardevGpiodev *d, const uint8_t *= buf, + size_t len) +{ + struct gpio_v2_line_request *req =3D &d->last_request; + struct gpio_v2_line_values values =3D { 0 }; + int ret, idx; + + if (len < (sizeof(values) + 8)) { + return -EAGAIN; + } + + memcpy(&values, &buf[8], sizeof(values)); + idx =3D find_first_bit((unsigned long *)&values.mask, req->num_lines); + while (idx < req->num_lines) { + values.bits |=3D qemu_gpio_get_line_value(&d->parent, req->offsets= [idx]); + idx =3D find_next_bit((unsigned long *)&values.mask, req->num_line= s, idx + 1); + } + + ret =3D qemu_chr_fe_write(&d->chardev, (uint8_t *)&values, sizeof(valu= es)); + if (ret !=3D sizeof(values)) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: failed writing %d bytes\n", + __func__, ret); + } + + return sizeof(values) + 8; +} + +static int gpio_chardev_set_line_values(ChardevGpiodev *d, const uint8_t *= buf, + size_t len) +{ + struct gpio_v2_line_request *req =3D &d->last_request; + struct gpio_v2_line_values values =3D { 0 }; + int ret, idx; + + if (len < sizeof(values) + 8) { + return -EAGAIN; + } + + memcpy(&values, &buf[8], sizeof(values)); + idx =3D find_first_bit((unsigned long *)&values.mask, req->num_lines); + while (idx < req->num_lines) { + qemu_gpio_set_line_value(&d->parent, req->offsets[idx], + test_bit(idx, (unsigned long *)&values.bi= ts)); + idx =3D find_next_bit((unsigned long *)&values.mask, req->num_line= s, idx + 1); + } + + ret =3D qemu_chr_fe_write(&d->chardev, (uint8_t *)&values, sizeof(valu= es)); + if (ret !=3D sizeof(values)) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: failed writing %d bytes\n", + __func__, ret); + } + + return sizeof(values) + 8; +} + +static int gpio_chardev_consume_one(ChardevGpiodev *d, const uint8_t *buf, + size_t len) +{ + unsigned long ctl; + int ret; + + if (len < 8) { + return -EAGAIN; + } + + memcpy(&ctl, buf, 8); + switch (ctl) { + case GPIO_GET_CHIPINFO_IOCTL: + ret =3D gpio_chardev_send_chip_info(d); + break; + case GPIO_GET_LINEINFO_UNWATCH_IOCTL: + ret =3D gpio_chardev_unwatch_line(d, buf, len); + break; + case GPIO_V2_GET_LINEINFO_IOCTL: + ret =3D gpio_chardev_send_line_info(d, buf, len); + break; + case GPIO_V2_GET_LINEINFO_WATCH_IOCTL: + ret =3D gpio_chardev_line_watch(d, buf, len); + break; + case GPIO_V2_GET_LINE_IOCTL: + ret =3D gpio_chardev_line_request(d, buf, len); + break; + case GPIO_V2_LINE_GET_VALUES_IOCTL: + ret =3D gpio_chardev_get_line_values(d, buf, len); + break; + case GPIO_V2_LINE_SET_VALUES_IOCTL: + ret =3D gpio_chardev_set_line_values(d, buf, len); + break; + case GPIO_V2_LINE_SET_CONFIG_IOCTL: + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: unknow ctl=3D%lx\n", + __func__, ctl); + return -EINVAL; + }; + + return ret; +} + +static void gpio_chardev_consume(ChardevGpiodev *d, size_t len) +{ + g_autofree guint8 *buf; + size_t t_cons =3D d->cons; + int i, ret, pos =3D 0; + size_t left =3D len; + + buf =3D g_malloc(len); + + for (i =3D 0; i < len && t_cons !=3D d->prod; i++) { + buf[i] =3D d->cbuf[t_cons++ & (d->size - 1)]; + } + + do { + ret =3D gpio_chardev_consume_one(d, &buf[pos], left); + if (ret > 0) { + left -=3D ret; + pos +=3D ret; + } + } while (ret > 0); + + /* advance */ + d->cons +=3D pos; + qemu_chr_fe_accept_input(&d->chardev); +} + +static void gpio_chardev_read(void *opaque, const uint8_t *buf, int len) +{ + ChardevGpiodev *d =3D GPIODEV_CHARDEV(opaque); + int i; + + if (!buf || (len < 0)) { + return; + } + + for (i =3D 0; i < len; i++) { + d->cbuf[d->prod++ & (d->size - 1)] =3D buf[i]; + if (d->prod - d->cons > d->size) { + d->cons =3D d->prod - d->size; + } + } + + gpio_chardev_consume(d, CIRC_CNT(d->prod, d->cons, d->size)); +} + +static void gpio_chardev_event(void *opaque, QEMUChrEvent event) +{ + ChardevGpiodev *d =3D GPIODEV_CHARDEV(opaque); + + if (event =3D=3D CHR_EVENT_OPENED) { + d->prod =3D 0; + d->cons =3D 0; + + /* remove watches */ + qemu_gpio_clear_watches(&d->parent); + } +} + +static void gpio_chardev_open(Gpiodev *gpio, GpiodevBackend *backend, + Error **errp) +{ + GpiodevChardev *opts =3D backend->u.chardev.data; + ChardevGpiodev *d =3D GPIODEV_CHARDEV(gpio); + Object *chr_backend; + Chardev *chr =3D NULL; + + d->size =3D opts->has_size ? opts->size : 65536; + + /* The size must be power of 2 */ + if (d->size & (d->size - 1)) { + error_setg(errp, "size of ringbuf chardev must be power of two"); + return; + } + + chr_backend =3D object_resolve_path_type(opts->chardev, TYPE_CHARDEV, = NULL); + if (chr_backend) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: %s got backend\n", + __func__, opts->chardev); + chr =3D qemu_chr_find(opts->chardev); + } + + if (!chr) { + error_setg(errp, "gpiodev: chardev: no chardev %s not found", opts= ->chardev); + return; + } + + d->cbuf =3D g_malloc0(d->size); + + qemu_chr_fe_init(&d->chardev, chr, NULL); + qemu_chr_fe_set_handlers(&d->chardev, + gpio_chardev_can_read, + gpio_chardev_read, + gpio_chardev_event, NULL, d, NULL, true); +} + +static void gpio_chardev_parse(QemuOpts *opts, GpiodevBackend *backend, + Error **errp) +{ + const char *chardev =3D qemu_opt_get(opts, "chardev"); + GpiodevChardev *gchardev; + int val; + + if (chardev =3D=3D NULL) { + error_setg(errp, "gpiodev: chardev: no chardev id given"); + return; + } + + backend->type =3D GPIODEV_BACKEND_KIND_CHARDEV; + gchardev =3D backend->u.chardev.data =3D g_new0(GpiodevChardev, 1); + val =3D qemu_opt_get_size(opts, "size", 0); + if (val !=3D 0) { + gchardev->has_size =3D true; + gchardev->size =3D val; + } + gchardev->chardev =3D g_strdup(chardev); +} + +static void gpio_chardev_finalize(Object *obj) +{ + ChardevGpiodev *d =3D GPIODEV_CHARDEV(obj); + + g_free(d->cbuf); +} + +static void gpio_chardev_class_init(ObjectClass *oc, void *data) +{ + GpiodevClass *cc =3D GPIODEV_CLASS(oc); + + cc->parse =3D &gpio_chardev_parse; + cc->open =3D &gpio_chardev_open; + cc->line_event =3D &gpio_chardev_line_event; + cc->config_event =3D &gpio_chardev_config_event; +} + +static const TypeInfo gpio_chardev_type_info[] =3D { + { + .name =3D TYPE_GPIODEV_CHARDEV, + .parent =3D TYPE_GPIODEV, + .class_init =3D gpio_chardev_class_init, + .instance_size =3D sizeof(ChardevGpiodev), + .instance_finalize =3D gpio_chardev_finalize, + }, +}; + +DEFINE_TYPES(gpio_chardev_type_info); + diff --git a/gpiodev/meson.build b/gpiodev/meson.build index 0c7e457a11a6b01ec675006ae11ce0c50356407e..64d3abb4e3d72cba0c26b665515= a0f97e82fb5d9 100644 --- a/gpiodev/meson.build +++ b/gpiodev/meson.build @@ -1,4 +1,5 @@ gpiodev_ss.add(files( + 'gpio-chardev.c', 'gpio-fe.c', 'gpio.c', )) diff --git a/include/gpiodev/gpio.h b/include/gpiodev/gpio.h index 2ea6c0e6af8125caacc944cdddca94b1bca8c4ff..a34d805ccc0bf5a25986b118dcc= 0b2cc0a55572c 100644 --- a/include/gpiodev/gpio.h +++ b/include/gpiodev/gpio.h @@ -55,6 +55,8 @@ struct Gpiodev { #define TYPE_GPIODEV "gpiodev" OBJECT_DECLARE_TYPE(Gpiodev, GpiodevClass, GPIODEV) =20 +#define TYPE_GPIODEV_CHARDEV "gpiodev-chardev" + struct GpiodevClass { ObjectClass parent_class; =20 --=20 2.45.2