From patchwork Fri Jun 23 12:21:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 695259 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp1925093wrm; Fri, 23 Jun 2023 05:34:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7YX8tezHpRdvzNuclKaKPAEEBsy5awwXuXAbYsn2FEQV/IJu6ztDUNCT9LB/AR4JxljIZu X-Received: by 2002:a05:6214:411c:b0:62f:ebc4:89b7 with SMTP id kc28-20020a056214411c00b0062febc489b7mr22880342qvb.26.1687523647784; Fri, 23 Jun 2023 05:34:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687523647; cv=none; d=google.com; s=arc-20160816; b=D/2JLHkgBcdzCyb0EGJPrtRgte02FiMRGdirNhkabEtbX33XNXO5YY//Sg/uVe+Kmj zKCcKWZKB+MKnlgGS5LNN9QK+fnGV+N5zpuxdKIIyKfuz1eb6mY9jkKDv1JfnFE3T8ut nTe7u69Z+dOvfKPzF5w0DnciNuMMqLVCsI4KIMyiWcSmbJJrEz6qzbqerJgdLuU4bghz rdqCfVKoiGg/u+lhD/c2+DAid898naN9EhH0NqbYYCYyTiIhTKJYWfgnr4gHnXrJ9Wez mKx3DYt0WxpjGz7pRm+kBBAJ9yuqRIFhhsbRyXKJIuOTJICN13UAuYYLdIxHSl8p+hgd ZBEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=z+Ft1R3JBDSn9JTJ33FIkeeIZZV1IyyGZBrwy7UUFlQ=; b=QJ+TlSgfokhdyziZ1V8WO6WhZWQj2sN2Ti3fPxZ8rndW0/BJxDVJ3LHiMvj2SQ9QqU 4/ltRjAaqbOxNdSHVdYKtjq4vH8mf5h5nxwU5sTyLhDB4ZQj5b5zWt09zO7IYANpigwZ jTm7ktEEFKbD3Olnft66dxycTDLBOYXhOdH+2tFv+38UTT+P18QQGvcOKUGLgiz6Uxl6 RgeCBh7/D3ffktnzCHg8jSG4juuWYlIRDTemb1thMVZPoRVKETMeZJzPa60mp5vVyAJl 2F703NwiLbtDCnWc489tsSCbPqH3Rf+unk3sJMEGJMnmuMQsZMEkXgX0laCE981XJVwL Kgrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UrZpQuhJ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g5-20020a0562141cc500b00631e793b9dcsi3616192qvd.541.2023.06.23.05.34.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Jun 2023 05:34:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UrZpQuhJ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCfwe-0001Kp-C0; Fri, 23 Jun 2023 08:31:20 -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 1qCfwJ-0001AR-Sp for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:31:01 -0400 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qCfwC-0000Tw-Nq for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:30:57 -0400 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-4f86bc35f13so730075e87.1 for ; Fri, 23 Jun 2023 05:30:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687523451; x=1690115451; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=z+Ft1R3JBDSn9JTJ33FIkeeIZZV1IyyGZBrwy7UUFlQ=; b=UrZpQuhJ+ELEtNGXLL+z+JySVvPbOrVLnheKfv0tZpfAEc4bttSAfyN5sp1TfFEy94 bR/7Ge85dIuxeFwTrYTkfvwRzEiqbMOxjiH+b7CQOSNVGwkzt96+s8f7gDllq0x7D0+P HNlt+/ykaqZ2Akdl5cnjLglFlppu64x7OMCiM5NB4PFfTWxlaRBWvzE1sIng6Ovr7i47 0FKZDSJvZ5ERU3dZhBrB6Rfc+MDALLdfnpGY68Uq4iFpBIMY33H1s9SDBxH04VzDo8JX lKOAMQTn1CVdYx9OOj3xggbWREqfBK2qigxbCAFmf61rLC+dRlsukZ+pWFroD16b7PHQ DgGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687523451; x=1690115451; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z+Ft1R3JBDSn9JTJ33FIkeeIZZV1IyyGZBrwy7UUFlQ=; b=MCljgqjY68fAl6M2WIUTpswihzvwxZLXfi2kqNHIt7iJGOp/9mNJl2iJQrfgwwMYaF FMFkfzX92hVM3q00gre7G/iv7oSo3nHgKEVxuv7jz22el4tjLuXIzG4PgQFuQ7EwwoFt uWEzMX8H4L6mH3uNTUVY3w1Vy5z5xK2k35dv7em9xNHJ15rh0sn5G+4YAL+Dseo2kqRl 0Omigfs38b/na2hmdKBfpHRc98gTuKj7gEWxuv4z7aHYNFfeKrvYhap8eWxWCt7QHYhq yDqeuXQhT40TQjkqpHEMIN+Cv7YEqeMp5ZNH/x5EuiWhJaFVitP2+ZcycpDWxrz2TgNk asrQ== X-Gm-Message-State: AC+VfDwJ3nFmBE/jh11GWraCerzqX2g09fBgQF3sInGyn6YnJY6/wVWX nx+wtXz7r8EbjDeHeDx7sqDhrQ== X-Received: by 2002:a19:e602:0:b0:4f9:5781:862a with SMTP id d2-20020a19e602000000b004f95781862amr5631412lfh.38.1687523450939; Fri, 23 Jun 2023 05:30:50 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 12-20020a05600c020c00b003f9bd9e3226sm2261931wmi.7.2023.06.23.05.30.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 05:30:50 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id A2DC31FFCF; Fri, 23 Jun 2023 13:21:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , Juan Quintela , Peter Maydell , Cleber Rosa , Darren Kenny , Alexandre Iooss , Peter Xu , qemu-arm@nongnu.org, Eduardo Habkost , Riku Voipio , Mahmoud Mandour , =?utf-8?q?Daniel_P=2E_Berrang?= =?utf-8?q?=C3=A9?= , Paolo Bonzini , Bandan Das , Marcin Juszkiewicz , Radoslaw Biernacki , Alexander Bulekov , Leif Lindholm , Qiuhao Li , Wainer dos Santos Moschetta , Marcel Apfelbaum , Leonardo Bras , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , Bin Meng , Thomas Huth , Beraldo Leal , Laurent Vivier , Yanan Wang , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH 26/26] docs/devel: introduce some key concepts for QOM development Date: Fri, 23 Jun 2023 13:21:00 +0100 Message-Id: <20230623122100.1640995-27-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230623122100.1640995-1-alex.bennee@linaro.org> References: <20230623122100.1640995-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12d; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x12d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Using QOM correctly is increasingly important to maintaining a modern code base. However the current documentation skips some important concepts before launching into a simple example. Lets: - at least mention properties - mention TYPE_OBJECT and TYPE_DEVICE - talk about why we have realize/unrealize - mention the QOM tree Signed-off-by: Alex Bennée Message-Id: <20230619171437.357374-6-alex.bennee@linaro.org> --- docs/devel/qom.rst | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/docs/devel/qom.rst b/docs/devel/qom.rst index c342ce18e3..0113afb6e6 100644 --- a/docs/devel/qom.rst +++ b/docs/devel/qom.rst @@ -13,6 +13,53 @@ features: - System for dynamically registering types - Support for single-inheritance of types - Multiple inheritance of stateless interfaces +- Mapping internal members to publicly exposed properties + +The root object class is TYPE_OBJECT which provides for the basic +object methods. + +The Device Class +================ + +The TYPE_DEVICE class is the parent class for all modern devices +implemented in QEMU and adds some specific methods to handle QEMU +device model. This includes managing the lifetime of devices from +creation through to when they become visible to the guest and +eventually unrealized. + +Device Life-cycle +----------------- + +As class initialisation cannot fail devices have an two additional +methods to handle the creation of dynamic devices. The ``realize`` +function is called with ``Error **`` pointer which should be set if +the device cannot complete its setup. Otherwise on successful +completion of the ``realize`` method the device object is added to the +QOM tree and made visible to the guest. + +The reverse function is ``unrealize`` and should be were clean-up +code lives to tidy up after the system is done with the device. + +All devices can be instantiated by C code, however only some can +created dynamically via the command line or monitor. Likewise only +some can be unplugged after creation and need an explicit +``unrealize`` implementation. This is determined by the +``user_creatable`` and ``hotpluggable`` variables in the root +``DeviceClass`` structure. + +The QOM tree +------------ + +The QOM tree is a composition tree which represents all of the objects +that make up a QEMU "machine". You can view this tree by running +``info qom-tree`` in the :ref:`QEMU monitor`. It will contain both +objects created by the machine itself as well those created due to +user configuration. + +Creating a minimal device +========================= + +A simple minimal device implementation may look something like bellow: .. code-block:: c :caption: Creating a minimal type