summaryrefslogtreecommitdiff
path: root/src/arch/arm64/armv8/lib/sysctrl.c
blob: ef3b455b659f0bcc367e953d36fc6eca43f8927e (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
/*
 * This file is part of the coreboot project.
 *
 * Copyright (C) 2014 Google Inc
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 of
 * the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Reference: ARM Architecture Reference Manual, ARMv8-A edition
 * sysctrl.c: This file defines all the library functions for accessing system
 * control registers in Aarch64
 */

#include <stdint.h>

#include <arch/lib_helpers.h>

/* ACTLR */
uint32_t raw_read_actlr_el1(void)
{
	uint64_t actlr_el1;

	__asm__ __volatile__("mrs %0, ACTLR_EL1\n\t" : "=r" (actlr_el1) :  : "memory");

	return actlr_el1;
}

void raw_write_actlr_el1(uint32_t actlr_el1)
{
	__asm__ __volatile__("msr ACTLR_EL1, %0\n\t" : : "r" ((uint64_t)actlr_el1) : "memory");
}

uint32_t raw_read_actlr_el2(void)
{
	uint64_t actlr_el2;

	__asm__ __volatile__("mrs %0, ACTLR_EL2\n\t" : "=r" (actlr_el2) :  : "memory");

	return actlr_el2;
}

void raw_write_actlr_el2(uint32_t actlr_el2)
{
	__asm__ __volatile__("msr ACTLR_EL2, %0\n\t" : : "r" ((uint64_t)actlr_el2) : "memory");
}

uint32_t raw_read_actlr_el3(void)
{
	uint64_t actlr_el3;

	__asm__ __volatile__("mrs %0, ACTLR_EL3\n\t" : "=r" (actlr_el3) :  : "memory");

	return actlr_el3;
}

void raw_write_actlr_el3(uint32_t actlr_el3)
{
	__asm__ __volatile__("msr ACTLR_EL3, %0\n\t" : : "r" ((uint64_t)actlr_el3) : "memory");
}

uint32_t raw_read_actlr_current(void)
{
	uint32_t el = get_current_el();
	return raw_read_actlr(el);
}

void raw_write_actlr_current(uint32_t actlr)
{
	uint32_t el = get_current_el();
	raw_write_actlr(actlr, el);
}

uint32_t raw_read_actlr(uint32_t el)
{
	SWITCH_CASE_READ(raw_read_actlr, actlr, uint32_t, el);
}

void raw_write_actlr(uint32_t actlr, uint32_t el)
{
	SWITCH_CASE_WRITE(raw_write_actlr, actlr, el);
}

/* AFSR0 */
uint32_t raw_read_afsr0_el1(void)
{
	uint64_t afsr0_el1;

	__asm__ __volatile__("mrs %0, AFSR0_EL1\n\t" : "=r" (afsr0_el1) :  : "memory");

	return afsr0_el1;
}

void raw_write_afsr0_el1(uint32_t afsr0_el1)
{
	__asm__ __volatile__("msr AFSR0_EL1, %0\n\t" : : "r" ((uint64_t)afsr0_el1) : "memory");
}

uint32_t raw_read_afsr0_el2(void)
{
	uint64_t afsr0_el2;

	__asm__ __volatile__("mrs %0, AFSR0_EL2\n\t" : "=r" (afsr0_el2) :  : "memory");

	return afsr0_el2;
}

void raw_write_afsr0_el2(uint32_t afsr0_el2)
{
	__asm__ __volatile__("msr AFSR0_EL2, %0\n\t" : : "r" ((uint64_t)afsr0_el2) : "memory");
}

uint32_t raw_read_afsr0_el3(void)
{
	uint64_t afsr0_el3;

	__asm__ __volatile__("mrs %0, AFSR0_EL3\n\t" : "=r" (afsr0_el3) :  : "memory");

	return afsr0_el3;
}

void raw_write_afsr0_el3(uint32_t afsr0_el3)
{
	__asm__ __volatile__("msr AFSR0_EL3, %0\n\t" : : "r" ((uint64_t)afsr0_el3) : "memory");
}

uint32_t raw_read_afsr0_current(void)
{
	uint32_t el = get_current_el();
	return raw_read_afsr0(el);
}

void raw_write_afsr0_current(uint32_t afsr0)
{
	uint32_t el = get_current_el();
	raw_write_afsr0(afsr0, el);
}

uint32_t raw_read_afsr0(uint32_t el)
{
	SWITCH_CASE_READ(raw_read_afsr0, afsr0, uint32_t, el);
}

void raw_write_afsr0(uint32_t afsr0, uint32_t el)
{
	SWITCH_CASE_WRITE(raw_write_afsr0, afsr0, el);
}

/* AFSR1 */
uint32_t raw_read_afsr1_el1(void)
{
	uint64_t afsr1_el1;

	__asm__ __volatile__("mrs %0, AFSR1_EL1\n\t" : "=r" (afsr1_el1) :  : "memory");

	return afsr1_el1;
}

void raw_write_afsr1_el1(uint32_t afsr1_el1)
{
	__asm__ __volatile__("msr AFSR1_EL1, %0\n\t" : : "r" ((uint64_t)afsr1_el1) : "memory");
}

uint32_t raw_read_afsr1_el2(void)
{
	uint64_t afsr1_el2;

	__asm__ __volatile__("mrs %0, AFSR1_EL2\n\t" : "=r" (afsr1_el2) :  : "memory");

	return afsr1_el2;
}

void raw_write_afsr1_el2(uint32_t afsr1_el2)
{
	__asm__ __volatile__("msr AFSR1_EL2, %0\n\t" : : "r" ((uint64_t)afsr1_el2) : "memory");
}

uint32_t raw_read_afsr1_el3(void)
{
	uint64_t afsr1_el3;

	__asm__ __volatile__("mrs %0, AFSR1_EL3\n\t" : "=r" (afsr1_el3) :  : "memory");

	return afsr1_el3;
}

void raw_write_afsr1_el3(uint32_t afsr1_el3)
{
	__asm__ __volatile__("msr AFSR1_EL3, %0\n\t" : : "r" ((uint64_t)afsr1_el3) : "memory");
}

uint32_t raw_read_afsr1_current(void)
{
	uint32_t el = get_current_el();
	return raw_read_afsr1(el);
}

void raw_write_afsr1_current(uint32_t afsr1)
{
	uint32_t el = get_current_el();
	raw_write_afsr1(afsr1, el);
}

uint32_t raw_read_afsr1(uint32_t el)
{
	SWITCH_CASE_READ(raw_read_afsr1, afsr1, uint32_t, el);
}

void raw_write_afsr1(uint32_t afsr1, uint32_t el)
{
	SWITCH_CASE_WRITE(raw_write_afsr1, afsr1, el);
}

/* AIDR */
uint32_t raw_read_aidr_el1(void)
{
	uint64_t aidr_el1;

	__asm__ __volatile__("mrs %0, AIDR_EL1\n\t" : "=r" (aidr_el1) :  : "memory");

	return aidr_el1;
}

/* AMAIR */
uint64_t raw_read_amair_el1(void)
{
	uint64_t amair_el1;

	__asm__ __volatile__("mrs %0, AMAIR_EL1\n\t" : "=r" (amair_el1) :  : "memory");

	return amair_el1;
}

void raw_write_amair_el1(uint64_t amair_el1)
{
	__asm__ __volatile__("msr AMAIR_EL1, %0\n\t" : : "r" (amair_el1) : "memory");
}

uint64_t raw_read_amair_el2(void)
{
	uint64_t amair_el2;

	__asm__ __volatile__("mrs %0, AMAIR_EL2\n\t" : "=r" (amair_el2) :  : "memory");

	return amair_el2;
}

void raw_write_amair_el2(uint64_t amair_el2)
{
	__asm__ __volatile__("msr AMAIR_EL2, %0\n\t" : : "r" (amair_el2) : "memory");
}

uint64_t raw_read_amair_el3(void)
{
	uint64_t amair_el3;

	__asm__ __volatile__("mrs %0, AMAIR_EL3\n\t" : "=r" (amair_el3) :  : "memory");

	return amair_el3;
}

void raw_write_amair_el3(uint64_t amair_el3)
{
	__asm__ __volatile__("msr AMAIR_EL3, %0\n\t" : : "r" (amair_el3) : "memory");
}

uint64_t raw_read_amair_current(void)
{
	uint32_t el = get_current_el();
	return raw_read_amair(el);
}

void raw_write_amair_current(uint64_t amair)
{
	uint32_t el = get_current_el();
	raw_write_amair(amair, el);
}

uint64_t raw_read_amair(uint32_t el)
{
	SWITCH_CASE_READ(raw_read_amair, amair, uint64_t, el);
}

void raw_write_amair(uint64_t amair, uint32_t el)
{
	SWITCH_CASE_WRITE(raw_write_amair, amair, el);
}

/* CCSIDR */
uint32_t raw_read_ccsidr_el1(void)
{
	uint64_t ccsidr_el1;

	__asm__ __volatile__("mrs %0, CCSIDR_EL1\n\t" : "=r" (ccsidr_el1) :  : "memory");

	return ccsidr_el1;
}

/* CLIDR */
uint32_t raw_read_clidr_el1(void)
{
	uint64_t clidr_el1;

	__asm__ __volatile__("mrs %0, CLIDR_EL1\n\t" : "=r" (clidr_el1) :  : "memory");

	return clidr_el1;
}

/* CPACR */
uint32_t raw_read_cpacr_el1(void)
{
	uint64_t cpacr_el1;

	__asm__ __volatile__("mrs %0, CPACR_EL1\n\t" : "=r" (cpacr_el1) :  : "memory");

	return cpacr_el1;
}

void raw_write_cpacr_el1(uint32_t cpacr_el1)
{
	__asm__ __volatile__("msr CPACR_EL1, %0\n\t" : : "r" ((uint64_t)cpacr_el1) : "memory");
}

/* CPTR */
uint32_t raw_read_cptr_el2(void)
{
	uint64_t cptr_el2;

	__asm__ __volatile__("mrs %0, CPTR_EL2\n\t" : "=r" (cptr_el2) :  : "memory");

	return cptr_el2;
}

void raw_write_cptr_el2(uint32_t cptr_el2)
{
	__asm__ __volatile__("msr CPTR_EL2, %0\n\t" : : "r" ((uint64_t)cptr_el2) : "memory");
}

uint32_t raw_read_cptr_el3(void)
{
	uint64_t cptr_el3;

	__asm__ __volatile__("mrs %0, CPTR_EL3\n\t" : "=r" (cptr_el3) :  : "memory");

	return cptr_el3;
}

void raw_write_cptr_el3(uint32_t cptr_el3)
{
	__asm__ __volatile__("msr CPTR_EL3, %0\n\t" : : "r" ((uint64_t)cptr_el3) : "memory");
}

/* CSSELR */
uint32_t raw_read_csselr_el1(void)
{
	uint64_t csselr_el1;

	__asm__ __volatile__("mrs %0, CSSELR_EL1\n\t" : "=r" (csselr_el1) :  : "memory");

	return csselr_el1;
}

void raw_write_csselr_el1(uint32_t csselr_el1)
{
	__asm__ __volatile__("msr CSSELR_EL1, %0\n\t" : : "r" ((uint64_t)csselr_el1) : "memory");
}

/* CTR */
uint32_t raw_read_ctr_el0(void)
{
	uint64_t ctr_el0;

	__asm__ __volatile__("mrs %0, CTR_EL0\n\t" : "=r" (ctr_el0) :  : "memory");

	return ctr_el0;
}

/* ESR */
uint32_t raw_read_esr_el1(void)
{
	uint64_t esr_el1;

	__asm__ __volatile__("mrs %0, ESR_EL1\n\t" : "=r" (esr_el1) :  : "memory");

	return esr_el1;
}

void raw_write_esr_el1(uint32_t esr_el1)
{
	__asm__ __volatile__("msr ESR_EL1, %0\n\t" : : "r" ((uint64_t)esr_el1) : "memory");
}

uint32_t raw_read_esr_el2(void)
{
	uint64_t esr_el2;

	__asm__ __volatile__("mrs %0, ESR_EL2\n\t" : "=r" (esr_el2) :  : "memory");

	return esr_el2;
}

void raw_write_esr_el2(uint32_t esr_el2)
{
	__asm__ __volatile__("msr ESR_EL2, %0\n\t" : : "r" ((uint64_t)esr_el2) : "memory");
}

uint32_t raw_read_esr_el3(void)
{
	uint64_t esr_el3;

	__asm__ __volatile__("mrs %0, ESR_EL3\n\t" : "=r" (esr_el3) :  : "memory");

	return esr_el3;
}

void raw_write_esr_el3(uint32_t esr_el3)
{
	__asm__ __volatile__("msr ESR_EL3, %0\n\t" : : "r" ((uint64_t)esr_el3) : "memory");
}

uint32_t raw_read_esr_current(void)
{
	uint32_t el = get_current_el();
	return raw_read_esr(el);
}

void raw_write_esr_current(uint32_t esr)
{
	uint32_t el = get_current_el();
	raw_write_esr(esr, el);
}

uint32_t raw_read_esr(uint32_t el)
{
	SWITCH_CASE_READ(raw_read_esr, esr, uint32_t, el);
}

void raw_write_esr(uint32_t esr, uint32_t el)
{
	SWITCH_CASE_WRITE(raw_write_esr, esr, el);
}

/* FAR */
uint64_t raw_read_far_el1(void)
{
	uint64_t far_el1;

	__asm__ __volatile__("mrs %0, FAR_EL1\n\t" : "=r" (far_el1) :  : "memory");

	return far_el1;
}

void raw_write_far_el1(uint64_t far_el1)
{
	__asm__ __volatile__("msr FAR_EL1, %0\n\t" : : "r" (far_el1) : "memory");
}

uint64_t raw_read_far_el2(void)
{
	uint64_t far_el2;

	__asm__ __volatile__("mrs %0, FAR_EL2\n\t" : "=r" (far_el2) :  : "memory");

	return far_el2;
}

void raw_write_far_el2(uint64_t far_el2)
{
	__asm__ __volatile__("msr FAR_EL2, %0\n\t" : : "r" (far_el2) : "memory");
}

uint64_t raw_read_far_el3(void)
{
	uint64_t far_el3;

	__asm__ __volatile__("mrs %0, FAR_EL3\n\t" : "=r" (far_el3) :  : "memory");

	return far_el3;
}

void raw_write_far_el3(uint64_t far_el3)
{
	__asm__ __volatile__("msr FAR_EL3, %0\n\t" : : "r" (far_el3) : "memory");
}

uint64_t raw_read_far_current(void)
{
	uint32_t el = get_current_el();
	return raw_read_far(el);
}

void raw_write_far_current(uint64_t far)
{
	uint32_t el = get_current_el();
	raw_write_far(far, el);
}

uint64_t raw_read_far(uint32_t el)
{
	SWITCH_CASE_READ(raw_read_far, far, uint64_t, el);
}

void raw_write_far(uint64_t far, uint32_t el)
{
	SWITCH_CASE_WRITE(raw_write_far, far, el);
}

/* HCR */
uint64_t raw_read_hcr_el2(void)
{
	uint64_t hcr_el2;

	__asm__ __volatile__("mrs %0, HCR_EL2\n\t" : "=r" (hcr_el2) :  : "memory");

	return hcr_el2;
}

void raw_write_hcr_el2(uint64_t hcr_el2)
{
	__asm__ __volatile__("msr HCR_EL2, %0\n\t" : : "r" (hcr_el2) : "memory");
}

/* AA64PFR0 */
uint64_t raw_read_aa64pfr0_el1(void)
{
	uint64_t aa64pfr0_el1;

	__asm__ __volatile__("mrs %0, ID_AA64PFR0_EL1\n\t" : "=r" (aa64pfr0_el1) :  : "memory");

	return aa64pfr0_el1;
}

/* MAIR */
uint64_t raw_read_mair_el1(void)
{
	uint64_t mair_el1;

	__asm__ __volatile__("mrs %0, MAIR_EL1\n\t" : "=r" (mair_el1) :  : "memory");

	return mair_el1;
}

void raw_write_mair_el1(uint64_t mair_el1)
{
	__asm__ __volatile__("msr MAIR_EL1, %0\n\t" : : "r" (mair_el1) : "memory");
}

uint64_t raw_read_mair_el2(void)
{
	uint64_t mair_el2;

	__asm__ __volatile__("mrs %0, MAIR_EL2\n\t" : "=r" (mair_el2) :  : "memory");

	return mair_el2;
}

void raw_write_mair_el2(uint64_t mair_el2)
{
	__asm__ __volatile__("msr MAIR_EL2, %0\n\t" : : "r" (mair_el2) : "memory");
}

uint64_t raw_read_mair_el3(void)
{
	uint64_t mair_el3;

	__asm__ __volatile__("mrs %0, MAIR_EL3\n\t" : "=r" (mair_el3) :  : "memory");

	return mair_el3;
}

void raw_write_mair_el3(uint64_t mair_el3)
{
	__asm__ __volatile__("msr MAIR_EL3, %0\n\t" : : "r" (mair_el3) : "memory");
}

uint64_t raw_read_mair_current(void)
{
	uint32_t el = get_current_el();
	return raw_read_mair(el);
}

void raw_write_mair_current(uint64_t mair)
{
	uint32_t el = get_current_el();
	raw_write_mair(mair, el);
}

uint64_t raw_read_mair(uint32_t el)
{
	SWITCH_CASE_READ(raw_read_mair, mair, uint64_t, el);
}

void raw_write_mair(uint64_t mair, uint32_t el)
{
	SWITCH_CASE_WRITE(raw_write_mair, mair, el);
}

/* MIDR */
uint32_t raw_read_midr_el1(void)
{
	uint64_t midr_el1;

	__asm__ __volatile__("mrs %0, MIDR_EL1\n\t" : "=r" (midr_el1) :  : "memory");

	return midr_el1;
}

/* MPIDR */
uint64_t raw_read_mpidr_el1(void)
{
	uint64_t mpidr_el1;

	__asm__ __volatile__("mrs %0, MPIDR_EL1\n\t" : "=r" (mpidr_el1) :  : "memory");

	return mpidr_el1;
}

/* RMR */
uint32_t raw_read_rmr_el1(void)
{
	uint64_t rmr_el1;

	__asm__ __volatile__("mrs %0, RMR_EL1\n\t" : "=r" (rmr_el1) :  : "memory");

	return rmr_el1;
}

void raw_write_rmr_el1(uint32_t rmr_el1)
{
	__asm__ __volatile__("msr RMR_EL1, %0\n\t" : : "r" ((uint64_t)rmr_el1) : "memory");
}

uint32_t raw_read_rmr_el2(void)
{
	uint64_t rmr_el2;

	__asm__ __volatile__("mrs %0, RMR_EL2\n\t" : "=r" (rmr_el2) :  : "memory");

	return rmr_el2;
}

void raw_write_rmr_el2(uint32_t rmr_el2)
{
	__asm__ __volatile__("msr RMR_EL2, %0\n\t" : : "r" ((uint64_t)rmr_el2) : "memory");
}

uint32_t raw_read_rmr_el3(void)
{
	uint64_t rmr_el3;

	__asm__ __volatile__("mrs %0, RMR_EL3\n\t" : "=r" (rmr_el3) :  : "memory");

	return rmr_el3;
}

void raw_write_rmr_el3(uint32_t rmr_el3)
{
	__asm__ __volatile__("msr RMR_EL3, %0\n\t" : : "r" ((uint64_t)rmr_el3) : "memory");
}

uint32_t raw_read_rmr_current(void)
{
	uint32_t el = get_current_el();
	return raw_read_rmr(el);
}

void raw_write_rmr_current(uint32_t rmr)
{
	uint32_t el = get_current_el();
	raw_write_rmr(rmr, el);
}

uint32_t raw_read_rmr(uint32_t el)
{
	SWITCH_CASE_READ(raw_read_rmr, rmr, uint32_t, el);
}

void raw_write_rmr(uint32_t rmr, uint32_t el)
{
	SWITCH_CASE_WRITE(raw_write_rmr, rmr, el);
}

/* RVBAR */
uint64_t raw_read_rvbar_el1(void)
{
	uint64_t rvbar_el1;

	__asm__ __volatile__("mrs %0, RVBAR_EL1\n\t" : "=r" (rvbar_el1) :  : "memory");

	return rvbar_el1;
}

void raw_write_rvbar_el1(uint64_t rvbar_el1)
{
	__asm__ __volatile__("msr RVBAR_EL1, %0\n\t" : : "r" (rvbar_el1) : "memory");
}

uint64_t raw_read_rvbar_el2(void)
{
	uint64_t rvbar_el2;

	__asm__ __volatile__("mrs %0, RVBAR_EL2\n\t" : "=r" (rvbar_el2) :  : "memory");

	return rvbar_el2;
}

void raw_write_rvbar_el2(uint64_t rvbar_el2)
{
	__asm__ __volatile__("msr RVBAR_EL2, %0\n\t" : : "r" (rvbar_el2) : "memory");
}

uint64_t raw_read_rvbar_el3(void)
{
	uint64_t rvbar_el3;

	__asm__ __volatile__("mrs %0, RVBAR_EL3\n\t" : "=r" (rvbar_el3) :  : "memory");

	return rvbar_el3;
}

void raw_write_rvbar_el3(uint64_t rvbar_el3)
{
	__asm__ __volatile__("msr RVBAR_EL3, %0\n\t" : : "r" (rvbar_el3) : "memory");
}

uint64_t raw_read_rvbar_current(void)
{
	uint32_t el = get_current_el();
	return raw_read_rvbar(el);
}

void raw_write_rvbar_current(uint64_t rvbar)
{
	uint32_t el = get_current_el();
	raw_write_rvbar(rvbar, el);
}

uint64_t raw_read_rvbar(uint32_t el)
{
	SWITCH_CASE_READ(raw_read_rvbar, rvbar, uint64_t, el);
}

void raw_write_rvbar(uint64_t rvbar, uint32_t el)
{
	SWITCH_CASE_WRITE(raw_write_rvbar, rvbar, el);
}

/* Scr */
uint32_t raw_read_scr_el3(void)
{
	uint64_t scr_el3;

	__asm__ __volatile__("mrs %0, SCR_EL3\n\t" : "=r" (scr_el3) :  : "memory");

	return scr_el3;
}

void raw_write_scr_el3(uint32_t scr_el3)
{
	__asm__ __volatile__("msr SCR_EL3, %0\n\t" : : "r" ((uint64_t)scr_el3) : "memory");
}

/* SCTLR */
uint32_t raw_read_sctlr_el1(void)
{
	uint64_t sctlr_el1;

	__asm__ __volatile__("mrs %0, SCTLR_EL1\n\t" : "=r" (sctlr_el1) :  : "memory");

	return sctlr_el1;
}

void raw_write_sctlr_el1(uint32_t sctlr_el1)
{
	__asm__ __volatile__("msr SCTLR_EL1, %0\n\t" : : "r" ((uint64_t)sctlr_el1) : "memory");
}

uint32_t raw_read_sctlr_el2(void)
{
	uint64_t sctlr_el2;

	__asm__ __volatile__("mrs %0, SCTLR_EL2\n\t" : "=r" (sctlr_el2) :  : "memory");

	return sctlr_el2;
}

void raw_write_sctlr_el2(uint32_t sctlr_el2)
{
	__asm__ __volatile__("msr SCTLR_EL2, %0\n\t" : : "r" ((uint64_t)sctlr_el2) : "memory");
}

uint32_t raw_read_sctlr_el3(void)
{
	uint64_t sctlr_el3;

	__asm__ __volatile__("mrs %0, SCTLR_EL3\n\t" : "=r" (sctlr_el3) :  : "memory");

	return sctlr_el3;
}

void raw_write_sctlr_el3(uint32_t sctlr_el3)
{
	__asm__ __volatile__("msr SCTLR_EL3, %0\n\t" : : "r" ((uint64_t)sctlr_el3) : "memory");
}

uint32_t raw_read_sctlr_current(void)
{
	uint32_t el = get_current_el();
	return raw_read_sctlr(el);
}

void raw_write_sctlr_current(uint32_t sctlr)
{
	uint32_t el = get_current_el();
	raw_write_sctlr(sctlr, el);
}

uint32_t raw_read_sctlr(uint32_t el)
{
	SWITCH_CASE_READ(raw_read_sctlr, sctlr, uint32_t, el);
}

void raw_write_sctlr(uint32_t sctlr, uint32_t el)
{
	SWITCH_CASE_WRITE(raw_write_sctlr, sctlr, el);
}

/* TCR */
uint64_t raw_read_tcr_el1(void)
{
	uint64_t tcr_el1;

	__asm__ __volatile__("mrs %0, TCR_EL1\n\t" : "=r" (tcr_el1) :  : "memory");

	return tcr_el1;
}

void raw_write_tcr_el1(uint64_t tcr_el1)
{
	__asm__ __volatile__("msr TCR_EL1, %0\n\t" : : "r" (tcr_el1) : "memory");
}

uint32_t raw_read_tcr_el2(void)
{
	uint64_t tcr_el2;

	__asm__ __volatile__("mrs %0, TCR_EL2\n\t" : "=r" (tcr_el2) :  : "memory");

	return tcr_el2;
}

void raw_write_tcr_el2(uint32_t tcr_el2)
{
	__asm__ __volatile__("msr TCR_EL2, %0\n\t" : : "r" ((uint64_t)tcr_el2) : "memory");
}

uint32_t raw_read_tcr_el3(void)
{
	uint64_t tcr_el3;

	__asm__ __volatile__("mrs %0, TCR_EL3\n\t" : "=r" (tcr_el3) :  : "memory");

	return tcr_el3;
}

void raw_write_tcr_el3(uint32_t tcr_el3)
{
	__asm__ __volatile__("msr TCR_EL3, %0\n\t" : : "r" ((uint64_t)tcr_el3) : "memory");
}


/*
 * IMPORTANT: TCR_EL1 is 64-bit whereas TCR_EL2 and TCR_EL3 are 32-bit. Thus,
 * 64-bit is used to read/write for tcr_current. tcr_el2 and tcr_el3 handle them
 * with appropriate 32-bit types.
 */
uint64_t raw_read_tcr_current(void)
{
	uint32_t el = get_current_el();
	return raw_read_tcr(el);
}

void raw_write_tcr_current(uint64_t tcr)
{
	uint32_t el = get_current_el();
	raw_write_tcr(tcr, el);
}

uint64_t raw_read_tcr(uint32_t el)
{
	SWITCH_CASE_READ(raw_read_tcr, tcr, uint64_t, el);
}

void raw_write_tcr(uint64_t tcr, uint32_t el)
{
	SWITCH_CASE_WRITE(raw_write_tcr, tcr, el);
}

/* TTBR0 */
uint64_t raw_read_ttbr0_el1(void)
{
	uint64_t ttbr0_el1;

	__asm__ __volatile__("mrs %0, TTBR0_EL1\n\t" : "=r" (ttbr0_el1) :  : "memory");

	return ttbr0_el1;
}

void raw_write_ttbr0_el1(uint64_t ttbr0_el1)
{
	__asm__ __volatile__("msr TTBR0_EL1, %0\n\t" : : "r" (ttbr0_el1) : "memory");
}

uint64_t raw_read_ttbr0_el2(void)
{
	uint64_t ttbr0_el2;

	__asm__ __volatile__("mrs %0, TTBR0_EL2\n\t" : "=r" (ttbr0_el2) :  : "memory");

	return ttbr0_el2;
}

void raw_write_ttbr0_el2(uint64_t ttbr0_el2)
{
	__asm__ __volatile__("msr TTBR0_EL2, %0\n\t" : : "r" (ttbr0_el2) : "memory");
}

uint64_t raw_read_ttbr0_el3(void)
{
	uint64_t ttbr0_el3;

	__asm__ __volatile__("mrs %0, TTBR0_EL3\n\t" : "=r" (ttbr0_el3) :  : "memory");

	return ttbr0_el3;
}

void raw_write_ttbr0_el3(uint64_t ttbr0_el3)
{
	__asm__ __volatile__("msr TTBR0_EL3, %0\n\t" : : "r" (ttbr0_el3) : "memory");
}

uint64_t raw_read_ttbr0_current(void)
{
	uint32_t el = get_current_el();
	return raw_read_ttbr0(el);
}

void raw_write_ttbr0_current(uint64_t ttbr0)
{
	uint32_t el = get_current_el();
	raw_write_ttbr0(ttbr0, el);
}

uint64_t raw_read_ttbr0(uint32_t el)
{
	SWITCH_CASE_READ(raw_read_ttbr0, ttbr0, uint64_t, el);
}

void raw_write_ttbr0(uint64_t ttbr0, uint32_t el)
{
	SWITCH_CASE_WRITE(raw_write_ttbr0, ttbr0, el);
}

/* TTBR1 */
uint64_t raw_read_ttbr1_el1(void)
{
	uint64_t ttbr1_el1;

	__asm__ __volatile__("mrs %0, TTBR1_EL1\n\t" : "=r" (ttbr1_el1) :  : "memory");

	return ttbr1_el1;
}

void raw_write_ttbr1_el1(uint64_t ttbr1_el1)
{
	__asm__ __volatile__("msr TTBR1_EL1, %0\n\t" : : "r" (ttbr1_el1) : "memory");
}

/* VBAR */
uint64_t raw_read_vbar_el1(void)
{
	uint64_t vbar_el1;

	__asm__ __volatile__("mrs %0, VBAR_EL1\n\t" : "=r" (vbar_el1) :  : "memory");

	return vbar_el1;
}

void raw_write_vbar_el1(uint64_t vbar_el1)
{
	__asm__ __volatile__("msr VBAR_EL1, %0\n\t" : : "r" (vbar_el1) : "memory");
}

uint64_t raw_read_vbar_el2(void)
{
	uint64_t vbar_el2;

	__asm__ __volatile__("mrs %0, VBAR_EL2\n\t" : "=r" (vbar_el2) :  : "memory");

	return vbar_el2;
}

void raw_write_vbar_el2(uint64_t vbar_el2)
{
	__asm__ __volatile__("msr VBAR_EL2, %0\n\t" : : "r" (vbar_el2) : "memory");
}

uint64_t raw_read_vbar_el3(void)
{
	uint64_t vbar_el3;

	__asm__ __volatile__("mrs %0, VBAR_EL3\n\t" : "=r" (vbar_el3) :  : "memory");

	return vbar_el3;
}

void raw_write_vbar_el3(uint64_t vbar_el3)
{
	__asm__ __volatile__("msr VBAR_EL3, %0\n\t" : : "r" (vbar_el3) : "memory");
}

uint64_t raw_read_vbar_current(void)
{
	uint32_t el = get_current_el();
	return raw_read_vbar(el);
}

void raw_write_vbar_current(uint64_t vbar)
{
	uint32_t el = get_current_el();
	raw_write_vbar(vbar, el);
}

uint64_t raw_read_vbar(uint32_t el)
{
	SWITCH_CASE_READ(raw_read_vbar, vbar, uint64_t, el);
}

void raw_write_vbar(uint64_t vbar, uint32_t el)
{
	SWITCH_CASE_WRITE(raw_write_vbar, vbar, el);
}

uint32_t raw_read_cntfrq_el0(void)
{
	uint64_t cntfrq_el0;

	__asm__ __volatile__("mrs %0, CNTFRQ_EL0\n\t" : "=r" (cntfrq_el0) : : "memory");
	return cntfrq_el0;
}

void raw_write_cntfrq_el0(uint32_t cntfrq_el0)
{
	__asm__ __volatile__("msr CNTFRQ_EL0, %0\n\t" : : "r" ((uint64_t)cntfrq_el0) : "memory");
}

uint64_t raw_read_cntpct_el0(void)
{
	uint64_t cntpct_el0;

	__asm__ __volatile__("mrs %0, CNTPCT_EL0\n\t" : "=r" (cntpct_el0) : : "memory");
	return cntpct_el0;
}