[RFC,v2,1/2] platform/x86: wmi: Allow retrieving the number of WMI object instances
Message ID | 20230426212848.108562-2-W_Armin@gmx.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp516491vqo; Wed, 26 Apr 2023 14:31:06 -0700 (PDT) X-Google-Smtp-Source: AKy350YULBfbLU20fIB0ULSkNy1u5bHFdXfXLzk9h7dNXcQYfQLCg2OpOWWwtbmI19xuFZRyDelz X-Received: by 2002:a05:6a21:100e:b0:ef:166a:acf9 with SMTP id nk14-20020a056a21100e00b000ef166aacf9mr23500008pzb.43.1682544665983; Wed, 26 Apr 2023 14:31:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682544665; cv=none; d=google.com; s=arc-20160816; b=s2cCoSqWkZL6+sS3UJqhkrzIM2EcUuDqjEmGtrx92zVTkjT8N245Oz4ZaNgUf8DoSc 7UfTHPsuhUPcyO0Oj/kBqY0tUEY++dGjGuD2kMQfXMJw9smht6uMa/fgv7Li9Xqo/A68 xza5rMtbCgwV6TdtMOyvtetfB1IEl3cZJjv/kk6a/BB4RFdtq00Bn54tuLoW99OE1N/J hEmfZhljNFYUu1LpUSbbsqrlegBx1D/8hdkQm7nCUcTliju/6MD+oUx4XjijM/PezLDq hBaHzIjtM0y2/dWoaWF6VJC9Otii/Aro0IadG44DJhbMWpU6Td6TOFnezmTgngjd4xg8 KWIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NlCtZCWJk00XcmpY7mjl7ud+19dOFERAGe9N+5rmtQ8=; b=THwsmcS0tdfLd+bmzVnOi1hr9lAWOVhkTLlyMXgt9hDe01gZOc6HpDb+NeyR2krIw4 os+O4oL/QZxhQs3e9VOAMwZmAXCspVLbKj5ll7cL2g5Mmda5qnncnQOj2k2Qy0zp/Vge 8NKlzYfKwEBHa0d3BPzVN9PHU1KUQOWTU4TNBCIFVQw0DRRdwBxRQLMxliYHL/BXB6Zk gaHTwI9XMGeLFpEyGyA7jlpYOXgCqR70gjuPxs/E+5F58kNQghIe5qkmnBZ6ubaPrz2n YquPMJxx0SGCEvk9AzQQah32rHiaH+BAQBReEUYJ3tmC4Bp36nvuo9DAC697yyDtlvoU zXGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=c+jhaqnQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t10-20020a63eb0a000000b0052069c10102si17058585pgh.75.2023.04.26.14.30.49; Wed, 26 Apr 2023 14:31:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=c+jhaqnQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239871AbjDZV3Z (ORCPT <rfc822;zxc52fgh@gmail.com> + 99 others); Wed, 26 Apr 2023 17:29:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239843AbjDZV3X (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 26 Apr 2023 17:29:23 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C77943AB3; Wed, 26 Apr 2023 14:29:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1682544537; i=w_armin@gmx.de; bh=/NvD9oCO/r0GrFnR01vAe+1hQd5sbYS115i1sHjdYVU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=c+jhaqnQYsjNniJayHeKrbysCjrX6izuZRB7X9qDmVdBKK9hpSqjEFA7rtMXwo0Wt pAqYg9mBuGr1WTvKZUGZVHu22FhInlnnyUpDC/46yQJ7iWFCewruJaovn1fXBNkzpp Vvhn4q6a4kJ9Xs/ZIuUiBCT7b1XKcyGWEYxCYMY0z7ts26Clwb7MBJBGIXg4Sr3w/w j1jOWPnfGJdfkkJ/MPjpYr4DvikFiYdxaft8Osn9IcPImU/4uZki6lYLEbowqr6wKc OUuEI9COjPM0xzlLiTB/e9MEEN72vXsEQQ6BZNP6JYApj94hAMwJSezYrNu9UgjHIi hznPILmWgMRTQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MAfUe-1pyQXR1NzE-00B300; Wed, 26 Apr 2023 23:28:57 +0200 From: Armin Wolf <W_Armin@gmx.de> To: hdegoede@redhat.com, markgross@kernel.org Cc: Mario.Limonciello@amd.com, prasanth.ksr@dell.com, jorgealtxwork@gmail.com, james@equiv.tech, Dell.Client.Kernel@dell.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC v2 1/2] platform/x86: wmi: Allow retrieving the number of WMI object instances Date: Wed, 26 Apr 2023 23:28:47 +0200 Message-Id: <20230426212848.108562-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230426212848.108562-1-W_Armin@gmx.de> References: <20230426212848.108562-1-W_Armin@gmx.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:wg2Q3rOcpLLziRjKpSU4Fquh6no2b2+fC594Er1V0xDb7k5rbuj mYlKRfhm8IkOUiLhuH6e1R3FgMSWpAVrjIgVSQc+5kTKgRVrUn3TMPj/qjbMHtB1vwNjlcx RSPDICvalGcNtRfC1EnuN98VTrfQVNajOaGGruktwHEYCX40EzQLplYXPoeqBcfn/uKavKo 4b0EwFBIz5kdq8J/oex2Q== UI-OutboundReport: notjunk:1;M01:P0:cbF/7xERkYo=;RR+7kF4mAqVLc4S8JUBV928cxmO jnOm57TuDfEcdT9cqNwdV/e2Qm1fMFg9u79C4pHM+UIqETLQdcyqSugXybiHuGNANsE84WYRT XCThlj0w0oq/AJlnZoMWK17esHgPppdTuCmMFUVHJb5Pmwynsj67EYVGCWLs21E6b6wJB8fny mFCJFxRkomudtVMWsS3Y9ZPNEnQSqxvgppnpySBAApqUZ0/ZNxnVSX6RtUWS7huPbRHqeec5W PUTuAlPGehhBVaCCtLHoCx1K+jnECI/wOObpub11oXgtqOMBJihJBvMC8RlrQ3y6axvp30Wd2 FnVYRfqZGgS3ZBYFDYZxDgIjMGtKa+RvzksMz8ny83sAl7Tdv+bykA0ueyAWh+QDhNXJjki8E jAD5To0RHOA9Oj6VL6DVdGPH8+Wf22bI2HlYBREWJ5koA7YbwA97EXaU0GgBv5/3W4E3v5PYz Wcd3jhn/pJXqaDkbLQEgNqARTnPS2Hkc+O7WdnhAYoRItZ1MISY2EFkkaQx3lbVkMP5UVa4J0 tt4QywW5mnEGlJmiI6Cy7kRnEMPHRCQMKXK5vKNshMLOr8WjJW+mOtBee0U4AAkE1NAWfSXTh sLHylac+B6xTIcCgl5BoD6mTb6wkO3aepgFx0w4oyPCgtS3/ikuMyIiOYiTsDA6x+VXH0VXUH 4GhbVEFb7we3YucdIG9sX9E0GSXavBvuold1YA8GzLCUv+5GZ0o6auhosLGyTENbASytSx8Ka X226qLP4gbrOylXiZ9Zpk40GLw/1nT3+mD7F5KYF84DpAtJT+C0oErXH08ZfbRkrBq/cU/swp fcC6icx1JqLTgUbzLKWM6g37hk4HjJawLTfiVJoGBocKb/TdcxBIcg/NIeYFtLWLMhezOgRjA WVeOHwUgSQvBqAGuUYSz8dHQPRyRnGXJePm2AIqCQuUBPq3jLnyUYFZ55l6h41mlcuwaMwkAO uEGMVvA65cQQbvsZMVFccwYOXIQ= X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764275955560859992?= X-GMAIL-MSGID: =?utf-8?q?1764275955560859992?= |
Series |
platform/x86: Allow retrieving the number of WMI object instances
|
|
Commit Message
Armin Wolf
April 26, 2023, 9:28 p.m. UTC
Currently, the WMI driver core knows how many instances of a given
WMI object exist, but WMI drivers cannot access this information.
At the same time, some current and upcoming WMI drivers want to
have access to this information. Add wmi_instance_count() and
wmidev_instance_count() to allow WMI drivers to get the number of
WMI object instances.
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
drivers/platform/x86/wmi.c | 40 ++++++++++++++++++++++++++++++++++++++
include/linux/acpi.h | 2 ++
include/linux/wmi.h | 2 ++
3 files changed, 44 insertions(+)
--
2.30.2
Comments
On Wed, Apr 26, 2023 at 11:28:47PM +0200, Armin Wolf wrote: > Currently, the WMI driver core knows how many instances of a given > WMI object exist, but WMI drivers cannot access this information. > At the same time, some current and upcoming WMI drivers want to > have access to this information. Add wmi_instance_count() and > wmidev_instance_count() to allow WMI drivers to get the number of > WMI object instances. > > Signed-off-by: Armin Wolf <W_Armin@gmx.de> Tested-by: James Seo <james@equiv.tech>
Hi Armin, Thank you for your work on this. On 4/26/23 23:28, Armin Wolf wrote: > Currently, the WMI driver core knows how many instances of a given > WMI object exist, but WMI drivers cannot access this information. > At the same time, some current and upcoming WMI drivers want to > have access to this information. Add wmi_instance_count() and > wmidev_instance_count() to allow WMI drivers to get the number of > WMI object instances. > > Signed-off-by: Armin Wolf <W_Armin@gmx.de> > --- > drivers/platform/x86/wmi.c | 40 ++++++++++++++++++++++++++++++++++++++ > include/linux/acpi.h | 2 ++ > include/linux/wmi.h | 2 ++ > 3 files changed, 44 insertions(+) > > diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c > index c226dd4163a1..7c1a904dec5f 100644 > --- a/drivers/platform/x86/wmi.c > +++ b/drivers/platform/x86/wmi.c > @@ -263,6 +263,46 @@ int set_required_buffer_size(struct wmi_device *wdev, u64 length) > } > EXPORT_SYMBOL_GPL(set_required_buffer_size); > > +/** > + * wmi_instance_count - Get number of WMI object instances > + * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba > + * @instance_count: variable to hold the instance count > + * > + * Get the number of WMI object instances. > + * > + * Returns: acpi_status signaling success or error. > + */ > +acpi_status wmi_instance_count(const char *guid_string, u8 *instance_count) > +{ > + struct wmi_block *wblock; > + acpi_status status; > + > + status = find_guid(guid_string, &wblock); > + if (ACPI_FAILURE(status)) > + return status; > + > + *instance_count = wmidev_instance_count(&wblock->dev); > + > + return AE_OK; > +} > +EXPORT_SYMBOL_GPL(wmi_instance_count); I would prefer this to have a normal kernel function prototype which returns -errno rather then returning an acpi_status. E.g. : /** * wmi_instance_count - Get number of WMI object instances * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba * * Get the number of WMI object instances. * * Returns: The number of WMI object instances, 0 if the GUID is not found. */ int wmi_instance_count(const char *guid_string) { struct wmi_block *wblock; acpi_status status; status = find_guid(guid_string, &wblock); if (ACPI_FAILURE(status)) return 0; return wmidev_instance_count(&wblock->dev); } EXPORT_SYMBOL_GPL(wmi_instance_count); This will also allow this to completely replace the get_instance_count() function in dell-wmi-sysman. Note I have just gone with always returning 0 here on error. I guess you could look at the status and return 0 for not-found and -errno for other errors but I don't think any callers will care for the difference, so just always returning 0 seems easier for callers to deal with. As always this is just a suggestion, let me know if you think this is a bad idea. Regards, Hans > + > +/** > + * wmidev_instance_count - Get number of WMI object instances > + * @wdev: A wmi bus device from a driver > + * > + * Get the number of WMI object instances. > + * > + * Returns: Number of WMI object instances. > + */ > +u8 wmidev_instance_count(struct wmi_device *wdev) > +{ > + struct wmi_block *wblock = container_of(wdev, struct wmi_block, dev); > + > + return wblock->gblock.instance_count; > +} > +EXPORT_SYMBOL_GPL(wmidev_instance_count); > + > /** > * wmi_evaluate_method - Evaluate a WMI method (deprecated) > * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba > diff --git a/include/linux/acpi.h b/include/linux/acpi.h > index efff750f326d..ab2a4b23e7a3 100644 > --- a/include/linux/acpi.h > +++ b/include/linux/acpi.h > @@ -412,6 +412,8 @@ extern bool acpi_is_pnp_device(struct acpi_device *); > > typedef void (*wmi_notify_handler) (u32 value, void *context); > > +acpi_status wmi_instance_count(const char *guid, u8 *instance_count); > + > extern acpi_status wmi_evaluate_method(const char *guid, u8 instance, > u32 method_id, > const struct acpi_buffer *in, > diff --git a/include/linux/wmi.h b/include/linux/wmi.h > index c1a3bd4e4838..763bd382cf2d 100644 > --- a/include/linux/wmi.h > +++ b/include/linux/wmi.h > @@ -35,6 +35,8 @@ extern acpi_status wmidev_evaluate_method(struct wmi_device *wdev, > extern union acpi_object *wmidev_block_query(struct wmi_device *wdev, > u8 instance); > > +u8 wmidev_instance_count(struct wmi_device *wdev); > + > extern int set_required_buffer_size(struct wmi_device *wdev, u64 length); > > /** > -- > 2.30.2 >
Am 27.04.23 um 11:43 schrieb Hans de Goede: > Hi Armin, > > Thank you for your work on this. > > On 4/26/23 23:28, Armin Wolf wrote: >> Currently, the WMI driver core knows how many instances of a given >> WMI object exist, but WMI drivers cannot access this information. >> At the same time, some current and upcoming WMI drivers want to >> have access to this information. Add wmi_instance_count() and >> wmidev_instance_count() to allow WMI drivers to get the number of >> WMI object instances. >> >> Signed-off-by: Armin Wolf <W_Armin@gmx.de> >> --- >> drivers/platform/x86/wmi.c | 40 ++++++++++++++++++++++++++++++++++++++ >> include/linux/acpi.h | 2 ++ >> include/linux/wmi.h | 2 ++ >> 3 files changed, 44 insertions(+) >> >> diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c >> index c226dd4163a1..7c1a904dec5f 100644 >> --- a/drivers/platform/x86/wmi.c >> +++ b/drivers/platform/x86/wmi.c >> @@ -263,6 +263,46 @@ int set_required_buffer_size(struct wmi_device *wdev, u64 length) >> } >> EXPORT_SYMBOL_GPL(set_required_buffer_size); >> >> +/** >> + * wmi_instance_count - Get number of WMI object instances >> + * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba >> + * @instance_count: variable to hold the instance count >> + * >> + * Get the number of WMI object instances. >> + * >> + * Returns: acpi_status signaling success or error. >> + */ >> +acpi_status wmi_instance_count(const char *guid_string, u8 *instance_count) >> +{ >> + struct wmi_block *wblock; >> + acpi_status status; >> + >> + status = find_guid(guid_string, &wblock); >> + if (ACPI_FAILURE(status)) >> + return status; >> + >> + *instance_count = wmidev_instance_count(&wblock->dev); >> + >> + return AE_OK; >> +} >> +EXPORT_SYMBOL_GPL(wmi_instance_count); > I would prefer this to have a normal kernel function prototype > which returns -errno rather then returning an acpi_status. E.g. : > > /** > * wmi_instance_count - Get number of WMI object instances > * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba > * > * Get the number of WMI object instances. > * > * Returns: The number of WMI object instances, 0 if the GUID is not found. > */ > int wmi_instance_count(const char *guid_string) > { > struct wmi_block *wblock; > acpi_status status; > > status = find_guid(guid_string, &wblock); > if (ACPI_FAILURE(status)) > return 0; > > return wmidev_instance_count(&wblock->dev); > } > EXPORT_SYMBOL_GPL(wmi_instance_count); > > This will also allow this to completely replace > the get_instance_count() function in dell-wmi-sysman. > > Note I have just gone with always returning 0 here > on error. I guess you could look at the status and > return 0 for not-found and -errno for other errors > but I don't think any callers will care for the difference, > so just always returning 0 seems easier for callers to > deal with. > > As always this is just a suggestion, let me know if > you think this is a bad idea. > > Regards, > > Hans > I like this idea. Returning a negative errno on error would allow drivers to distinguish between "WMI object not found" and "zero instances found", which might be useful for some drivers. Maybe a function for converting ACPI errors to POSIX errors already exists, otherwise i will just write one myself. Armin Wolf > >> + >> +/** >> + * wmidev_instance_count - Get number of WMI object instances >> + * @wdev: A wmi bus device from a driver >> + * >> + * Get the number of WMI object instances. >> + * >> + * Returns: Number of WMI object instances. >> + */ >> +u8 wmidev_instance_count(struct wmi_device *wdev) >> +{ >> + struct wmi_block *wblock = container_of(wdev, struct wmi_block, dev); >> + >> + return wblock->gblock.instance_count; >> +} >> +EXPORT_SYMBOL_GPL(wmidev_instance_count); >> + >> /** >> * wmi_evaluate_method - Evaluate a WMI method (deprecated) >> * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba >> diff --git a/include/linux/acpi.h b/include/linux/acpi.h >> index efff750f326d..ab2a4b23e7a3 100644 >> --- a/include/linux/acpi.h >> +++ b/include/linux/acpi.h >> @@ -412,6 +412,8 @@ extern bool acpi_is_pnp_device(struct acpi_device *); >> >> typedef void (*wmi_notify_handler) (u32 value, void *context); >> >> +acpi_status wmi_instance_count(const char *guid, u8 *instance_count); >> + >> extern acpi_status wmi_evaluate_method(const char *guid, u8 instance, >> u32 method_id, >> const struct acpi_buffer *in, >> diff --git a/include/linux/wmi.h b/include/linux/wmi.h >> index c1a3bd4e4838..763bd382cf2d 100644 >> --- a/include/linux/wmi.h >> +++ b/include/linux/wmi.h >> @@ -35,6 +35,8 @@ extern acpi_status wmidev_evaluate_method(struct wmi_device *wdev, >> extern union acpi_object *wmidev_block_query(struct wmi_device *wdev, >> u8 instance); >> >> +u8 wmidev_instance_count(struct wmi_device *wdev); >> + >> extern int set_required_buffer_size(struct wmi_device *wdev, u64 length); >> >> /** >> -- >> 2.30.2 >>
Hi, On 4/27/23 18:26, Armin Wolf wrote: > Am 27.04.23 um 11:43 schrieb Hans de Goede: > >> Hi Armin, >> >> Thank you for your work on this. >> >> On 4/26/23 23:28, Armin Wolf wrote: >>> Currently, the WMI driver core knows how many instances of a given >>> WMI object exist, but WMI drivers cannot access this information. >>> At the same time, some current and upcoming WMI drivers want to >>> have access to this information. Add wmi_instance_count() and >>> wmidev_instance_count() to allow WMI drivers to get the number of >>> WMI object instances. >>> >>> Signed-off-by: Armin Wolf <W_Armin@gmx.de> >>> --- >>> drivers/platform/x86/wmi.c | 40 ++++++++++++++++++++++++++++++++++++++ >>> include/linux/acpi.h | 2 ++ >>> include/linux/wmi.h | 2 ++ >>> 3 files changed, 44 insertions(+) >>> >>> diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c >>> index c226dd4163a1..7c1a904dec5f 100644 >>> --- a/drivers/platform/x86/wmi.c >>> +++ b/drivers/platform/x86/wmi.c >>> @@ -263,6 +263,46 @@ int set_required_buffer_size(struct wmi_device *wdev, u64 length) >>> } >>> EXPORT_SYMBOL_GPL(set_required_buffer_size); >>> >>> +/** >>> + * wmi_instance_count - Get number of WMI object instances >>> + * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba >>> + * @instance_count: variable to hold the instance count >>> + * >>> + * Get the number of WMI object instances. >>> + * >>> + * Returns: acpi_status signaling success or error. >>> + */ >>> +acpi_status wmi_instance_count(const char *guid_string, u8 *instance_count) >>> +{ >>> + struct wmi_block *wblock; >>> + acpi_status status; >>> + >>> + status = find_guid(guid_string, &wblock); >>> + if (ACPI_FAILURE(status)) >>> + return status; >>> + >>> + *instance_count = wmidev_instance_count(&wblock->dev); >>> + >>> + return AE_OK; >>> +} >>> +EXPORT_SYMBOL_GPL(wmi_instance_count); >> I would prefer this to have a normal kernel function prototype >> which returns -errno rather then returning an acpi_status. E.g. : >> >> /** >> * wmi_instance_count - Get number of WMI object instances >> * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba >> * >> * Get the number of WMI object instances. >> * >> * Returns: The number of WMI object instances, 0 if the GUID is not found. >> */ >> int wmi_instance_count(const char *guid_string) >> { >> struct wmi_block *wblock; >> acpi_status status; >> >> status = find_guid(guid_string, &wblock); >> if (ACPI_FAILURE(status)) >> return 0; >> >> return wmidev_instance_count(&wblock->dev); >> } >> EXPORT_SYMBOL_GPL(wmi_instance_count); >> >> This will also allow this to completely replace >> the get_instance_count() function in dell-wmi-sysman. >> >> Note I have just gone with always returning 0 here >> on error. I guess you could look at the status and >> return 0 for not-found and -errno for other errors >> but I don't think any callers will care for the difference, >> so just always returning 0 seems easier for callers to >> deal with. >> >> As always this is just a suggestion, let me know if >> you think this is a bad idea. >> >> Regards, >> >> Hans >> > I like this idea. Returning a negative errno on error would allow drivers to > distinguish between "WMI object not found" and "zero instances found", which > might be useful for some drivers. > > Maybe a function for converting ACPI errors to POSIX errors already exists, > otherwise i will just write one myself. Ok, that sounds good to me. I'm looking forward to a non RFC submission of these changes. Regards, Hans
diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index c226dd4163a1..7c1a904dec5f 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -263,6 +263,46 @@ int set_required_buffer_size(struct wmi_device *wdev, u64 length) } EXPORT_SYMBOL_GPL(set_required_buffer_size); +/** + * wmi_instance_count - Get number of WMI object instances + * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba + * @instance_count: variable to hold the instance count + * + * Get the number of WMI object instances. + * + * Returns: acpi_status signaling success or error. + */ +acpi_status wmi_instance_count(const char *guid_string, u8 *instance_count) +{ + struct wmi_block *wblock; + acpi_status status; + + status = find_guid(guid_string, &wblock); + if (ACPI_FAILURE(status)) + return status; + + *instance_count = wmidev_instance_count(&wblock->dev); + + return AE_OK; +} +EXPORT_SYMBOL_GPL(wmi_instance_count); + +/** + * wmidev_instance_count - Get number of WMI object instances + * @wdev: A wmi bus device from a driver + * + * Get the number of WMI object instances. + * + * Returns: Number of WMI object instances. + */ +u8 wmidev_instance_count(struct wmi_device *wdev) +{ + struct wmi_block *wblock = container_of(wdev, struct wmi_block, dev); + + return wblock->gblock.instance_count; +} +EXPORT_SYMBOL_GPL(wmidev_instance_count); + /** * wmi_evaluate_method - Evaluate a WMI method (deprecated) * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba diff --git a/include/linux/acpi.h b/include/linux/acpi.h index efff750f326d..ab2a4b23e7a3 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -412,6 +412,8 @@ extern bool acpi_is_pnp_device(struct acpi_device *); typedef void (*wmi_notify_handler) (u32 value, void *context); +acpi_status wmi_instance_count(const char *guid, u8 *instance_count); + extern acpi_status wmi_evaluate_method(const char *guid, u8 instance, u32 method_id, const struct acpi_buffer *in, diff --git a/include/linux/wmi.h b/include/linux/wmi.h index c1a3bd4e4838..763bd382cf2d 100644 --- a/include/linux/wmi.h +++ b/include/linux/wmi.h @@ -35,6 +35,8 @@ extern acpi_status wmidev_evaluate_method(struct wmi_device *wdev, extern union acpi_object *wmidev_block_query(struct wmi_device *wdev, u8 instance); +u8 wmidev_instance_count(struct wmi_device *wdev); + extern int set_required_buffer_size(struct wmi_device *wdev, u64 length); /**