hc
2023-11-30 6c9be420e167ee7ce45c0309586f09ddab28ac15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_MICROBLAZE_CMPXCHG_H
#define _ASM_MICROBLAZE_CMPXCHG_H
 
#include <linux/irqflags.h>
 
void __bad_xchg(volatile void *ptr, int size);
 
static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
                               int size)
{
   unsigned long ret;
   unsigned long flags;
 
   switch (size) {
   case 1:
       local_irq_save(flags);
       ret = *(volatile unsigned char *)ptr;
       *(volatile unsigned char *)ptr = x;
       local_irq_restore(flags);
       break;
 
   case 4:
       local_irq_save(flags);
       ret = *(volatile unsigned long *)ptr;
       *(volatile unsigned long *)ptr = x;
       local_irq_restore(flags);
       break;
   default:
       __bad_xchg(ptr, size), ret = 0;
       break;
   }
 
   return ret;
}
 
#define xchg(ptr, x) \
   ((__typeof__(*(ptr))) __xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
 
#include <asm-generic/cmpxchg.h>
#include <asm-generic/cmpxchg-local.h>
 
#endif /* _ASM_MICROBLAZE_CMPXCHG_H */