Skip to content

Commit b1923ca

Browse files
ozbenhmpe
authored andcommitted
powerpc: Merge 32-bit and 64-bit setup_arch()
There is little enough differences now. mpe: Add a/p/k/setup.h to contain the prototypes and empty versions of functions we need, rather than using weak functions. Add a few other empty versions to avoid as many #ifdefs as possible in the code. Signed-off-by: Benjamin Herrenschmidt <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 009776b commit b1923ca

File tree

6 files changed

+250
-233
lines changed

6 files changed

+250
-233
lines changed

arch/powerpc/include/asm/rtas.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ extern bool rtas_indicator_present(int token, int *maxindex);
351351
extern int rtas_set_indicator(int indicator, int index, int new_value);
352352
extern int rtas_set_indicator_fast(int indicator, int index, int new_value);
353353
extern void rtas_progress(char *s, unsigned short hex);
354-
extern void rtas_initialize(void);
355354
extern int rtas_suspend_cpu(struct rtas_suspend_me_data *data);
356355
extern int rtas_suspend_last_cpu(struct rtas_suspend_me_data *data);
357356
extern int rtas_online_cpus_mask(cpumask_var_t cpus);
@@ -460,9 +459,11 @@ static inline int page_is_rtas_user_buf(unsigned long pfn)
460459
/* Not the best place to put pSeries_coalesce_init, will be fixed when we
461460
* move some of the rtas suspend-me stuff to pseries */
462461
extern void pSeries_coalesce_init(void);
462+
void rtas_initialize(void);
463463
#else
464464
static inline int page_is_rtas_user_buf(unsigned long pfn) { return 0;}
465465
static inline void pSeries_coalesce_init(void) { }
466+
static inline void rtas_initialize(void) { };
466467
#endif
467468

468469
extern int call_rtas(const char *, int, int, unsigned long *, ...);

arch/powerpc/include/asm/smp.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@ static inline void set_hard_smp_processor_id(int cpu, int phys)
160160
{
161161
paca[cpu].hw_cpu_id = phys;
162162
}
163-
164-
extern void smp_release_cpus(void);
165-
166163
#else
167164
/* 32-bit */
168165
#ifndef CONFIG_SMP
@@ -179,6 +176,12 @@ static inline void set_hard_smp_processor_id(int cpu, int phys)
179176
#endif /* !CONFIG_SMP */
180177
#endif /* !CONFIG_PPC64 */
181178

179+
#if defined(CONFIG_PPC64) && (defined(CONFIG_SMP) || defined(CONFIG_KEXEC))
180+
extern void smp_release_cpus(void);
181+
#else
182+
static inline void smp_release_cpus(void) { };
183+
#endif
184+
182185
extern int smt_enabled_at_boot;
183186

184187
extern void smp_mpic_probe(void);

arch/powerpc/kernel/setup-common.c

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/percpu.h>
3636
#include <linux/memblock.h>
3737
#include <linux/of_platform.h>
38+
#include <linux/hugetlb.h>
3839
#include <asm/io.h>
3940
#include <asm/paca.h>
4041
#include <asm/prom.h>
@@ -61,6 +62,12 @@
6162
#include <asm/cputhreads.h>
6263
#include <mm/mmu_decl.h>
6364
#include <asm/fadump.h>
65+
#include <asm/udbg.h>
66+
#include <asm/hugetlb.h>
67+
#include <asm/livepatch.h>
68+
#include <asm/mmu_context.h>
69+
70+
#include "setup.h"
6471

6572
#ifdef DEBUG
6673
#include <asm/udbg.h>
@@ -758,3 +765,169 @@ void arch_setup_pdev_archdata(struct platform_device *pdev)
758765
pdev->dev.dma_mask = &pdev->archdata.dma_mask;
759766
set_dma_ops(&pdev->dev, &dma_direct_ops);
760767
}
768+
769+
static __init void print_system_info(void)
770+
{
771+
pr_info("-----------------------------------------------------\n");
772+
#ifdef CONFIG_PPC_STD_MMU_64
773+
pr_info("ppc64_pft_size = 0x%llx\n", ppc64_pft_size);
774+
#endif
775+
#ifdef CONFIG_PPC_STD_MMU_32
776+
pr_info("Hash_size = 0x%lx\n", Hash_size);
777+
#endif
778+
pr_info("phys_mem_size = 0x%llx\n",
779+
(unsigned long long)memblock_phys_mem_size());
780+
781+
pr_info("dcache_bsize = 0x%x\n", dcache_bsize);
782+
pr_info("icache_bsize = 0x%x\n", icache_bsize);
783+
if (ucache_bsize != 0)
784+
pr_info("ucache_bsize = 0x%x\n", ucache_bsize);
785+
786+
pr_info("cpu_features = 0x%016lx\n", cur_cpu_spec->cpu_features);
787+
pr_info(" possible = 0x%016lx\n",
788+
(unsigned long)CPU_FTRS_POSSIBLE);
789+
pr_info(" always = 0x%016lx\n",
790+
(unsigned long)CPU_FTRS_ALWAYS);
791+
pr_info("cpu_user_features = 0x%08x 0x%08x\n",
792+
cur_cpu_spec->cpu_user_features,
793+
cur_cpu_spec->cpu_user_features2);
794+
pr_info("mmu_features = 0x%08x\n", cur_cpu_spec->mmu_features);
795+
#ifdef CONFIG_PPC64
796+
pr_info("firmware_features = 0x%016lx\n", powerpc_firmware_features);
797+
#endif
798+
799+
#ifdef CONFIG_PPC_STD_MMU_64
800+
if (htab_address)
801+
pr_info("htab_address = 0x%p\n", htab_address);
802+
if (htab_hash_mask)
803+
pr_info("htab_hash_mask = 0x%lx\n", htab_hash_mask);
804+
#endif
805+
#ifdef CONFIG_PPC_STD_MMU_32
806+
if (Hash)
807+
pr_info("Hash = 0x%p\n", Hash);
808+
if (Hash_mask)
809+
pr_info("Hash_mask = 0x%lx\n", Hash_mask);
810+
#endif
811+
812+
if (PHYSICAL_START > 0)
813+
pr_info("physical_start = 0x%llx\n",
814+
(unsigned long long)PHYSICAL_START);
815+
pr_info("-----------------------------------------------------\n");
816+
}
817+
818+
/*
819+
* Called into from start_kernel this initializes memblock, which is used
820+
* to manage page allocation until mem_init is called.
821+
*/
822+
void __init setup_arch(char **cmdline_p)
823+
{
824+
*cmdline_p = boot_command_line;
825+
826+
/* Set a half-reasonable default so udelay does something sensible */
827+
loops_per_jiffy = 500000000 / HZ;
828+
829+
/* Unflatten the device-tree passed by prom_init or kexec */
830+
unflatten_device_tree();
831+
832+
/*
833+
* Initialize cache line/block info from device-tree (on ppc64) or
834+
* just cputable (on ppc32).
835+
*/
836+
initialize_cache_info();
837+
838+
/* Initialize RTAS if available. */
839+
rtas_initialize();
840+
841+
/* Check if we have an initrd provided via the device-tree. */
842+
check_for_initrd();
843+
844+
/* Probe the machine type, establish ppc_md. */
845+
probe_machine();
846+
847+
/* Setup panic notifier if requested by the platform. */
848+
setup_panic();
849+
850+
/*
851+
* Configure ppc_md.power_save (ppc32 only, 64-bit machines do
852+
* it from their respective probe() function.
853+
*/
854+
setup_power_save();
855+
856+
/* Discover standard serial ports. */
857+
find_legacy_serial_ports();
858+
859+
/* Register early console with the printk subsystem. */
860+
register_early_udbg_console();
861+
862+
/* Setup the various CPU maps based on the device-tree. */
863+
smp_setup_cpu_maps();
864+
865+
/* Initialize xmon. */
866+
xmon_setup();
867+
868+
/* Check the SMT related command line arguments (ppc64). */
869+
check_smt_enabled();
870+
871+
/* On BookE, setup per-core TLB data structures. */
872+
setup_tlb_core_data();
873+
874+
/*
875+
* Release secondary cpus out of their spinloops at 0x60 now that
876+
* we can map physical -> logical CPU ids.
877+
*
878+
* Freescale Book3e parts spin in a loop provided by firmware,
879+
* so smp_release_cpus() does nothing for them.
880+
*/
881+
#ifdef CONFIG_SMP
882+
smp_release_cpus();
883+
#endif
884+
885+
/* Print various info about the machine that has been gathered so far. */
886+
print_system_info();
887+
888+
/* Reserve large chunks of memory for use by CMA for KVM. */
889+
kvm_cma_reserve();
890+
891+
/*
892+
* Reserve any gigantic pages requested on the command line.
893+
* memblock needs to have been initialized by the time this is
894+
* called since this will reserve memory.
895+
*/
896+
reserve_hugetlb_gpages();
897+
898+
klp_init_thread_info(&init_thread_info);
899+
900+
init_mm.start_code = (unsigned long)_stext;
901+
init_mm.end_code = (unsigned long) _etext;
902+
init_mm.end_data = (unsigned long) _edata;
903+
init_mm.brk = klimit;
904+
#ifdef CONFIG_PPC_64K_PAGES
905+
init_mm.context.pte_frag = NULL;
906+
#endif
907+
#ifdef CONFIG_SPAPR_TCE_IOMMU
908+
mm_iommu_init(&init_mm.context);
909+
#endif
910+
irqstack_early_init();
911+
exc_lvl_early_init();
912+
emergency_stack_init();
913+
914+
initmem_init();
915+
916+
#ifdef CONFIG_DUMMY_CONSOLE
917+
conswitchp = &dummy_con;
918+
#endif
919+
if (ppc_md.setup_arch)
920+
ppc_md.setup_arch();
921+
922+
paging_init();
923+
924+
/* Initialize the MMU context management stuff. */
925+
mmu_context_init();
926+
927+
#ifdef CONFIG_PPC64
928+
/* Interrupt code needs to be 64K-aligned. */
929+
if ((unsigned long)_stext & 0xffff)
930+
panic("Kernelbase not 64K-aligned (0x%lx)!\n",
931+
(unsigned long)_stext);
932+
#endif
933+
}

arch/powerpc/kernel/setup.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Prototypes for functions that are shared between setup_(32|64|common).c
3+
*
4+
* Copyright 2016 Michael Ellerman, IBM Corporation.
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* as published by the Free Software Foundation; either version
9+
* 2 of the License, or (at your option) any later version.
10+
*/
11+
12+
#ifndef __ARCH_POWERPC_KERNEL_SETUP_H
13+
#define __ARCH_POWERPC_KERNEL_SETUP_H
14+
15+
void initialize_cache_info(void);
16+
void irqstack_early_init(void);
17+
18+
#ifdef CONFIG_PPC32
19+
void setup_power_save(void);
20+
#else
21+
static inline void setup_power_save(void) { };
22+
#endif
23+
24+
#if defined(CONFIG_PPC64) && defined(CONFIG_SMP)
25+
void check_smt_enabled(void);
26+
#else
27+
static inline void check_smt_enabled(void) { };
28+
#endif
29+
30+
#if defined(CONFIG_PPC_BOOK3E) && defined(CONFIG_SMP)
31+
void setup_tlb_core_data(void);
32+
#else
33+
static inline void setup_tlb_core_data(void) { };
34+
#endif
35+
36+
#if defined(CONFIG_PPC_BOOK3E) || defined(CONFIG_BOOKE) || defined(CONFIG_40x)
37+
void exc_lvl_early_init(void);
38+
#else
39+
static inline void exc_lvl_early_init(void) { };
40+
#endif
41+
42+
#ifdef CONFIG_PPC64
43+
void emergency_stack_init(void);
44+
#else
45+
static inline void emergency_stack_init(void) { };
46+
#endif
47+
48+
/*
49+
* Having this in kvm_ppc.h makes include dependencies too
50+
* tricky to solve for setup-common.c so have it here.
51+
*/
52+
#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
53+
void kvm_cma_reserve(void);
54+
#else
55+
static inline void kvm_cma_reserve(void) { };
56+
#endif
57+
58+
#endif /* __ARCH_POWERPC_KERNEL_SETUP_H */

arch/powerpc/kernel/setup_32.c

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include <asm/time.h>
3737
#include <asm/serial.h>
3838
#include <asm/udbg.h>
39-
#include <asm/mmu_context.h>
4039
#include <asm/code-patching.h>
4140

4241
#define DBG(fmt...)
@@ -191,7 +190,7 @@ int __init ppc_init(void)
191190

192191
arch_initcall(ppc_init);
193192

194-
static void __init irqstack_early_init(void)
193+
void __init irqstack_early_init(void)
195194
{
196195
unsigned int i;
197196

@@ -206,7 +205,7 @@ static void __init irqstack_early_init(void)
206205
}
207206

208207
#if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
209-
static void __init exc_lvl_early_init(void)
208+
void __init exc_lvl_early_init(void)
210209
{
211210
unsigned int i, hw_cpu;
212211

@@ -229,11 +228,9 @@ static void __init exc_lvl_early_init(void)
229228
#endif
230229
}
231230
}
232-
#else
233-
#define exc_lvl_early_init()
234231
#endif
235232

236-
static void setup_power_save(void)
233+
void __init setup_power_save(void)
237234
{
238235
#ifdef CONFIG_6xx
239236
if (cpu_has_feature(CPU_FTR_CAN_DOZE) ||
@@ -248,7 +245,7 @@ static void setup_power_save(void)
248245
#endif
249246
}
250247

251-
static __init void initialize_cache_info(void)
248+
__init void initialize_cache_info(void)
252249
{
253250
/*
254251
* Set cache line size based on type of cpu as a default.
@@ -261,57 +258,3 @@ static __init void initialize_cache_info(void)
261258
if (cpu_has_feature(CPU_FTR_UNIFIED_ID_CACHE))
262259
ucache_bsize = icache_bsize = dcache_bsize;
263260
}
264-
265-
266-
/* Warning, IO base is not yet inited */
267-
void __init setup_arch(char **cmdline_p)
268-
{
269-
*cmdline_p = boot_command_line;
270-
271-
/* so udelay does something sensible, assume <= 1000 bogomips */
272-
loops_per_jiffy = 500000000 / HZ;
273-
274-
unflatten_device_tree();
275-
initialize_cache_info();
276-
check_for_initrd();
277-
278-
probe_machine();
279-
280-
setup_panic();
281-
282-
setup_power_save();
283-
284-
find_legacy_serial_ports();
285-
286-
/* Register early console */
287-
register_early_udbg_console();
288-
289-
smp_setup_cpu_maps();
290-
291-
xmon_setup();
292-
293-
init_mm.start_code = (unsigned long)_stext;
294-
init_mm.end_code = (unsigned long) _etext;
295-
init_mm.end_data = (unsigned long) _edata;
296-
init_mm.brk = klimit;
297-
298-
exc_lvl_early_init();
299-
300-
irqstack_early_init();
301-
302-
initmem_init();
303-
if ( ppc_md.progress ) ppc_md.progress("setup_arch: initmem", 0x3eab);
304-
305-
#ifdef CONFIG_DUMMY_CONSOLE
306-
conswitchp = &dummy_con;
307-
#endif
308-
309-
if (ppc_md.setup_arch)
310-
ppc_md.setup_arch();
311-
if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
312-
313-
paging_init();
314-
315-
/* Initialize the MMU context management stuff */
316-
mmu_context_init();
317-
}

0 commit comments

Comments
 (0)