From nobody Mon Feb 9 09:34:51 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1677517495; cv=none; d=zohomail.com; s=zohoarc; b=RJtw9eVl7UBYIL6Xrm+DkQaahERwiePj5EQn7NH9dxFakVwWBhi3+iitC1C/O7XAd5NYj5v1kyErzH1Dh/EymqI+5rFQDDCopch7OLoWEscgJ6+8rZ6LgnaFJsEWU3pPF/4ZWT3Vbq94R2u8d5OKy3ECjH9uda2qy9syDstdNEE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677517495; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=/xE0MO7gvk8G87hqdLHfxzB2p3HyKGe97WnsJLZ75BE=; b=C7//OxePZQvmsr544zsOeCaJxNafDcJAZBZ7ph/enk0bznCHug1IVpqqnVKXEQ7K06im4URmDYhNey7XcjJNKVJJEegrm+/iAW6Jeaz8BlECuwEnTrnmHZJBkFlQw8eoJUlNL6Bl0rjNJO1qKbaeG+RD39i5KZUVS98jDeDeFSk= ARC-Authentication-Results: i=1; mx.zohomail.com; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16775174949545.552027876519105; Mon, 27 Feb 2023 09:04:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pWgvf-00081a-DU; Mon, 27 Feb 2023 12:04:47 -0500 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 1pWgvd-0007pk-SR for qemu-devel@nongnu.org; Mon, 27 Feb 2023 12:04:45 -0500 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 1pWgvc-0003Jv-4e for qemu-devel@nongnu.org; Mon, 27 Feb 2023 12:04:45 -0500 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4PQRcw4v5xz6J7sd; Tue, 28 Feb 2023 01:02:24 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (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.21; Mon, 27 Feb 2023 17:04:41 +0000 To: , Michael Tsirkin , Fan Ni CC: , , Ira Weiny , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Dave Jiang Subject: [PATCH v2 3/6] bswap: Add the ability to store to an unaligned 24 bit field Date: Mon, 27 Feb 2023 17:03:08 +0000 Message-ID: <20230227170311.20054-4-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230227170311.20054-1-Jonathan.Cameron@huawei.com> References: <20230227170311.20054-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.122.247.231] X-ClientProxiedBy: lhrpeml100004.china.huawei.com (7.191.162.219) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected 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=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1677517495616100001 Content-Type: text/plain; charset="utf-8" From: Ira Weiny CXL has 24 bit unaligned fields which need to be stored to. CXL is specified as little endian. Define st24_le_p() and the supporting functions to store such a field from a 32 bit host native value. The use of b, w, l, q as the size specifier is limiting. So "24" was used for the size part of the function name. Signed-off-by: Ira Weiny Signed-off-by: Jonathan Cameron Reviewed-by: Fan Ni --- v7: - Pulled this patch out of the CXL events series as Ira pointed out it can be used to simplify this series. --- include/qemu/bswap.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h index 15a78c0db5..ee71cbeaaa 100644 --- a/include/qemu/bswap.h +++ b/include/qemu/bswap.h @@ -8,11 +8,23 @@ #undef bswap64 #define bswap64(_x) __builtin_bswap64(_x) =20 +static inline uint32_t bswap24(uint32_t x) +{ + return (((x & 0x000000ffU) << 16) | + ((x & 0x0000ff00U) << 0) | + ((x & 0x00ff0000U) >> 16)); +} + static inline void bswap16s(uint16_t *s) { *s =3D __builtin_bswap16(*s); } =20 +static inline void bswap24s(uint32_t *s) +{ + *s =3D bswap24(*s); +} + static inline void bswap32s(uint32_t *s) { *s =3D __builtin_bswap32(*s); @@ -176,6 +188,7 @@ CPU_CONVERT(le, 64, uint64_t) * size is: * b: 8 bits * w: 16 bits + * 24: 24 bits * l: 32 bits * q: 64 bits * @@ -248,6 +261,11 @@ static inline void stw_he_p(void *ptr, uint16_t v) __builtin_memcpy(ptr, &v, sizeof(v)); } =20 +static inline void st24_he_p(void *ptr, uint32_t v) +{ + __builtin_memcpy(ptr, &v, 3); +} + static inline int ldl_he_p(const void *ptr) { int32_t r; @@ -297,6 +315,11 @@ static inline void stw_le_p(void *ptr, uint16_t v) stw_he_p(ptr, le_bswap(v, 16)); } =20 +static inline void st24_le_p(void *ptr, uint32_t v) +{ + st24_he_p(ptr, le_bswap(v, 24)); +} + static inline void stl_le_p(void *ptr, uint32_t v) { stl_he_p(ptr, le_bswap(v, 32)); --=20 2.37.2