Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp6196508ybv; Wed, 12 Feb 2020 07:44:50 -0800 (PST) X-Google-Smtp-Source: APXvYqz+gPnlZh4B/+3EGWPNbJmg80kyXBPN92YnMW0y8EQu4Gm+LlQC6PPKX4b7lDUB0ePO54JS X-Received: by 2002:a9d:7e99:: with SMTP id m25mr9499579otp.212.1581522289951; Wed, 12 Feb 2020 07:44:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581522289; cv=none; d=google.com; s=arc-20160816; b=Fw/fC1wyWZlf5rpHSsZUoaE/kSxQY463rdeodiaCAUt+VvlVI/E8QSycyaKqXYH3Fc UM8AUi9AVCQZviTGZyqpZ6eDx3eu5m7gz6IO+QkTTCyJSiyxmZ6n47f8zT7lyQ/xbRY4 t1Ai2DDim1O3gX/8ZhDEkTE0Er9ADp1bc7upERMaOWu5pdsWTyXZXfgT+qyNgRhElBjm unxA0bM01O2BXfOiWfhqYCc8ROVXyCTJWXw55mGkCnVNcA33n/8xgT6ia5m+ARlfahBr MTPskf73meDo/nbQsuUGd53r/ViievHTOnfwdLJCuHPvk8fjavOGdDhEupaSgz6uaHTP gIXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BRco9JsmCdsskPKJMJX6LKetEjtGtQ7ZxpHTF2nQDdU=; b=GCfLlKzKmyqE4BYq9OZJhKVai+22iRqcr1RLwoWkgkc3quJPL3HQo5ZjYw3OHIL2lg BPh1n0EPm1rPkJSDaFCKeoqbeCQqnD5+WE8jo85xiBk7NhZE+flYEb2ZE4zU2iqbjyN3 Fc4ibdglSFms2lW6lHGrUXs9hw663lHaL2emwaL7M4AxXGvervU9Qu3VLF5NJ2a9tCY2 B+xICFSi8Djb3+2URG2o8kRISusnVDX9dQPRpiS/qSMLt71Vtpr0wVgeOEDLeBLrm33V ulHB4dosQIxU8BOo3mCwmZ/VKXTGlH03CUA1LqdoxLV1vXPqDtQC3L4GVYmKTfN0YcRB oVUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@monstr-eu.20150623.gappssmtp.com header.s=20150623 header.b=rBOM5vGA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h2si3310273oie.151.2020.02.12.07.44.37; Wed, 12 Feb 2020 07:44:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@monstr-eu.20150623.gappssmtp.com header.s=20150623 header.b=rBOM5vGA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728632AbgBLPmn (ORCPT + 99 others); Wed, 12 Feb 2020 10:42:43 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36711 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728599AbgBLPmm (ORCPT ); Wed, 12 Feb 2020 10:42:42 -0500 Received: by mail-wr1-f66.google.com with SMTP id z3so2954976wru.3 for ; Wed, 12 Feb 2020 07:42:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BRco9JsmCdsskPKJMJX6LKetEjtGtQ7ZxpHTF2nQDdU=; b=rBOM5vGAEp7eYFE0Gflw+2hMyhFIG78V87Z7f3IBSobwMnUriX3HWpBH2zAVvUAnBV H1keqxl6PhrbT+RXAFk9aTBcaVIUqvaXWIhX8oCxsT/rK1GpBMY3p2hpo9vXD7ZyrMRn 9QpKUmbcOYdA27PSd7aR/oAPnDXrQkmmLK06u8PjwajtCL6pclqyHgGo6h4jxLkmvpkl nxGZTEWZguphilCSWQtc/KTPtHLI+ERHG36YTJ2aMPY1ZAWDeB/H4nOak/jU8EsIclud J55Z/yfca4BZdcGKtifHkXiA4BYkHDwyxMyx/iixxdMrKeKt9Cms1E0IBIaSQpw4Mggx aT4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=BRco9JsmCdsskPKJMJX6LKetEjtGtQ7ZxpHTF2nQDdU=; b=RO7Jku+aXqZDI9B0yZ9KjsQHJVy3fvk8KS49wJf8vP2r2YlhYuf0n/l4URlyb8Ttxq 6JnV1vG2uPTg+9tOTs03to808hePk9YC7rJPESQqY9/arfKIrF4e/U07SZzm4xpNX3Wd jN/MciYuCAC3jqSw/XQcW/HnYdW0BXlE1r2VboP+N7HFNQK8j9QhkfUSyXg6MwADQrf3 UPFHTM5jaFLGg0zc8k5qrsz8JgNLHApHeNlT8eCEoaYfbyDvmYgpWjdtQnj6xf0ADDXZ SJQCOwjtA/jLgNbpb1AqoM3bYTxj2xv+FjlaOLEANiR0ZOcmqX0jwd75kbEwCwRCthUX 1eVw== X-Gm-Message-State: APjAAAW5+T79Ba7lBMZwa/JV33BEhMn6H3yt3oqw87KFWDys7Rfu+yp2 RkT2qYqe2UreB0F4ardDl89ZQvRQNz2wS/Yn X-Received: by 2002:a5d:62c8:: with SMTP id o8mr15620215wrv.316.1581522159301; Wed, 12 Feb 2020 07:42:39 -0800 (PST) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id q3sm1110916wmj.38.2020.02.12.07.42.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Feb 2020 07:42:38 -0800 (PST) From: Michal Simek To: linux-kernel@vger.kernel.org, monstr@monstr.eu, michal.simek@xilinx.com, git@xilinx.com, arnd@arndb.de Cc: Stefan Asserhall Subject: [PATCH 4/7] microblaze: Add SMP implementation of xchg and cmpxchg Date: Wed, 12 Feb 2020 16:42:26 +0100 Message-Id: X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stefan Asserhall Microblaze support only 32bit loads and stores that's why only 4 byte operations are supported by SMP. Signed-off-by: Stefan Asserhall Signed-off-by: Michal Simek --- arch/microblaze/include/asm/cmpxchg.h | 87 +++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/arch/microblaze/include/asm/cmpxchg.h b/arch/microblaze/include/asm/cmpxchg.h index 3523b51aab36..0c24ac37df7f 100644 --- a/arch/microblaze/include/asm/cmpxchg.h +++ b/arch/microblaze/include/asm/cmpxchg.h @@ -4,6 +4,93 @@ #ifndef CONFIG_SMP # include +#else + +extern void __xchg_called_with_bad_pointer(void); + +static inline unsigned long __xchg_u32(volatile void *p, unsigned long val) +{ + unsigned long prev, temp; + + __asm__ __volatile__ ( + /* load conditional address in %3 to %0 */ + "1: lwx %0, %3, r0;\n" + /* attempt store of new value */ + " swx %4, %3, r0;\n" + /* checking msr carry flag */ + " addic %1, r0, 0;\n" + /* store failed (MSR[C] set)? try again */ + " bnei %1, 1b;\n" + /* Outputs: result value */ + : "=&r" (prev), "=&r" (temp), "+m" (*(volatile unsigned int *)p) + /* Inputs: counter address */ + : "r" (p), "r" (val) + : "cc", "memory" + ); + + return prev; +} + +static inline unsigned long __xchg(unsigned long x, volatile void *ptr, + int size) +{ + if (size == 4) + return __xchg_u32(ptr, x); + + __xchg_called_with_bad_pointer(); + return x; +} + +#define xchg(ptr, x) ({ \ + ((__typeof__(*(ptr))) \ + __xchg((unsigned long)(x), (ptr), sizeof(*(ptr)))); \ +}) + +static inline unsigned long __cmpxchg_u32(volatile unsigned int *p, + unsigned long old, unsigned long new) +{ + int result, tmp; + + __asm__ __volatile__ ( + /* load conditional address in %3 to %0 */ + "1: lwx %0, %3, r0;\n" + /* compare loaded value with old value */ + " cmp %2, %0, %4;\n" + /* not equal to old value, write old value */ + " bnei %2, 2f;\n" + /* attempt store of new value*/ + " swx %5, %3, r0;\n" + /* checking msr carry flag */ + " addic %2, r0, 0;\n" + /* store failed (MSR[C] set)? try again */ + " bnei %2, 1b;\n" + "2: " + /* Outputs : result value */ + : "=&r" (result), "+m" (*p), "=&r" (tmp) + /* Inputs : counter address, old, new */ + : "r" (p), "r" (old), "r" (new), "r" (&tmp) + : "cc", "memory" + ); + + return result; +} + +static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, + unsigned long new, unsigned int size) +{ + if (size == 4) + return __cmpxchg_u32(ptr, old, new); + + __xchg_called_with_bad_pointer(); + return old; +} + +#define cmpxchg(ptr, o, n) ({ \ + ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \ + (unsigned long)(n), sizeof(*(ptr)))); \ +}) + + #endif #endif /* _ASM_MICROBLAZE_CMPXCHG_H */ -- 2.25.0