From nobody Thu Sep 19 02:11:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1719323544; cv=none; d=zohomail.com; s=zohoarc; b=Cx1tFE2rPXSiMLcqE/RVZpFwD4cCHD9QD+z8f55nRosRJMPEIFy5AloQE13gqW6cEhEJfSLlSkfDRHuACW0VPZV3lOZK+THIVOn9F8P+f5nB0a4/PewhWmR0DI+F4j9ghjrFwCyjH+pkeIA0+KEiWmLN29LoSBlUXw1FySyD/eg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719323544; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1FrKnov37Nx5RTAuE+Ip2KD1aMSdkm5yA9SPDVIzLCE=; b=Ebp+MkjUSh8yhNENclqFlWZRuq4edTbAH1QB/X8Q325XR01PivVrTjN1HVMR1ykDHYi08Sfs4ZpIYnb9Mvf9cW1T68LgLPLpQY1UOSA9+xBh5WAxBG3bEaeAHwEyeaQpoLghkAyfDk/Jy/O6aXDTsmq2GnShF7MGxV0mRJvIhd4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1719323544320394.1170532719939; Tue, 25 Jun 2024 06:52:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.747733.1155211 (Exim 4.92) (envelope-from ) id 1sM6aY-0006vX-BG; Tue, 25 Jun 2024 13:52:02 +0000 Received: by outflank-mailman (output) from mailman id 747733.1155211; Tue, 25 Jun 2024 13:52:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sM6aY-0006v8-6u; Tue, 25 Jun 2024 13:52:02 +0000 Received: by outflank-mailman (input) for mailman id 747733; Tue, 25 Jun 2024 13:52:01 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sM6aW-0006cc-VQ for xen-devel@lists.xenproject.org; Tue, 25 Jun 2024 13:52:00 +0000 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [2a00:1450:4864:20::635]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1850fd4f-32fa-11ef-90a3-e314d9c70b13; Tue, 25 Jun 2024 15:52:00 +0200 (CEST) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a724440f597so358838666b.0 for ; Tue, 25 Jun 2024 06:52:00 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6fcf560627sm521042666b.148.2024.06.25.06.51.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 06:51:58 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1850fd4f-32fa-11ef-90a3-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719323519; x=1719928319; darn=lists.xenproject.org; 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=1FrKnov37Nx5RTAuE+Ip2KD1aMSdkm5yA9SPDVIzLCE=; b=QlKw80M/GeQenHK1jzsmxj83H5UC8jD3XbfcXdn+o83XjH5qL40uwkRF/jdTzigdqu lgfTTX5zq0OOMT32U7OQVRdQZ/sVhgeD7sYc8RzvW48By7dIQyOj9bSM273/npAa4M5a s2PJF88d/B8ri518IdwwumLBWISL4clgZ2LxXSFYsk6kk2yX4x+zrEIOZWVYFUr5ruaV FeUxFv/qd5NYasMC/277aRyQnkhMN0O601Ap421/LPxOUdAeiOl1KCzlG4rtXsMqUTho CtAnjQynTLpJS5ZuT3Kq5YcVbxcwRl8o62nVfaAEGuxApUt/LaOhd0BgaRgH8cmN2Bxk aUeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719323519; x=1719928319; 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=1FrKnov37Nx5RTAuE+Ip2KD1aMSdkm5yA9SPDVIzLCE=; b=hVtTvnvXCZvzhWhy8qoj6Om8IN4NqVyyXOX7x5jx80lER0FhS6OafAA7IkVyVAaTn9 BgT3GTrPyVbn5oEzBEHvD7L6FP/4gMcE0yNN6bkmvmyXBS7/TUWXEFBTyKZPkRbZN3O+ FisUiakc/cnb0MFliAmy5TM2ACwjlYrnqQ6yW01BQEjq8cjnzmkDdPWtZdyKXOOYRFK4 q6CITPQXQyoa2SB3X/2hes74SkNdy+Jz8+T/mF8gTlP6vbYmS4lzZhqKI0MQZkTr1rKf uCZcool9h05xGr7hMSgqxfbYrc1kjZUK1GSfEO9SZCgmB29vUyDqO4Bpl6/OLrHeoWBa GNIQ== X-Gm-Message-State: AOJu0YxCacodlXFFfRUxQxMvMKtnEEa1YG6op5Ht6Xr4ppm5a2u6Rabi mlu0mARkce/wpDU/2DZsqrnplSwdcXotEnNyS4Hz+YUeNwHS6DSVO7trK679 X-Google-Smtp-Source: AGHT+IEyYJALzg0VlcwOiDGXNXFNzd1AZPMr3eALpVdlpk/C3uBU/LrsMHq7/n0t5MvCLwgCV0nk1g== X-Received: by 2002:a17:907:d402:b0:a72:6849:cb21 with SMTP id a640c23a62f3a-a726849d851mr195370166b.54.1719323519249; Tue, 25 Jun 2024 06:51:59 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v13 02/10] xen/riscv: introduce bitops.h Date: Tue, 25 Jun 2024 15:51:44 +0200 Message-ID: <0e4441eee82b0545e59099e2f62e3a01fa198d08.1719319093.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1719323545647100005 Content-Type: text/plain; charset="utf-8" Taken from Linux-6.4.0-rc1 Xen's bitops.h consists of several Linux's headers: * linux/arch/include/asm/bitops.h: * The following function were removed as they aren't used in Xen: * test_and_set_bit_lock * clear_bit_unlock * __clear_bit_unlock * The following functions were renamed in the way how they are used by common code: * __test_and_set_bit * __test_and_clear_bit * The declaration and implementation of the following functios were updated to make Xen build happy: * clear_bit * set_bit * __test_and_clear_bit * __test_and_set_bit Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in V11-V13: - Nothing changed. Only rebase was done. --- Changes in V10: - update the error message BITS_PER_LONG -> BITOP_BITS_PER_WORD --- Changes in V9: - add Acked-by: Jan Beulich - drop redefinition of bitop_uint_t in asm/types.h as some operation in Xe= n common code expects to work with 32-bit quantities. - s/BITS_PER_LONG/BITOP_BITS_PER_WORD in asm/bitops.h around __AMO() macro= s. --- Changes in V8: - define bitop_uint_t in after the changes in patch related = to introduction of "introduce generic non-atomic test_*bit()". - drop duplicated __set_bit() and __clear_bit(). - drop duplicated comment: /* Based on linux/arch/include/asm/bitops.h */. - update type of res and mask in test_and_op_bit_ord(): unsigned long -> b= itop_uint_t. - drop 1 padding blank in test_and_op_bit_ord(). - update definition of test_and_set_bit(),test_and_clear_bit(),test_and_ch= ange_bit: change return type to bool. - change addr argument type of test_and_change_bit(): unsigned long * -> v= oid *. - move test_and_change_bit() closer to other test_and-s function. - Code style fixes: tabs -> space. - s/#undef __op_bit/#undef op_bit. - update the commit message: delete information about generic-non-atomic.h= changes as now it is a separate patch. --- Changes in V7: - Update the commit message. - Drop "__" for __op_bit and __op_bit_ord as they are atomic. - add comment above __set_bit and __clear_bit about why they are defined a= s atomic. - align bitops_uint_t with __AMO(). - make changes after generic non-atomic test_*bit() were changed. - s/__asm__ __volatile__/asm volatile --- Changes in V6: - rebase clean ups were done: drop unused asm-generic includes --- Changes in V5: - new patch --- xen/arch/riscv/include/asm/bitops.h | 137 ++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 xen/arch/riscv/include/asm/bitops.h diff --git a/xen/arch/riscv/include/asm/bitops.h b/xen/arch/riscv/include/a= sm/bitops.h new file mode 100644 index 0000000000..7f7af3fda1 --- /dev/null +++ b/xen/arch/riscv/include/asm/bitops.h @@ -0,0 +1,137 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2012 Regents of the University of California */ + +#ifndef _ASM_RISCV_BITOPS_H +#define _ASM_RISCV_BITOPS_H + +#include + +#if BITOP_BITS_PER_WORD =3D=3D 64 +#define __AMO(op) "amo" #op ".d" +#elif BITOP_BITS_PER_WORD =3D=3D 32 +#define __AMO(op) "amo" #op ".w" +#else +#error "Unexpected BITOP_BITS_PER_WORD" +#endif + +/* Based on linux/arch/include/asm/bitops.h */ + +/* + * Non-atomic bit manipulation. + * + * Implemented using atomics to be interrupt safe. Could alternatively + * implement with local interrupt masking. + */ +#define __set_bit(n, p) set_bit(n, p) +#define __clear_bit(n, p) clear_bit(n, p) + +#define test_and_op_bit_ord(op, mod, nr, addr, ord) \ +({ \ + bitop_uint_t res, mask; \ + mask =3D BITOP_MASK(nr); \ + asm volatile ( \ + __AMO(op) #ord " %0, %2, %1" \ + : "=3Dr" (res), "+A" (addr[BITOP_WORD(nr)]) \ + : "r" (mod(mask)) \ + : "memory"); \ + ((res & mask) !=3D 0); \ +}) + +#define op_bit_ord(op, mod, nr, addr, ord) \ + asm volatile ( \ + __AMO(op) #ord " zero, %1, %0" \ + : "+A" (addr[BITOP_WORD(nr)]) \ + : "r" (mod(BITOP_MASK(nr))) \ + : "memory"); + +#define test_and_op_bit(op, mod, nr, addr) \ + test_and_op_bit_ord(op, mod, nr, addr, .aqrl) +#define op_bit(op, mod, nr, addr) \ + op_bit_ord(op, mod, nr, addr, ) + +/* Bitmask modifiers */ +#define NOP(x) (x) +#define NOT(x) (~(x)) + +/** + * test_and_set_bit - Set a bit and return its old value + * @nr: Bit to set + * @addr: Address to count from + */ +static inline bool test_and_set_bit(int nr, volatile void *p) +{ + volatile bitop_uint_t *addr =3D p; + + return test_and_op_bit(or, NOP, nr, addr); +} + +/** + * test_and_clear_bit - Clear a bit and return its old value + * @nr: Bit to clear + * @addr: Address to count from + */ +static inline bool test_and_clear_bit(int nr, volatile void *p) +{ + volatile bitop_uint_t *addr =3D p; + + return test_and_op_bit(and, NOT, nr, addr); +} + +/** + * test_and_change_bit - Toggle (change) a bit and return its old value + * @nr: Bit to change + * @addr: Address to count from + * + * This operation is atomic and cannot be reordered. + * It also implies a memory barrier. + */ +static inline bool test_and_change_bit(int nr, volatile void *p) +{ + volatile bitop_uint_t *addr =3D p; + + return test_and_op_bit(xor, NOP, nr, addr); +} + +/** + * set_bit - Atomically set a bit in memory + * @nr: the bit to set + * @addr: the address to start counting from + * + * Note that @nr may be almost arbitrarily large; this function is not + * restricted to acting on a single-word quantity. + */ +static inline void set_bit(int nr, volatile void *p) +{ + volatile bitop_uint_t *addr =3D p; + + op_bit(or, NOP, nr, addr); +} + +/** + * clear_bit - Clears a bit in memory + * @nr: Bit to clear + * @addr: Address to start counting from + */ +static inline void clear_bit(int nr, volatile void *p) +{ + volatile bitop_uint_t *addr =3D p; + + op_bit(and, NOT, nr, addr); +} + +#undef test_and_op_bit +#undef op_bit +#undef NOP +#undef NOT +#undef __AMO + +#endif /* _ASM_RISCV_BITOPS_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.45.2