From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5CB96C83F2C for ; Tue, 5 Sep 2023 14:57:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qdXU2-0002rU-4d; Tue, 05 Sep 2023 10:56:50 -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 1qdXTz-0002rL-Km for qemu-devel@nongnu.org; Tue, 05 Sep 2023 10:56:47 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qdXTw-0005cu-D6 for qemu-devel@nongnu.org; Tue, 05 Sep 2023 10:56:47 -0400 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Rg7l138Vdz6J7pN; Tue, 5 Sep 2023 22:52:13 +0800 (CST) Received: from localhost (10.122.247.231) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 5 Sep 2023 15:56:40 +0100 Date: Tue, 5 Sep 2023 15:56:39 +0100 To: Philippe =?ISO-8859-1?Q?Mathieu-Daud=E9?= CC: , Michael Tsirkin , Fan Ni , , Dave Jiang , Subject: Re: [PATCH 1/2] hw/cxl: Add utility functions decoder interleave ways and target count. Message-ID: <20230905155639.00000b3a@huawei.com> In-Reply-To: <89d5477c-ece0-b738-c64f-056242619d92@linaro.org> References: <20230904164704.18739-1-Jonathan.Cameron@huawei.com> <20230904164704.18739-2-Jonathan.Cameron@huawei.com> <89d5477c-ece0-b738-c64f-056242619d92@linaro.org> Organization: Huawei Technologies R&D (UK) Ltd. X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.29; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.122.247.231] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected Received-SPF: pass client-ip=185.176.79.56; envelope-from=jonathan.cameron@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: , Reply-to: Jonathan Cameron From: Jonathan Cameron via Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On Mon, 4 Sep 2023 20:26:59 +0200 Philippe Mathieu-Daud=E9 wrote: > On 4/9/23 18:47, Jonathan Cameron wrote: > > As an encoded version of these key configuration parameters is > > a register, provide functions to extract it again so as to avoid > > the need for duplicating the storage. > >=20 > > Signed-off-by: Jonathan Cameron > > --- > > include/hw/cxl/cxl_component.h | 14 ++++++++++++++ > > hw/cxl/cxl-component-utils.c | 17 +++++++++++++++++ > > 2 files changed, 31 insertions(+) > >=20 > > diff --git a/include/hw/cxl/cxl_component.h b/include/hw/cxl/cxl_compon= ent.h > > index 42c7e581a7..f0ad9cf7de 100644 > > --- a/include/hw/cxl/cxl_component.h > > +++ b/include/hw/cxl/cxl_component.h > > @@ -238,7 +238,21 @@ static inline int cxl_decoder_count_enc(int count) > > return 0; > > } > > =20 > > +static inline int cxl_decoder_count_dec(int enc_cnt) > > +{ > > + switch (enc_cnt) { > > + case 0: return 1; > > + case 1: return 2; > > + case 2: return 4; > > + case 3: return 6; > > + case 4: return 8; > > + case 5: return 10; > > + } > > + return 0; > > +} =20 >=20 > Why inline? >=20 Bad habit. > Alternatively: >=20 > unsigned cxl_decoder_count_dec(unsigned enc_cnt) > { > return enc_cnt <=3D 5 ? 2 * enc_cnt : 0; It gets a little more fiddly than the code I'm proposing implies. For Switches and Host Bridges larger values are defined (we just don't emulate them yet and may never do so) and those don't have a sensible mapping.=20 I guess there is no harm in adding the full decode however which will make it more obvious why it was a switch statement. > } >=20 >=20