blob: cfad7fca01d61d72942d98a37d18e5e0675980bc [file] [log] [blame]
David Howellsa0616cd2012-03-28 18:30:02 +01001/*
2 * Copyright IBM Corp. 1999, 2009
3 *
4 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
5 */
6
7#ifndef __ASM_CTL_REG_H
8#define __ASM_CTL_REG_H
9
Michael Holzheuacf6a002013-11-13 10:38:27 +010010#include <linux/bug.h>
11
Heiko Carstens12325f02013-09-30 14:47:46 +020012#define __ctl_load(array, low, high) { \
13 typedef struct { char _[sizeof(array)]; } addrtype; \
14 \
15 BUILD_BUG_ON(sizeof(addrtype) != (high - low + 1) * sizeof(long));\
16 asm volatile( \
Heiko Carstens5a798592015-02-12 13:08:27 +010017 " lctlg %1,%2,%0\n" \
Heiko Carstens12325f02013-09-30 14:47:46 +020018 : : "Q" (*(addrtype *)(&array)), "i" (low), "i" (high));\
19}
David Howellsa0616cd2012-03-28 18:30:02 +010020
Heiko Carstens12325f02013-09-30 14:47:46 +020021#define __ctl_store(array, low, high) { \
22 typedef struct { char _[sizeof(array)]; } addrtype; \
23 \
24 BUILD_BUG_ON(sizeof(addrtype) != (high - low + 1) * sizeof(long));\
25 asm volatile( \
Heiko Carstens5a798592015-02-12 13:08:27 +010026 " stctg %1,%2,%0\n" \
Heiko Carstens12325f02013-09-30 14:47:46 +020027 : "=Q" (*(addrtype *)(&array)) \
28 : "i" (low), "i" (high)); \
29}
David Howellsa0616cd2012-03-28 18:30:02 +010030
Heiko Carstens12325f02013-09-30 14:47:46 +020031static inline void __ctl_set_bit(unsigned int cr, unsigned int bit)
32{
33 unsigned long reg;
David Howellsa0616cd2012-03-28 18:30:02 +010034
Heiko Carstens12325f02013-09-30 14:47:46 +020035 __ctl_store(reg, cr, cr);
36 reg |= 1UL << bit;
37 __ctl_load(reg, cr, cr);
38}
David Howellsa0616cd2012-03-28 18:30:02 +010039
Heiko Carstens12325f02013-09-30 14:47:46 +020040static inline void __ctl_clear_bit(unsigned int cr, unsigned int bit)
41{
42 unsigned long reg;
David Howellsa0616cd2012-03-28 18:30:02 +010043
Heiko Carstens12325f02013-09-30 14:47:46 +020044 __ctl_store(reg, cr, cr);
45 reg &= ~(1UL << bit);
46 __ctl_load(reg, cr, cr);
47}
David Howellsa0616cd2012-03-28 18:30:02 +010048
Heiko Carstens12325f02013-09-30 14:47:46 +020049void smp_ctl_set_bit(int cr, int bit);
50void smp_ctl_clear_bit(int cr, int bit);
David Howellsa0616cd2012-03-28 18:30:02 +010051
Heiko Carstens5f4e87a2014-01-01 16:08:37 +010052union ctlreg0 {
53 unsigned long val;
54 struct {
Heiko Carstens5f4e87a2014-01-01 16:08:37 +010055 unsigned long : 32;
Heiko Carstens5f4e87a2014-01-01 16:08:37 +010056 unsigned long : 3;
57 unsigned long lap : 1; /* Low-address-protection control */
58 unsigned long : 4;
59 unsigned long edat : 1; /* Enhanced-DAT-enablement control */
60 unsigned long : 23;
61 };
62};
63
David Howellsa0616cd2012-03-28 18:30:02 +010064#ifdef CONFIG_SMP
Heiko Carstens12325f02013-09-30 14:47:46 +020065# define ctl_set_bit(cr, bit) smp_ctl_set_bit(cr, bit)
66# define ctl_clear_bit(cr, bit) smp_ctl_clear_bit(cr, bit)
David Howellsa0616cd2012-03-28 18:30:02 +010067#else
Heiko Carstens12325f02013-09-30 14:47:46 +020068# define ctl_set_bit(cr, bit) __ctl_set_bit(cr, bit)
69# define ctl_clear_bit(cr, bit) __ctl_clear_bit(cr, bit)
70#endif
David Howellsa0616cd2012-03-28 18:30:02 +010071
72#endif /* __ASM_CTL_REG_H */