blob: 875c5643bcca0aaa04761b26ccb791de0aa4f140 [file] [log] [blame]
Duy Truong790f06d2013-02-13 16:38:12 -08001/* Copyright (c) 2010, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14/*
15mrcmcr.h
16
17DESCRIPTION: Convenience macros for access the cp registers in the arm.
18
19REV/DATE: Fri Mar 18 16:34:44 EST 2005
20*/
21
22#ifndef __mrcmcr__h_
23#define __mrcmcr__h_
24
25/*
26* Define some convenience macros to acccess the cp registers from c code
27* Lots of macro trickery here.
28*
29* Takes the same format as the asm instructions and unfortunatly you cannot
30* use variables to select the crn, crn or op fields...
31*
32* For those unfamiliar with the # and string stuff.
33* # creates a string from the value and any two strings that are beside
34* are concatenated...thus these create one big asm string for the
35* inline asm code.
36*
37* When compiled these compile to single asm instructions (fast) but
38* without all the hassel of __asm__ __volatile__ (...) =r
39*
40* Format is:
41*
42* unsigned long reg; // destination variable
43* MRC(reg, p15, 0, c1, c0, 0 );
44*
45* MRC read control register
46* MCR control register write
47*/
48
49/*
50* Some assembly macros so we can use the same macros as in the C version.
51* Turns the ASM code a little C-ish but keeps the code consistent and in
52* one location...
53*/
54#ifdef __ASSEMBLY__
55
56
57#define MRC(reg, processor, op1, crn, crm, op2) \
58(mrc processor , op1 , reg, crn , crm , op2)
59
60#define MCR(reg, processor, op1, crn, crm, op2) \
61(mcr processor , op1 , reg, crn , crm , op2)
62
63/*
64* C version of the macros.
65*/
66#else
67
68#define MRC(reg, processor, op1, crn, crm, op2) \
69__asm__ __volatile__ ( \
70" mrc " #processor "," #op1 ", %0," #crn "," #crm "," #op2 "\n" \
71: "=r" (reg))
72
73#define MCR(reg, processor, op1, crn, crm, op2) \
74__asm__ __volatile__ ( \
75" mcr " #processor "," #op1 ", %0," #crn "," #crm "," #op2 "\n" \
76: : "r" (reg))
77#endif
78
79
80/*
81* Easy access convenience function to read CP15 registers from c code
82*/
83#define MRC15(reg, op1, crn, crm, op2) MRC(reg, p15, op1, crn, crm, op2)
84#define MCR15(reg, op1, crn, crm, op2) MCR(reg, p15, op1, crn, crm, op2)
85
86#endif