linux/arch/c6x/include/asm/cmpxchg.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0-only */
   2/*
   3 *  Port on Texas Instruments TMS320C6x architecture
   4 *
   5 *  Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
   6 *  Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
   7 */
   8#ifndef _ASM_C6X_CMPXCHG_H
   9#define _ASM_C6X_CMPXCHG_H
  10
  11#include <linux/irqflags.h>
  12
  13/*
  14 * Misc. functions
  15 */
  16static inline unsigned int __xchg(unsigned int x, volatile void *ptr, int size)
  17{
  18        unsigned int tmp;
  19        unsigned long flags;
  20
  21        local_irq_save(flags);
  22
  23        switch (size) {
  24        case 1:
  25                tmp = 0;
  26                tmp = *((unsigned char *) ptr);
  27                *((unsigned char *) ptr) = (unsigned char) x;
  28                break;
  29        case 2:
  30                tmp = 0;
  31                tmp = *((unsigned short *) ptr);
  32                *((unsigned short *) ptr) = x;
  33                break;
  34        case 4:
  35                tmp = 0;
  36                tmp = *((unsigned int *) ptr);
  37                *((unsigned int *) ptr) = x;
  38                break;
  39        }
  40        local_irq_restore(flags);
  41        return tmp;
  42}
  43
  44#define xchg(ptr, x) \
  45        ((__typeof__(*(ptr)))__xchg((unsigned int)(x), (void *) (ptr), \
  46                                    sizeof(*(ptr))))
  47
  48#include <asm-generic/cmpxchg-local.h>
  49
  50/*
  51 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  52 * them available.
  53 */
  54#define cmpxchg_local(ptr, o, n)                                        \
  55        ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr),             \
  56                                                     (unsigned long)(o), \
  57                                                     (unsigned long)(n), \
  58                                                     sizeof(*(ptr))))
  59#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  60
  61#include <asm-generic/cmpxchg.h>
  62
  63#endif /* _ASM_C6X_CMPXCHG_H */
  64