All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 10/20] x86: Add atomic operations
Date: Mon, 27 Apr 2015 16:48:13 -0600	[thread overview]
Message-ID: <1430174911-27538-11-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1430174911-27538-1-git-send-email-sjg@chromium.org>

Add a subset of this header file from Linux 4.0 to support atomic operations
in U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/x86/include/asm/atomic.h | 115 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 115 insertions(+)
 create mode 100644 arch/x86/include/asm/atomic.h

diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
new file mode 100644
index 0000000..806f787
--- /dev/null
+++ b/arch/x86/include/asm/atomic.h
@@ -0,0 +1,115 @@
+#ifndef _ASM_X86_ATOMIC_H
+#define _ASM_X86_ATOMIC_H
+
+#include <linux/compiler.h>
+#include <linux/types.h>
+#include <asm/processor.h>
+
+typedef struct { volatile int counter; } atomic_t;
+
+/*
+ * Atomic operations that C can't guarantee us.  Useful for
+ * resource counting etc..
+ */
+
+#define ATOMIC_INIT(i)	{ (i) }
+
+/**
+ * atomic_read - read atomic variable
+ * @v: pointer of type atomic_t
+ *
+ * Atomically reads the value of @v.
+ */
+static inline int atomic_read(const atomic_t *v)
+{
+	return ACCESS_ONCE((v)->counter);
+}
+
+/**
+ * atomic_set - set atomic variable
+ * @v: pointer of type atomic_t
+ * @i: required value
+ *
+ * Atomically sets the value of @v to @i.
+ */
+static inline void atomic_set(atomic_t *v, int i)
+{
+	v->counter = i;
+}
+
+/**
+ * atomic_add - add integer to atomic variable
+ * @i: integer value to add
+ * @v: pointer of type atomic_t
+ *
+ * Atomically adds @i to @v.
+ */
+static inline void atomic_add(int i, atomic_t *v)
+{
+	asm volatile(LOCK_PREFIX "addl %1,%0"
+		     : "+m" (v->counter)
+		     : "ir" (i));
+}
+
+/**
+ * atomic_sub - subtract integer from atomic variable
+ * @i: integer value to subtract
+ * @v: pointer of type atomic_t
+ *
+ * Atomically subtracts @i from @v.
+ */
+static inline void atomic_sub(int i, atomic_t *v)
+{
+	asm volatile(LOCK_PREFIX "subl %1,%0"
+		     : "+m" (v->counter)
+		     : "ir" (i));
+}
+
+/**
+ * atomic_inc - increment atomic variable
+ * @v: pointer of type atomic_t
+ *
+ * Atomically increments @v by 1.
+ */
+static inline void atomic_inc(atomic_t *v)
+{
+	asm volatile(LOCK_PREFIX "incl %0"
+		     : "+m" (v->counter));
+}
+
+/**
+ * atomic_dec - decrement atomic variable
+ * @v: pointer of type atomic_t
+ *
+ * Atomically decrements @v by 1.
+ */
+static inline void atomic_dec(atomic_t *v)
+{
+	asm volatile(LOCK_PREFIX "decl %0"
+		     : "+m" (v->counter));
+}
+
+/**
+ * atomic_inc_short - increment of a short integer
+ * @v: pointer to type int
+ *
+ * Atomically adds 1 to @v
+ * Returns the new value of @u
+ */
+static inline short int atomic_inc_short(short int *v)
+{
+	asm(LOCK_PREFIX "addw $1, %0" : "+m" (*v));
+	return *v;
+}
+
+/* These are x86-specific, used by some header files */
+#define atomic_clear_mask(mask, addr)				\
+	asm volatile(LOCK_PREFIX "andl %0,%1"			\
+		     : : "r" (~(mask)), "m" (*(addr)) : "memory")
+
+#define atomic_set_mask(mask, addr)				\
+	asm volatile(LOCK_PREFIX "orl %0,%1"			\
+		     : : "r" ((unsigned)(mask)), "m" (*(addr))	\
+		     : "memory")
+
+#endif /* _ASM_X86_ATOMIC_H */
-- 
2.2.0.rc0.207.ga3a616c

  parent reply	other threads:[~2015-04-27 22:48 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-27 22:48 [U-Boot] [PATCH 00/20] x86: Add CPU uclass and multi-core support for Minnowboard MAX Simon Glass
2015-04-27 22:48 ` [U-Boot] [PATCH 01/20] Fix comment nits in board_f.c Simon Glass
2015-04-28  1:54   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 02/20] dm: core: Add a function to bind a driver for a device tree node Simon Glass
2015-04-27 22:48 ` [U-Boot] [PATCH 03/20] x86: Remove unwanted MMC debugging Simon Glass
2015-04-28  1:59   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 04/20] x86: Disable -Werror Simon Glass
2015-04-28  1:59   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 05/20] Move display_options functions to their own header Simon Glass
2015-04-28  2:10   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 06/20] Add print_freq() to display frequencies nicely Simon Glass
2015-04-28  4:13   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 07/20] x86: Add support for the Simple Firmware Interface (SFI) Simon Glass
2015-04-28  6:51   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 08/20] dm: Implement a CPU uclass Simon Glass
2015-04-28  7:24   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 09/20] Add a 'cpu' command to print CPU information Simon Glass
2015-04-28  7:34   ` Bin Meng
2015-04-27 22:48 ` Simon Glass [this message]
2015-04-28  7:38   ` [U-Boot] [PATCH 10/20] x86: Add atomic operations Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 11/20] x86: Add defines for fixed MTRRs Simon Glass
2015-04-28  7:45   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 12/20] x86: Add an mfence macro Simon Glass
2015-04-28  7:48   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 13/20] x86: Store the GDT pointer in global_data Simon Glass
2015-04-28  7:55   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 14/20] x86: Provide access to the IDT Simon Glass
2015-04-28  8:16   ` Bin Meng
2015-04-29  2:08     ` Simon Glass
2015-04-29  5:23       ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 15/20] x86: Add multi-processor init Simon Glass
2015-04-27 22:48 ` [U-Boot] [PATCH 16/20] x86: Add functions to set and clear bits on MSRs Simon Glass
2015-04-27 22:48 ` [U-Boot] [PATCH 17/20] x86: Allow CPUs to be set up after relocation Simon Glass
2015-04-27 22:48 ` [U-Boot] [PATCH 18/20] x86: Add a CPU driver for baytrail Simon Glass
2015-04-27 22:48 ` [U-Boot] [PATCH 19/20] x86: Tidy up the LAPIC init code Simon Glass
2015-04-27 22:48 ` [U-Boot] [PATCH 20/20] x86: Enable multi-core init for Minnowboard MAX Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1430174911-27538-11-git-send-email-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.