Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4729377pxb; Tue, 2 Nov 2021 14:54:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7l7BAt9WQjUtU26hr/Xw2e49FpiePmlvvnJOWK2xQvY47mgNnNZ2shjRDLgE3CKiPBNJF X-Received: by 2002:a05:6e02:20c9:: with SMTP id 9mr1336806ilq.43.1635890070507; Tue, 02 Nov 2021 14:54:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635890070; cv=none; d=google.com; s=arc-20160816; b=bJPHDwJG3Pho9V/AIYhGodGnupqeHj2BoVJmWZxbXJpFHuoM8rw9pmKmNzj2Q1Mx2c jPXhQ8v1cEw6QcnC/r+VQtuSzXEVjbg/pVQYANjQZsYrYP2xusrmeWQYEvcIzt4/xEkY vp9DQM/oS/9kVu8rxlc8SsAhHIxsoilek3da3VF2OOCrTA6OguTLLI6AdxxdQFMa8Tc5 50hhg/AR6sIxEXF0TIiEG5xWpIF4QCUJYIW+AtPV77kvcStbYjTpIaVz/aeai7MxIuEV VBf/lLD9xmxsNwsDhOdx9jumYP3FyVp+Lw5KxAawplYs4uQgke49tYpzMKL15sEs1vdr 99aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=RnYOJv9PYIDoyoec2MNj0/M0YrMLQ6W7sSkvbdM1mqI=; b=xycW1dAGuncS+HFSFm7p6qD1h7jzW++j60QVICyu97wY3i4V//CkqmyUl+xI7v3J2f jCxV9ZKJjtoBdw0c4/GwAghxACK+YzhQCAXMyLAiEz2znzFLSv2iDifRBEsOFwqo7UEC VC92jiuzNEl7cSxepogigwzwWWkSOAZiBBMKXVMU7ShKrv6kgZ1bO1LHOxW2Qg7sWxs/ qzbDcK5Yp5p5+/6tqxWckeVIdZzyXAMDjr7nhhk8RtlL0G1P906dqe5uFEzNqPf0/OyB Nnw91smDMGRj8llsZvbAAgYcfI2Kib3olJhopC5Kjd8HuObjQyUNAwchU+fNUpmBonnZ FsJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay41si251992jab.95.2021.11.02.14.54.18; Tue, 02 Nov 2021 14:54:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231380AbhKBV4B (ORCPT + 99 others); Tue, 2 Nov 2021 17:56:01 -0400 Received: from mga01.intel.com ([192.55.52.88]:56522 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231337AbhKBVz6 (ORCPT ); Tue, 2 Nov 2021 17:55:58 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10156"; a="254993994" X-IronPort-AV: E=Sophos;i="5.87,203,1631602800"; d="scan'208";a="254993994" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Nov 2021 14:53:21 -0700 X-IronPort-AV: E=Sophos;i="5.87,203,1631602800"; d="scan'208";a="500772575" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Nov 2021 14:53:21 -0700 From: ira.weiny@intel.com To: Jonathan Corbet Cc: Ira Weiny , Dave Jiang , Greg Kroah-Hartman , Dan Williams , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH 1/3] Documentation/auxiliary_bus: Clarify auxiliary_device creation Date: Tue, 2 Nov 2021 14:53:15 -0700 Message-Id: <20211102215317.3676782-2-ira.weiny@intel.com> X-Mailer: git-send-email 2.28.0.rc0.12.gb6a658bd00c9 In-Reply-To: <20211102215317.3676782-1-ira.weiny@intel.com> References: <20211102215317.3676782-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ira Weiny The documentation for creating an auxiliary device is a 3 step not a 2 step process. Specifically the requirements of setting the name, id, dev.release, and dev.parent fields was not clear as a precursor to the '2 step' process documented. Clarify by declaring this a 3 step process starting with setting the fields of struct auxiliary_device correctly. Also add some sample code and tie the change into the rest of the documentation. Reviewed-by: Dave Jiang Signed-off-by: Ira Weiny --- Documentation/driver-api/auxiliary_bus.rst | 77 +++++++++++++++++----- 1 file changed, 59 insertions(+), 18 deletions(-) diff --git a/Documentation/driver-api/auxiliary_bus.rst b/Documentation/driver-api/auxiliary_bus.rst index ef902daf0d68..8b3e795f3691 100644 --- a/Documentation/driver-api/auxiliary_bus.rst +++ b/Documentation/driver-api/auxiliary_bus.rst @@ -79,18 +79,6 @@ is given a name that, combined with the registering drivers KBUILD_MODNAME, creates a match_name that is used for driver binding, and an id that combined with the match_name provide a unique name to register with the bus subsystem. -Registering an auxiliary_device is a two-step process. First call -auxiliary_device_init(), which checks several aspects of the auxiliary_device -struct and performs a device_initialize(). After this step completes, any -error state must have a call to auxiliary_device_uninit() in its resolution path. -The second step in registering an auxiliary_device is to perform a call to -auxiliary_device_add(), which sets the name of the device and add the device to -the bus. - -Unregistering an auxiliary_device is also a two-step process to mirror the -register process. First call auxiliary_device_delete(), then call -auxiliary_device_uninit(). - .. code-block:: c struct auxiliary_device { @@ -99,15 +87,68 @@ auxiliary_device_uninit(). u32 id; }; -If two auxiliary_devices both with a match_name "mod.foo" are registered onto -the bus, they must have unique id values (e.g. "x" and "y") so that the -registered devices names are "mod.foo.x" and "mod.foo.y". If match_name + id -are not unique, then the device_add fails and generates an error message. +Registering an auxiliary_device is a three-step process. + +First, a 'struct auxiliary_device' needs to be defined or allocated for each +sub-device desired. The name, id, dev.release, and dev.parent fields of this +structure must be filled in as follows. + +The 'name' field is to be given a name that is recognized by the auxiliary +driver. If two auxiliary_devices with the same match_name, eg +"mod.MY_DEVICE_NAME", are registered onto the bus, they must have unique id +values (e.g. "x" and "y") so that the registered devices names are "mod.foo.x" +and "mod.foo.y". If match_name + id are not unique, then the device_add fails +and generates an error message. The auxiliary_device.dev.type.release or auxiliary_device.dev.release must be -populated with a non-NULL pointer to successfully register the auxiliary_device. +populated with a non-NULL pointer to successfully register the +auxiliary_device. This release call is where resources associated with the +auxiliary device must be free'ed. Because once the device is placed on the bus +the parent driver can not tell what other code may have a reference to this +data. + +The auxiliary_device.dev.parent should be set. Typically to the registering +drivers device. + +Second, call auxiliary_device_init(), which checks several aspects of the +auxiliary_device struct and performs a device_initialize(). After this step +completes, any error state must have a call to auxiliary_device_uninit() in its +resolution path. + +The third and final step in registering an auxiliary_device is to perform a +call to auxiliary_device_add(), which sets the name of the device and adds the +device to the bus. + +.. code-block:: c + + struct axiliary_device *my_aux_dev = my_aux_dev_alloc(xxx); + + /* Step 1: */ + my_aux_dev->name = MY_DEVICE_NAME; + my_aux_dev->id = my_unique_id_alloc(xxx); + my_aux_dev->dev.release = my_aux_dev_release; + my_aux_dev->dev.parent = my_dev; + + /* Step 2: */ + if (auxiliary_device_init(my_aux_dev)) + goto fail; + + /* Step 3: */ + if (auxiliary_device_add(my_aux_dev)) { + auxiliary_device_uninit(my_aux_dev); + goto fail; + } + +Unregistering an auxiliary_device is a two-step process to mirror the register +process. First call auxiliary_device_delete(), then call +auxiliary_device_uninit(). + + +.. code-block:: c + + auxiliary_device_delete(my_dev->my_aux_dev); + auxiliary_device_uninit(my_dev->my_aux_dev); -The auxiliary_device.dev.parent must also be populated. Auxiliary Device Memory Model and Lifespan ------------------------------------------ -- 2.28.0.rc0.12.gb6a658bd00c9