-
Notifications
You must be signed in to change notification settings - Fork 279
/
ppc64.c
3860 lines (3383 loc) · 111 KB
/
ppc64.c
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
/* ppc64.c -- core analysis suite
*
* Copyright (C) 2004-2015,2018 David Anderson
* Copyright (C) 2004-2015,2018 Red Hat, Inc. All rights reserved.
* Copyright (C) 2004, 2006 Haren Myneni, IBM Corporation
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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.
*/
#ifdef PPC64
#include "defs.h"
#include <endian.h>
#include <ctype.h>
static int ppc64_kvtop(struct task_context *, ulong, physaddr_t *, int);
static int ppc64_uvtop(struct task_context *, ulong, physaddr_t *, int);
static ulong ppc64_vmalloc_start(void);
static int ppc64_vmemmap_to_phys(ulong, physaddr_t *, int);
static int ppc64_is_task_addr(ulong);
static int ppc64_verify_symbol(const char *, ulong, char);
static ulong ppc64_get_task_pgd(ulong);
static int ppc64_translate_pte(ulong, void *, ulonglong);
static ulong ppc64_processor_speed(void);
static int ppc64_eframe_search(struct bt_info *);
static void ppc64_back_trace_cmd(struct bt_info *);
static void ppc64_back_trace(struct gnu_request *, struct bt_info *);
static void get_ppc64_frame(struct bt_info *, ulong *, ulong *);
static void ppc64_print_stack_entry(int,struct gnu_request *,
ulong, ulong, struct bt_info *);
static void ppc64_dump_irq(int);
static ulong ppc64_get_sp(ulong);
static void ppc64_get_stack_frame(struct bt_info *, ulong *, ulong *);
static int ppc64_dis_filter(ulong, char *, unsigned int);
static void ppc64_cmd_mach(void);
static int ppc64_get_smp_cpus(void);
static void ppc64_display_machine_stats(void);
static void ppc64_dump_line_number(ulong);
static struct line_number_hook ppc64_line_number_hooks[];
static ulong ppc64_get_stackbase(ulong);
static ulong ppc64_get_stacktop(ulong);
void ppc64_compiler_warning_stub(void);
static ulong ppc64_in_irqstack(ulong);
static enum emergency_stack_type ppc64_in_emergency_stack(int cpu, ulong addr,
bool verbose);
static void ppc64_set_bt_emergency_stack(enum emergency_stack_type type,
struct bt_info *bt);
static char * ppc64_check_eframe(struct ppc64_pt_regs *);
static void ppc64_print_eframe(char *, struct ppc64_pt_regs *,
struct bt_info *);
static int ppc64_get_current_task_reg(int regno, const char *name, int size,
void *value);
static void parse_cmdline_args(void);
static int ppc64_paca_percpu_offset_init(int);
static void ppc64_init_cpu_info(void);
static int ppc64_get_cpu_map(void);
static void ppc64_clear_machdep_cache(void);
static void ppc64_init_paca_info(void);
static void ppc64_vmemmap_init(void);
static int ppc64_get_kvaddr_ranges(struct vaddr_range *);
static uint get_ptetype(ulong pte);
static int is_hugepage(ulong pte);
static int is_hugepd(ulong pte);
static ulong hugepage_dir(ulong pte);
static ulong pgd_page_vaddr_l4(ulong pgd);
static ulong pud_page_vaddr_l4(ulong pud);
static ulong pmd_page_vaddr_l4(ulong pmd);
static int is_opal_context(ulong sp, ulong nip);
void opalmsg(void);
struct user_regs_bitmap_struct {
struct ppc64_pt_regs ur;
ulong bitmap[32];
};
static int is_opal_context(ulong sp, ulong nip)
{
uint64_t opal_start, opal_end;
if (!(machdep->flags & OPAL_FW))
return FALSE;
opal_start = machdep->machspec->opal.base;
opal_end = opal_start + machdep->machspec->opal.size;
if (((sp >= opal_start) && (sp < opal_end)) ||
((nip >= opal_start) && (nip < opal_end)))
return TRUE;
return FALSE;
}
static inline int is_hugepage(ulong pte)
{
if ((machdep->flags & BOOK3E) ||
(THIS_KERNEL_VERSION < LINUX(3,10,0))) {
/*
* hugepage support via hugepd for book3e and
* also kernel v3.9 & below.
*/
return 0;
} else if (THIS_KERNEL_VERSION >= LINUX(4,5,0)) {
/*
* leaf pte for huge page, if _PAGE_PTE is set.
*/
return !!(pte & _PAGE_PTE);
} else { /* BOOK3S, kernel v3.10 - v4.4 */
/*
* leaf pte for huge page, bottom two bits != 00
*/
return ((pte & HUGE_PTE_MASK) != 0x0);
}
}
static inline int is_hugepd(ulong pte)
{
if ((machdep->flags & BOOK3E) ||
(THIS_KERNEL_VERSION < LINUX(3,10,0)))
return ((pte & PD_HUGE) == 0x0);
else if (THIS_KERNEL_VERSION >= LINUX(4,5,0)) {
/*
* hugepd pointer, if _PAGE_PTE is not set and
* hugepd shift mask is set.
*/
return (!(pte & _PAGE_PTE) &&
((pte & HUGEPD_SHIFT_MASK) != 0));
} else { /* BOOK3S, kernel v3.10 - v4.4 */
/*
* hugepd pointer, bottom two bits == 00 and next 4 bits
* indicate size of table
*/
return (((pte & HUGE_PTE_MASK) == 0x0) &&
((pte & HUGEPD_SHIFT_MASK) != 0));
}
}
static inline uint get_ptetype(ulong pte)
{
uint pte_type = 0; /* 0: regular entry; 1: huge pte; 2: huge pd */
if (is_hugepage(pte))
pte_type = 1;
else if (!(machdep->flags & RADIX_MMU) &&
(PAGESIZE() != PPC64_64K_PAGE_SIZE) && is_hugepd(pte))
pte_type = 2;
return pte_type;
}
static inline ulong hugepage_dir(ulong pte)
{
if ((machdep->flags & BOOK3E) ||
(THIS_KERNEL_VERSION < LINUX(3,10,0)))
return (ulong)((pte & ~HUGEPD_SHIFT_MASK) | PD_HUGE);
else if (machdep->flags & PHYS_ENTRY_L4)
return PTOV(pte & ~HUGEPD_ADDR_MASK);
else /* BOOK3S, kernel v3.10 - v4.4 */
return (ulong)(pte & ~HUGEPD_SHIFT_MASK);
}
static inline ulong pgd_page_vaddr_l4(ulong pgd)
{
ulong pgd_val;
pgd_val = (pgd & ~machdep->machspec->pgd_masked_bits);
if (machdep->flags & PHYS_ENTRY_L4) {
/*
* physical address is stored starting from kernel v4.6
*/
pgd_val = PTOV(pgd_val);
}
return pgd_val;
}
static inline ulong pud_page_vaddr_l4(ulong pud)
{
ulong pud_val;
pud_val = (pud & ~machdep->machspec->pud_masked_bits);
if (machdep->flags & PHYS_ENTRY_L4) {
/*
* physical address is stored starting from kernel v4.6
*/
pud_val = PTOV(pud_val);
}
return pud_val;
}
static inline ulong pmd_page_vaddr_l4(ulong pmd)
{
ulong pmd_val;
pmd_val = (pmd & ~machdep->machspec->pmd_masked_bits);
if (machdep->flags & PHYS_ENTRY_L4) {
/*
* physical address is stored starting from kernel v4.6
*/
pmd_val = PTOV(pmd_val);
}
return pmd_val;
}
static int book3e_is_kvaddr(ulong addr)
{
return (addr >= BOOK3E_VMBASE);
}
static int book3e_is_vmaddr(ulong addr)
{
return (addr >= BOOK3E_VMBASE) && (addr < machdep->identity_map_base);
}
static int ppc64_is_vmaddr(ulong addr)
{
return (vt->vmalloc_start && addr >= vt->vmalloc_start);
}
#define is_RHEL8() (strstr(kt->proc_version, ".el8."))
static int set_ppc64_max_physmem_bits(void)
{
int dimension;
char *string;
if ((string = pc->read_vmcoreinfo("NUMBER(MAX_PHYSMEM_BITS)"))) {
machdep->max_physmem_bits = atol(string);
free(string);
return 0;
}
get_array_length("mem_section", &dimension, 0);
if ((machdep->flags & VMEMMAP) &&
(THIS_KERNEL_VERSION >= LINUX(4,20,0)) &&
!dimension && (machdep->pagesize == 65536)) {
/*
* SPARSEMEM_VMEMMAP & SPARSEMEM_EXTREME configurations with
* 64K pagesize and v4.20 kernel or later.
*/
machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_4_20;
} else if ((machdep->flags & VMEMMAP) &&
((THIS_KERNEL_VERSION >= LINUX(4,19,0)) || is_RHEL8())) {
/* SPARSEMEM_VMEMMAP & v4.19 kernel or later, or RHEL8 */
machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_4_19;
} else if (THIS_KERNEL_VERSION >= LINUX(3,7,0))
machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_3_7;
else
machdep->max_physmem_bits = _MAX_PHYSMEM_BITS;
return 0;
}
struct machine_specific ppc64_machine_specific = {
.hwintrstack = NULL,
.hwstackbuf = 0,
.hwstacksize = 0,
.pte_rpn_shift = PTE_RPN_SHIFT_DEFAULT,
._page_pte = 0x0UL,
._page_present = 0x1UL,
._page_user = 0x2UL,
._page_rw = 0x4UL,
._page_guarded = 0x8UL,
._page_coherent = 0x10UL,
._page_no_cache = 0x20UL,
._page_writethru = 0x40UL,
._page_dirty = 0x80UL,
._page_accessed = 0x100UL,
.is_kvaddr = generic_is_kvaddr,
.is_vmaddr = ppc64_is_vmaddr,
};
struct machine_specific book3e_machine_specific = {
.hwintrstack = NULL,
.hwstackbuf = 0,
.hwstacksize = 0,
.pte_rpn_shift = PTE_RPN_SHIFT_L4_BOOK3E_64K,
._page_pte = 0x0UL,
._page_present = 0x1UL,
._page_user = 0xCUL,
._page_rw = 0x30UL,
._page_guarded = 0x100000UL,
._page_coherent = 0x200000UL,
._page_no_cache = 0x400000UL,
._page_writethru = 0x800000UL,
._page_dirty = 0x1000UL,
._page_accessed = 0x40000UL,
.is_kvaddr = book3e_is_kvaddr,
.is_vmaddr = book3e_is_vmaddr,
};
/**
* No additional checks are required on PPC64, for checking if PRSTATUS notes
* is valid
*/
static int ppc64_is_cpu_prstatus_valid(int cpu)
{
return TRUE;
}
#define SKIBOOT_BASE 0x30000000
/*
* Do all necessary machine-specific setup here. This is called several
* times during initialization.
*/
void
ppc64_init(int when)
{
struct machine_specific *ms;
#if defined(__x86_64__)
if (ACTIVE())
error(FATAL, "compiled for the PPC64 architecture\n");
#endif
switch (when)
{
case SETUP_ENV:
machdep->process_elf_notes = process_elf64_notes;
break;
case PRE_SYMTAB:
machdep->machspec = &ppc64_machine_specific;
machdep->verify_symbol = ppc64_verify_symbol;
if (pc->flags & KERNEL_DEBUG_QUERY)
return;
machdep->stacksize = PPC64_STACK_SIZE;
machdep->last_pgd_read = 0;
machdep->last_pud_read = 0;
machdep->last_pmd_read = 0;
machdep->last_ptbl_read = 0;
machdep->verify_paddr = generic_verify_paddr;
machdep->ptrs_per_pgd = PTRS_PER_PGD;
machdep->flags |= MACHDEP_BT_TEXT;
if (machdep->cmdline_args[0])
parse_cmdline_args();
machdep->clear_machdep_cache = ppc64_clear_machdep_cache;
break;
case PRE_GDB:
/*
* Recently there were changes made to kexec tools
* to support 64K page size. With those changes
* vmcore file obtained from a kernel which supports
* 64K page size cannot be analyzed using crash on a
* machine running with kernel supporting 4K page size
*
* The following modifications are required in crash
* tool to be in sync with kexec tools.
*
* Look if the following symbol exists. If yes then
* the dump was taken with a kernel supporting 64k
* page size. So change the page size accordingly.
*
* Also moved the following code block from
* PRE_SYMTAB case here.
*/
if (symbol_exists("interrupt_base_book3e")) {
machdep->machspec = &book3e_machine_specific;
machdep->flags |= BOOK3E;
machdep->kvbase = BOOK3E_VMBASE;
} else
machdep->kvbase = symbol_value("_stext");
if (symbol_exists("__hash_page_64K"))
machdep->pagesize = PPC64_64K_PAGE_SIZE;
else
machdep->pagesize = memory_page_size();
machdep->pageshift = ffs(machdep->pagesize) - 1;
machdep->pageoffset = machdep->pagesize - 1;
machdep->pagemask = ~((ulonglong)machdep->pageoffset);
if ((machdep->pgd = (char *)malloc(PAGESIZE())) == NULL)
error(FATAL, "cannot malloc pgd space.");
if ((machdep->pud = (char *)malloc(PAGESIZE())) == NULL)
error(FATAL, "cannot malloc pud space.");
if ((machdep->pmd = (char *)malloc(PAGESIZE())) == NULL)
error(FATAL, "cannot malloc pmd space.");
if ((machdep->ptbl = (char *)malloc(PAGESIZE())) == NULL)
error(FATAL, "cannot malloc ptbl space.");
machdep->identity_map_base = symbol_value("_stext");
machdep->is_kvaddr = machdep->machspec->is_kvaddr;
machdep->is_uvaddr = generic_is_uvaddr;
machdep->eframe_search = ppc64_eframe_search;
machdep->back_trace = ppc64_back_trace_cmd;
machdep->processor_speed = ppc64_processor_speed;
machdep->uvtop = ppc64_uvtop;
machdep->kvtop = ppc64_kvtop;
machdep->get_task_pgd = ppc64_get_task_pgd;
machdep->get_stack_frame = ppc64_get_stack_frame;
machdep->get_stackbase = ppc64_get_stackbase;
machdep->get_stacktop = ppc64_get_stacktop;
machdep->translate_pte = ppc64_translate_pte;
machdep->memory_size = generic_memory_size;
machdep->is_task_addr = ppc64_is_task_addr;
machdep->dis_filter = ppc64_dis_filter;
machdep->cmd_mach = ppc64_cmd_mach;
machdep->get_smp_cpus = ppc64_get_smp_cpus;
machdep->line_number_hooks = ppc64_line_number_hooks;
machdep->value_to_symbol = generic_machdep_value_to_symbol;
machdep->get_kvaddr_ranges = ppc64_get_kvaddr_ranges;
machdep->init_kernel_pgd = NULL;
machdep->is_cpu_prstatus_valid = ppc64_is_cpu_prstatus_valid;
if (symbol_exists("vmemmap_populate")) {
if (symbol_exists("vmemmap")) {
readmem(symbol_value("vmemmap"), KVADDR,
&machdep->machspec->vmemmap_base,
sizeof(void *), "vmemmap", QUIET|FAULT_ON_ERROR);
} else
machdep->machspec->vmemmap_base =
VMEMMAP_REGION_ID << REGION_SHIFT;
machdep->flags |= VMEMMAP;
}
machdep->get_irq_affinity = generic_get_irq_affinity;
machdep->show_interrupts = generic_show_interrupts;
break;
case POST_GDB:
ms = machdep->machspec;
if (!(machdep->flags & BOOK3E)) {
/*
* To determine if the kernel was running on OPAL based platform,
* use struct opal, which is populated with relevant values.
*/
if (symbol_exists("opal")) {
get_symbol_data("opal", sizeof(struct ppc64_opal), &(ms->opal));
if (ms->opal.base == SKIBOOT_BASE)
machdep->flags |= OPAL_FW;
}
/*
* On Power ISA 3.0 based server processors, a kernel can
* run with radix MMU or standard MMU. Set the flag,
* if it is radix MMU.
*/
if (symbol_exists("cur_cpu_spec") &&
MEMBER_EXISTS("cpu_spec", "mmu_features")) {
ulong cur_cpu_spec;
uint mmu_features, offset;
get_symbol_data("cur_cpu_spec", sizeof(void *), &cur_cpu_spec);
offset = MEMBER_OFFSET("cpu_spec", "mmu_features");
readmem(cur_cpu_spec + offset, KVADDR, &mmu_features,
sizeof(uint), "cpu mmu features", FAULT_ON_ERROR);
machdep->flags |= (mmu_features & RADIX_MMU);
}
/*
* Starting with v3.14 we no longer use _PAGE_COHERENT
* bit as it is always set on hash64 and on platforms
* that cannot always set it, _PAGE_NO_CACHE and
* _PAGE_WRITETHRU can be used to infer it.
*/
if (THIS_KERNEL_VERSION >= LINUX(3,14,0))
ms->_page_coherent = 0x0UL;
/*
* In kernel v4.5, _PAGE_PTE bit is introduced to
* distinguish PTEs from pointers.
*/
if (THIS_KERNEL_VERSION >= LINUX(4,5,0)) {
ms->_page_pte = 0x1UL;
ms->_page_present = 0x2UL;
ms->_page_user = 0x4UL;
ms->_page_rw = 0x8UL;
ms->_page_guarded = 0x10UL;
}
/*
* Starting with kernel v4.6, to accommodate both
* radix and hash MMU modes in a single kernel,
* _PAGE_PTE & _PAGE_PRESENT page flags are changed.
* Also, page table entries store physical addresses.
*/
if (THIS_KERNEL_VERSION >= LINUX(4,6,0)) {
ms->_page_pte = 0x1UL << 62;
ms->_page_present = 0x1UL << 63;
machdep->flags |= PHYS_ENTRY_L4;
}
if (THIS_KERNEL_VERSION >= LINUX(4,7,0)) {
/*
* Starting with kernel v4.7 page table entries
* are always big endian on BOOK3S. Set this
* flag if kernel is not big endian.
*/
if (__BYTE_ORDER == __LITTLE_ENDIAN)
machdep->flags |= SWAP_ENTRY_L4;
}
}
if (!(machdep->flags & (VM_ORIG|VM_4_LEVEL))) {
if (THIS_KERNEL_VERSION >= LINUX(2,6,14)) {
machdep->flags |= VM_4_LEVEL;
} else {
machdep->flags |= VM_ORIG;
}
}
if (machdep->flags & VM_ORIG) {
/* pre-2.6.14 layout */
free(machdep->pud);
machdep->pud = NULL;
machdep->ptrs_per_pgd = PTRS_PER_PGD;
} else {
/* 2.6.14 layout */
if (machdep->pagesize == 65536) {
/* 64K pagesize */
if (machdep->flags & RADIX_MMU) {
ms->l1_index_size = PTE_INDEX_SIZE_RADIX_64K;
ms->l2_index_size = PMD_INDEX_SIZE_RADIX_64K;
ms->l3_index_size = PUD_INDEX_SIZE_RADIX_64K;
ms->l4_index_size = PGD_INDEX_SIZE_RADIX_64K;
} else if (!(machdep->flags & BOOK3E) &&
(THIS_KERNEL_VERSION >= LINUX(4,6,0))) {
ms->l1_index_size = PTE_INDEX_SIZE_L4_64K_3_10;
if (THIS_KERNEL_VERSION >= LINUX(4,12,0)) {
ms->l2_index_size = PMD_INDEX_SIZE_L4_64K_4_12;
if (THIS_KERNEL_VERSION >= LINUX(4,17,0))
ms->l3_index_size = PUD_INDEX_SIZE_L4_64K_4_17;
else
ms->l3_index_size = PUD_INDEX_SIZE_L4_64K_4_12;
ms->l4_index_size = PGD_INDEX_SIZE_L4_64K_4_12;
} else {
ms->l2_index_size = PMD_INDEX_SIZE_L4_64K_4_6;
ms->l3_index_size = PUD_INDEX_SIZE_L4_64K_4_6;
ms->l4_index_size = PGD_INDEX_SIZE_L4_64K_3_10;
}
} else if (THIS_KERNEL_VERSION >= LINUX(3,10,0)) {
ms->l1_index_size = PTE_INDEX_SIZE_L4_64K_3_10;
ms->l2_index_size = PMD_INDEX_SIZE_L4_64K_3_10;
ms->l3_index_size = PUD_INDEX_SIZE_L4_64K;
ms->l4_index_size = PGD_INDEX_SIZE_L4_64K_3_10;
} else {
ms->l1_index_size = PTE_INDEX_SIZE_L4_64K;
ms->l2_index_size = PMD_INDEX_SIZE_L4_64K;
ms->l3_index_size = PUD_INDEX_SIZE_L4_64K;
ms->l4_index_size = PGD_INDEX_SIZE_L4_64K;
}
if (!(machdep->flags & BOOK3E))
ms->pte_rpn_shift = symbol_exists("demote_segment_4k") ?
PTE_RPN_SHIFT_L4_64K_V2 : PTE_RPN_SHIFT_L4_64K_V1;
if (!(machdep->flags & BOOK3E) &&
(THIS_KERNEL_VERSION >= LINUX(4,6,0))) {
ms->pgd_masked_bits = PGD_MASKED_BITS_64K_4_6;
ms->pud_masked_bits = PUD_MASKED_BITS_64K_4_6;
ms->pmd_masked_bits = PMD_MASKED_BITS_64K_4_6;
} else {
ms->pgd_masked_bits = PGD_MASKED_BITS_64K;
ms->pud_masked_bits = PUD_MASKED_BITS_64K;
if ((machdep->flags & BOOK3E) &&
(THIS_KERNEL_VERSION >= LINUX(4,5,0)))
ms->pmd_masked_bits = PMD_MASKED_BITS_BOOK3E_64K_4_5;
else if (THIS_KERNEL_VERSION >= LINUX(3,11,0))
ms->pmd_masked_bits = PMD_MASKED_BITS_64K_3_11;
else
ms->pmd_masked_bits = PMD_MASKED_BITS_64K;
}
} else {
/* 4K pagesize */
if (machdep->flags & RADIX_MMU) {
ms->l1_index_size = PTE_INDEX_SIZE_RADIX_4K;
ms->l2_index_size = PMD_INDEX_SIZE_RADIX_4K;
ms->l3_index_size = PUD_INDEX_SIZE_RADIX_4K;
ms->l4_index_size = PGD_INDEX_SIZE_RADIX_4K;
} else {
ms->l1_index_size = PTE_INDEX_SIZE_L4_4K;
ms->l2_index_size = PMD_INDEX_SIZE_L4_4K;
if (THIS_KERNEL_VERSION >= LINUX(3,7,0))
ms->l3_index_size = PUD_INDEX_SIZE_L4_4K_3_7;
else
ms->l3_index_size = PUD_INDEX_SIZE_L4_4K;
ms->l4_index_size = PGD_INDEX_SIZE_L4_4K;
if (machdep->flags & BOOK3E)
ms->pte_rpn_shift = PTE_RPN_SHIFT_L4_BOOK3E_4K;
else
ms->pte_rpn_shift = THIS_KERNEL_VERSION >= LINUX(4,5,0) ?
PTE_RPN_SHIFT_L4_4K_4_5 : PTE_RPN_SHIFT_L4_4K;
}
ms->pgd_masked_bits = PGD_MASKED_BITS_4K;
ms->pud_masked_bits = PUD_MASKED_BITS_4K;
ms->pmd_masked_bits = PMD_MASKED_BITS_4K;
}
ms->pte_rpn_mask = PTE_RPN_MASK_DEFAULT;
if (!(machdep->flags & BOOK3E)) {
if (THIS_KERNEL_VERSION >= LINUX(4,6,0)) {
ms->pte_rpn_mask = PTE_RPN_MASK_L4_4_6;
ms->pte_rpn_shift = PTE_RPN_SHIFT_L4_4_6;
}
if (THIS_KERNEL_VERSION >= LINUX(4,7,0)) {
ms->pgd_masked_bits = PGD_MASKED_BITS_4_7;
ms->pud_masked_bits = PUD_MASKED_BITS_4_7;
ms->pmd_masked_bits = PMD_MASKED_BITS_4_7;
}
}
/* Compute ptrs per each level */
ms->l1_shift = machdep->pageshift;
ms->ptrs_per_l1 = (1 << ms->l1_index_size);
ms->ptrs_per_l2 = (1 << ms->l2_index_size);
ms->ptrs_per_l3 = (1 << ms->l3_index_size);
ms->ptrs_per_l4 = (1 << ms->l4_index_size);
machdep->ptrs_per_pgd = ms->ptrs_per_l4;
/* Compute shifts */
ms->l2_shift = ms->l1_shift + ms->l1_index_size;
ms->l3_shift = ms->l2_shift + ms->l2_index_size;
ms->l4_shift = ms->l3_shift + ms->l3_index_size;
}
if (machdep->flags & VMEMMAP)
ppc64_vmemmap_init();
machdep->section_size_bits = _SECTION_SIZE_BITS;
set_ppc64_max_physmem_bits();
ppc64_init_cpu_info();
machdep->vmalloc_start = ppc64_vmalloc_start;
MEMBER_OFFSET_INIT(thread_struct_pg_tables,
"thread_struct", "pg_tables");
STRUCT_SIZE_INIT(irqdesc, "irqdesc");
STRUCT_SIZE_INIT(irq_desc_t, "irq_desc_t");
if (INVALID_SIZE(irqdesc) && INVALID_SIZE(irq_desc_t))
STRUCT_SIZE_INIT(irq_desc_t, "irq_desc");
/* as of 2.3.x PPC uses the generic irq handlers */
if (VALID_SIZE(irq_desc_t))
machdep->dump_irq = generic_dump_irq;
else {
machdep->dump_irq = ppc64_dump_irq;
MEMBER_OFFSET_INIT(irqdesc_action, "irqdesc", "action");
MEMBER_OFFSET_INIT(irqdesc_ctl, "irqdesc", "ctl");
MEMBER_OFFSET_INIT(irqdesc_level, "irqdesc", "level");
}
MEMBER_OFFSET_INIT(device_node_type, "device_node", "type");
MEMBER_OFFSET_INIT(device_node_allnext,
"device_node", "allnext");
MEMBER_OFFSET_INIT(device_node_properties,
"device_node", "properties");
MEMBER_OFFSET_INIT(property_name, "property", "name");
MEMBER_OFFSET_INIT(property_value, "property", "value");
MEMBER_OFFSET_INIT(property_next, "property", "next");
MEMBER_OFFSET_INIT(machdep_calls_setup_residual,
"machdep_calls", "setup_residual");
MEMBER_OFFSET_INIT(RESIDUAL_VitalProductData,
"RESIDUAL", "VitalProductData");
MEMBER_OFFSET_INIT(VPD_ProcessorHz, "VPD", "ProcessorHz");
MEMBER_OFFSET_INIT(bd_info_bi_intfreq, "bd_info", "bi_intfreq");
if (symbol_exists("irq_desc"))
ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_desc,
"irq_desc", NULL, 0);
else if (kernel_symbol_exists("nr_irqs"))
get_symbol_data("nr_irqs", sizeof(unsigned int),
&machdep->nr_irqs);
else
machdep->nr_irqs = 0;
if (symbol_exists("paca") &&
MEMBER_EXISTS("paca_struct", "xHrdIntStack")) {
ulong paca_sym, offset;
uint cpu, paca_size = STRUCT_SIZE("paca_struct");
/*
* Get the HW Interrupt stack base and top values.
* Note that, this stack will be used to store frames
* when the CPU received IPI (only for 2.4 kernel).
* Hence it is needed to retrieve IPI symbols
* (Ex: smp_message_recv, xics_ipi_action, and etc)
* and to get the top SP in the process's stack.
*/
offset = MEMBER_OFFSET("paca_struct", "xHrdIntStack");
paca_sym = symbol_value("paca");
if (!(ms->hwintrstack = (ulong *)calloc(NR_CPUS, sizeof(ulong))))
error(FATAL, "cannot malloc hwintrstack space.");
for (cpu = 0; cpu < kt->cpus; cpu++) {
readmem(paca_sym + (paca_size * cpu) + offset, KVADDR,
&ms->hwintrstack[cpu], sizeof(ulong),
"PPC64 HW_intr_stack", FAULT_ON_ERROR);
}
ms->hwstacksize = 8 * machdep->pagesize;
if ((ms->hwstackbuf = (char *)malloc(ms->hwstacksize)) == NULL)
error(FATAL, "cannot malloc hwirqstack buffer space.");
}
machdep->get_current_task_reg = ppc64_get_current_task_reg;
ppc64_init_paca_info();
if (!machdep->hz) {
machdep->hz = HZ;
if (THIS_KERNEL_VERSION >= LINUX(2,6,0))
machdep->hz = 1000;
}
/*
* IRQ stacks are introduced in 2.6 and also configurable.
*/
if ((THIS_KERNEL_VERSION >= LINUX(2,6,0)) &&
symbol_exists("hardirq_ctx"))
ASSIGN_SIZE(irq_ctx) = STACKSIZE();
break;
case POST_INIT:
break;
case LOG_ONLY:
machdep->identity_map_base = kt->vmcoreinfo._stext_SYMBOL;
break;
}
}
#ifndef KSYMS_START
#define KSYMS_START 1
#endif
static ulong
ppc64_task_to_stackbase(ulong task)
{
ulong stackbase;
if (tt->flags & THREAD_INFO_IN_TASK) {
readmem(task + OFFSET(task_struct_stack), KVADDR, &stackbase,
sizeof(void *), "task_struct.stack", FAULT_ON_ERROR);
return stackbase;
} else if (tt->flags & THREAD_INFO)
return task_to_thread_info(task);
else
return task;
}
static ulong
ppc64_get_stackbase(ulong task)
{
return ppc64_task_to_stackbase(task);
}
static ulong
ppc64_get_stacktop(ulong task)
{
return ppc64_task_to_stackbase(task) + STACKSIZE();
}
void
ppc64_dump_machdep_table(ulong arg)
{
struct machine_specific *ms = machdep->machspec;
int i, c, others;
others = 0;
fprintf(fp, " flags: %lx (", machdep->flags);
if (machdep->flags & KSYMS_START)
fprintf(fp, "%sKSYMS_START", others++ ? "|" : "");
if (machdep->flags & MACHDEP_BT_TEXT)
fprintf(fp, "%sMACHDEP_BT_TEXT", others++ ? "|" : "");
if (machdep->flags & VM_ORIG)
fprintf(fp, "%sVM_ORIG", others++ ? "|" : "");
if (machdep->flags & VM_4_LEVEL)
fprintf(fp, "%sVM_4_LEVEL", others++ ? "|" : "");
if (machdep->flags & VMEMMAP)
fprintf(fp, "%sVMEMMAP", others++ ? "|" : "");
if (machdep->flags & VMEMMAP_AWARE)
fprintf(fp, "%sVMEMMAP_AWARE", others++ ? "|" : "");
if (machdep->flags & BOOK3E)
fprintf(fp, "%sBOOK3E", others++ ? "|" : "");
if (machdep->flags & PHYS_ENTRY_L4)
fprintf(fp, "%sPHYS_ENTRY_L4", others++ ? "|" : "");
if (machdep->flags & SWAP_ENTRY_L4)
fprintf(fp, "%sSWAP_ENTRY_L4", others++ ? "|" : "");
if (machdep->flags & RADIX_MMU)
fprintf(fp, "%sRADIX_MMU", others++ ? "|" : "");
if (machdep->flags & OPAL_FW)
fprintf(fp, "%sOPAL_FW", others++ ? "|" : "");
fprintf(fp, ")\n");
fprintf(fp, " kvbase: %lx\n", machdep->kvbase);
fprintf(fp, " identity_map_base: %lx\n", machdep->identity_map_base);
fprintf(fp, " pagesize: %d\n", machdep->pagesize);
fprintf(fp, " pageshift: %d\n", machdep->pageshift);
fprintf(fp, " pagemask: %llx\n", machdep->pagemask);
fprintf(fp, " pageoffset: %lx\n", machdep->pageoffset);
fprintf(fp, " stacksize: %ld\n", machdep->stacksize);
fprintf(fp, " hz: %d\n", machdep->hz);
fprintf(fp, " mhz: %ld\n", machdep->mhz);
fprintf(fp, " memsize: %ld (0x%lx)\n",
machdep->memsize, machdep->memsize);
fprintf(fp, " bits: %d\n", machdep->bits);
fprintf(fp, " nr_irqs: %d\n", machdep->nr_irqs);
fprintf(fp, " eframe_search: ppc64_eframe_search()\n");
fprintf(fp, " back_trace: ppc64_back_trace_cmd()\n");
fprintf(fp, " processor_speed: ppc64_processor_speed()\n");
fprintf(fp, " uvtop: ppc64_uvtop()\n");
fprintf(fp, " kvtop: ppc64_kvtop()\n");
fprintf(fp, " get_task_pgd: ppc64_get_task_pgd()\n");
fprintf(fp, " dump_irq: ppc64_dump_irq()\n");
fprintf(fp, " get_stack_frame: ppc64_get_stack_frame()\n");
fprintf(fp, " get_stackbase: ppc64_get_stackbase()\n");
fprintf(fp, " get_stacktop: ppc64_get_stacktop()\n");
fprintf(fp, " translate_pte: ppc64_translate_pte()\n");
fprintf(fp, " memory_size: generic_memory_size()\n");
fprintf(fp, " vmalloc_start: ppc64_vmalloc_start()\n");
fprintf(fp, " is_task_addr: ppc64_is_task_addr()\n");
fprintf(fp, " verify_symbol: ppc64_verify_symbol()\n");
fprintf(fp, " dis_filter: ppc64_dis_filter()\n");
fprintf(fp, " cmd_mach: ppc64_cmd_mach()\n");
fprintf(fp, " get_smp_cpus: ppc64_get_smp_cpus()\n");
fprintf(fp, " is_kvaddr: %s\n",
machdep->is_kvaddr == book3e_is_kvaddr ?
"book3e_is_kvaddr()" : "generic_is_kvaddr()");
fprintf(fp, " is_uvaddr: generic_is_uvaddr()\n");
fprintf(fp, " verify_paddr: generic_verify_paddr()\n");
fprintf(fp, " get_kvaddr_ranges: ppc64_get_kvaddr_ranges()\n");
fprintf(fp, " get_irq_affinity: generic_get_irq_affinity()\n");
fprintf(fp, " show_interrupts: generic_show_interrupts()\n");
fprintf(fp, " xendump_p2m_create: NULL\n");
fprintf(fp, "xen_kdump_p2m_create: NULL\n");
fprintf(fp, " line_number_hooks: ppc64_line_number_hooks\n");
fprintf(fp, " last_pgd_read: %lx\n", machdep->last_pgd_read);
fprintf(fp, " last_pud_read: %lx\n", machdep->last_pud_read);
fprintf(fp, " last_pmd_read: %lx\n", machdep->last_pmd_read);
fprintf(fp, " last_ptbl_read: %lx\n", machdep->last_ptbl_read);
fprintf(fp, "clear_machdep_cache: ppc64_clear_machdep_cache()\n");
fprintf(fp, " pgd: %lx\n", (ulong)machdep->pgd);
fprintf(fp, " pud: %lx\n", (ulong)machdep->pud);
fprintf(fp, " pmd: %lx\n", (ulong)machdep->pmd);
fprintf(fp, " ptbl: %lx\n", (ulong)machdep->ptbl);
fprintf(fp, " ptrs_per_pgd: %d\n", machdep->ptrs_per_pgd);
fprintf(fp, " section_size_bits: %ld\n", machdep->section_size_bits);
fprintf(fp, " max_physmem_bits: %ld\n", machdep->max_physmem_bits);
fprintf(fp, " sections_per_root: %ld\n", machdep->sections_per_root);
for (i = 0; i < MAX_MACHDEP_ARGS; i++) {
fprintf(fp, " cmdline_args[%d]: %s\n",
i, machdep->cmdline_args[i] ?
machdep->cmdline_args[i] : "(unused)");
}
fprintf(fp, " machspec: %lx\n", (ulong)ms);
fprintf(fp, " is_kvaddr: %s\n",
ms->is_kvaddr == book3e_is_kvaddr ?
"book3e_is_kvaddr()" : "generic_is_kvaddr()");
fprintf(fp, " is_vmaddr: %s\n",
ms->is_vmaddr == book3e_is_vmaddr ?
"book3e_is_vmaddr()" : "ppc64_is_vmaddr()");
if (ms->hwintrstack) {
fprintf(fp, " hwintrstack[%d]: ", NR_CPUS);
for (c = 0; c < NR_CPUS; c++) {
fprintf(fp, "%s%016lx ",
((c % 4) == 0) ? "\n " : "",
ms->hwintrstack[c]);
}
} else
fprintf(fp, " hwintrstack: (unused)");
fprintf(fp, "\n");
fprintf(fp, " hwstackbuf: %lx\n", (ulong)ms->hwstackbuf);
fprintf(fp, " hwstacksize: %d\n", ms->hwstacksize);
fprintf(fp, " l4_index_size: %d\n", ms->l4_index_size);
fprintf(fp, " l3_index_size: %d\n", ms->l3_index_size);
fprintf(fp, " l2_index_size: %d\n", ms->l2_index_size);
fprintf(fp, " l1_index_size: %d\n", ms->l1_index_size);
fprintf(fp, " ptrs_per_l4: %d\n", ms->ptrs_per_l4);
fprintf(fp, " ptrs_per_l3: %d\n", ms->ptrs_per_l3);
fprintf(fp, " ptrs_per_l2: %d\n", ms->ptrs_per_l2);
fprintf(fp, " ptrs_per_l1: %d\n", ms->ptrs_per_l1);
fprintf(fp, " l4_shift: %d\n", ms->l4_shift);
fprintf(fp, " l3_shift: %d\n", ms->l3_shift);
fprintf(fp, " l2_shift: %d\n", ms->l2_shift);
fprintf(fp, " l1_shift: %d\n", ms->l1_shift);
fprintf(fp, " pte_rpn_mask: %lx\n", ms->pte_rpn_mask);
fprintf(fp, " pte_rpn_shift: %d\n", ms->pte_rpn_shift);
fprintf(fp, " pgd_masked_bits: %lx\n", ms->pgd_masked_bits);
fprintf(fp, " pud_masked_bits: %lx\n", ms->pud_masked_bits);
fprintf(fp, " pmd_masked_bits: %lx\n", ms->pmd_masked_bits);
fprintf(fp, " vmemmap_base: ");
if (ms->vmemmap_base)
fprintf(fp, "%lx\n", ms->vmemmap_base);
else
fprintf(fp, "(unused)\n");
if (ms->vmemmap_cnt) {
fprintf(fp, " vmemmap_cnt: %d\n",
ms->vmemmap_cnt);
fprintf(fp, " vmemmap_psize: %d\n",
ms->vmemmap_psize);
for (i = 0; i < ms->vmemmap_cnt; i++) {
fprintf(fp,
" vmemmap_list[%d]: virt: %lx phys: %lx\n", i,
ms->vmemmap_list[i].virt,
ms->vmemmap_list[i].phys);
}
} else {
fprintf(fp, " vmemmap_cnt: (unused)\n");
fprintf(fp, " vmemmap_page_size: (unused)\n");
fprintf(fp, " vmemmap_list[]: (unused)\n");
}
}
/*
* Virtual to physical memory translation. This function will be called
* by both ppc64_kvtop and ppc64_uvtop.
*/
static int
ppc64_vtop(ulong vaddr, ulong *pgd, physaddr_t *paddr, int verbose)
{
ulong *page_dir;
ulong *page_middle;
ulong *page_table;
ulong pgd_pte, pmd_pte;
ulong pte;
if (verbose)
fprintf(fp, "PAGE DIRECTORY: %lx\n", (ulong)pgd);
if (THIS_KERNEL_VERSION < LINUX(2,6,0))
page_dir = (ulong *)((uint *)pgd + PGD_OFFSET_24(vaddr));
else
page_dir = (ulong *)((uint *)pgd + PGD_OFFSET(vaddr));
FILL_PGD(PAGEBASE(pgd), KVADDR, PAGESIZE());
pgd_pte = UINT(machdep->pgd + PAGEOFFSET(page_dir));
if (verbose)
fprintf(fp, " PGD: %lx => %lx\n", (ulong)page_dir, pgd_pte);
if (!pgd_pte)
return FALSE;
pgd_pte <<= PAGESHIFT();
page_middle = (ulong *)((uint *)pgd_pte + PMD_OFFSET(vaddr));
FILL_PMD(PTOV(PAGEBASE(pgd_pte)), KVADDR, PAGESIZE());
pmd_pte = UINT(machdep->pmd + PAGEOFFSET(page_middle));
if (verbose)
fprintf(fp, " PMD: %lx => %lx\n", (ulong)page_middle, pmd_pte);
if (!(pmd_pte))
return FALSE;
if (THIS_KERNEL_VERSION < LINUX(2,6,0))
pmd_pte <<= PAGESHIFT();
else
pmd_pte = ((pmd_pte << PAGESHIFT()) >> PMD_TO_PTEPAGE_SHIFT);
page_table = (ulong *)pmd_pte + (BTOP(vaddr) & (PTRS_PER_PTE - 1));
if (verbose)
fprintf(fp, " PMD: %lx => %lx\n",(ulong)page_middle,
(ulong)page_table);
FILL_PTBL(PTOV(PAGEBASE(pmd_pte)), KVADDR, PAGESIZE());
pte = ULONG(machdep->ptbl + PAGEOFFSET(page_table));
if (verbose)
fprintf(fp, " PTE: %lx => %lx\n", (ulong)page_table, pte);
if (!(pte & _PAGE_PRESENT)) {
if (pte && verbose) {
fprintf(fp, "\n");
ppc64_translate_pte(pte, 0, PTE_RPN_SHIFT_DEFAULT);
}
return FALSE;
}
*paddr = PAGEBASE(PTOB(pte >> PTE_RPN_SHIFT_DEFAULT)) + PAGEOFFSET(vaddr);
if (verbose) {
fprintf(fp, " PAGE: %lx\n\n", PAGEBASE(*paddr));
ppc64_translate_pte(pte, 0, PTE_RPN_SHIFT_DEFAULT);
}
return TRUE;
}
/*