Skip to content

Commit

Permalink
powerpc: Merge 32-bit and 64-bit setup_arch()
Browse files Browse the repository at this point in the history
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 <benh@kernel.crashing.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
  • Loading branch information
Benjamin Herrenschmidt authored and Michael Ellerman committed Jul 21, 2016
1 parent 009776b commit b1923ca
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 233 deletions.
3 changes: 2 additions & 1 deletion arch/powerpc/include/asm/rtas.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ extern bool rtas_indicator_present(int token, int *maxindex);
extern int rtas_set_indicator(int indicator, int index, int new_value);
extern int rtas_set_indicator_fast(int indicator, int index, int new_value);
extern void rtas_progress(char *s, unsigned short hex);
extern void rtas_initialize(void);
extern int rtas_suspend_cpu(struct rtas_suspend_me_data *data);
extern int rtas_suspend_last_cpu(struct rtas_suspend_me_data *data);
extern int rtas_online_cpus_mask(cpumask_var_t cpus);
Expand Down Expand Up @@ -460,9 +459,11 @@ static inline int page_is_rtas_user_buf(unsigned long pfn)
/* Not the best place to put pSeries_coalesce_init, will be fixed when we
* move some of the rtas suspend-me stuff to pseries */
extern void pSeries_coalesce_init(void);
void rtas_initialize(void);
#else
static inline int page_is_rtas_user_buf(unsigned long pfn) { return 0;}
static inline void pSeries_coalesce_init(void) { }
static inline void rtas_initialize(void) { };
#endif

extern int call_rtas(const char *, int, int, unsigned long *, ...);
Expand Down
9 changes: 6 additions & 3 deletions arch/powerpc/include/asm/smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ static inline void set_hard_smp_processor_id(int cpu, int phys)
{
paca[cpu].hw_cpu_id = phys;
}

extern void smp_release_cpus(void);

#else
/* 32-bit */
#ifndef CONFIG_SMP
Expand All @@ -179,6 +176,12 @@ static inline void set_hard_smp_processor_id(int cpu, int phys)
#endif /* !CONFIG_SMP */
#endif /* !CONFIG_PPC64 */

#if defined(CONFIG_PPC64) && (defined(CONFIG_SMP) || defined(CONFIG_KEXEC))
extern void smp_release_cpus(void);
#else
static inline void smp_release_cpus(void) { };
#endif

extern int smt_enabled_at_boot;

extern void smp_mpic_probe(void);
Expand Down
173 changes: 173 additions & 0 deletions arch/powerpc/kernel/setup-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <linux/percpu.h>
#include <linux/memblock.h>
#include <linux/of_platform.h>
#include <linux/hugetlb.h>
#include <asm/io.h>
#include <asm/paca.h>
#include <asm/prom.h>
Expand All @@ -61,6 +62,12 @@
#include <asm/cputhreads.h>
#include <mm/mmu_decl.h>
#include <asm/fadump.h>
#include <asm/udbg.h>
#include <asm/hugetlb.h>
#include <asm/livepatch.h>
#include <asm/mmu_context.h>

#include "setup.h"

#ifdef DEBUG
#include <asm/udbg.h>
Expand Down Expand Up @@ -758,3 +765,169 @@ void arch_setup_pdev_archdata(struct platform_device *pdev)
pdev->dev.dma_mask = &pdev->archdata.dma_mask;
set_dma_ops(&pdev->dev, &dma_direct_ops);
}

static __init void print_system_info(void)
{
pr_info("-----------------------------------------------------\n");
#ifdef CONFIG_PPC_STD_MMU_64
pr_info("ppc64_pft_size = 0x%llx\n", ppc64_pft_size);
#endif
#ifdef CONFIG_PPC_STD_MMU_32
pr_info("Hash_size = 0x%lx\n", Hash_size);
#endif
pr_info("phys_mem_size = 0x%llx\n",
(unsigned long long)memblock_phys_mem_size());

pr_info("dcache_bsize = 0x%x\n", dcache_bsize);
pr_info("icache_bsize = 0x%x\n", icache_bsize);
if (ucache_bsize != 0)
pr_info("ucache_bsize = 0x%x\n", ucache_bsize);

pr_info("cpu_features = 0x%016lx\n", cur_cpu_spec->cpu_features);
pr_info(" possible = 0x%016lx\n",
(unsigned long)CPU_FTRS_POSSIBLE);
pr_info(" always = 0x%016lx\n",
(unsigned long)CPU_FTRS_ALWAYS);
pr_info("cpu_user_features = 0x%08x 0x%08x\n",
cur_cpu_spec->cpu_user_features,
cur_cpu_spec->cpu_user_features2);
pr_info("mmu_features = 0x%08x\n", cur_cpu_spec->mmu_features);
#ifdef CONFIG_PPC64
pr_info("firmware_features = 0x%016lx\n", powerpc_firmware_features);
#endif

#ifdef CONFIG_PPC_STD_MMU_64
if (htab_address)
pr_info("htab_address = 0x%p\n", htab_address);
if (htab_hash_mask)
pr_info("htab_hash_mask = 0x%lx\n", htab_hash_mask);
#endif
#ifdef CONFIG_PPC_STD_MMU_32
if (Hash)
pr_info("Hash = 0x%p\n", Hash);
if (Hash_mask)
pr_info("Hash_mask = 0x%lx\n", Hash_mask);
#endif

if (PHYSICAL_START > 0)
pr_info("physical_start = 0x%llx\n",
(unsigned long long)PHYSICAL_START);
pr_info("-----------------------------------------------------\n");
}

/*
* Called into from start_kernel this initializes memblock, which is used
* to manage page allocation until mem_init is called.
*/
void __init setup_arch(char **cmdline_p)
{
*cmdline_p = boot_command_line;

/* Set a half-reasonable default so udelay does something sensible */
loops_per_jiffy = 500000000 / HZ;

/* Unflatten the device-tree passed by prom_init or kexec */
unflatten_device_tree();

/*
* Initialize cache line/block info from device-tree (on ppc64) or
* just cputable (on ppc32).
*/
initialize_cache_info();

/* Initialize RTAS if available. */
rtas_initialize();

/* Check if we have an initrd provided via the device-tree. */
check_for_initrd();

/* Probe the machine type, establish ppc_md. */
probe_machine();

/* Setup panic notifier if requested by the platform. */
setup_panic();

/*
* Configure ppc_md.power_save (ppc32 only, 64-bit machines do
* it from their respective probe() function.
*/
setup_power_save();

/* Discover standard serial ports. */
find_legacy_serial_ports();

/* Register early console with the printk subsystem. */
register_early_udbg_console();

/* Setup the various CPU maps based on the device-tree. */
smp_setup_cpu_maps();

/* Initialize xmon. */
xmon_setup();

/* Check the SMT related command line arguments (ppc64). */
check_smt_enabled();

/* On BookE, setup per-core TLB data structures. */
setup_tlb_core_data();

/*
* Release secondary cpus out of their spinloops at 0x60 now that
* we can map physical -> logical CPU ids.
*
* Freescale Book3e parts spin in a loop provided by firmware,
* so smp_release_cpus() does nothing for them.
*/
#ifdef CONFIG_SMP
smp_release_cpus();
#endif

/* Print various info about the machine that has been gathered so far. */
print_system_info();

/* Reserve large chunks of memory for use by CMA for KVM. */
kvm_cma_reserve();

/*
* Reserve any gigantic pages requested on the command line.
* memblock needs to have been initialized by the time this is
* called since this will reserve memory.
*/
reserve_hugetlb_gpages();

klp_init_thread_info(&init_thread_info);

init_mm.start_code = (unsigned long)_stext;
init_mm.end_code = (unsigned long) _etext;
init_mm.end_data = (unsigned long) _edata;
init_mm.brk = klimit;
#ifdef CONFIG_PPC_64K_PAGES
init_mm.context.pte_frag = NULL;
#endif
#ifdef CONFIG_SPAPR_TCE_IOMMU
mm_iommu_init(&init_mm.context);
#endif
irqstack_early_init();
exc_lvl_early_init();
emergency_stack_init();

initmem_init();

#ifdef CONFIG_DUMMY_CONSOLE
conswitchp = &dummy_con;
#endif
if (ppc_md.setup_arch)
ppc_md.setup_arch();

paging_init();

/* Initialize the MMU context management stuff. */
mmu_context_init();

#ifdef CONFIG_PPC64
/* Interrupt code needs to be 64K-aligned. */
if ((unsigned long)_stext & 0xffff)
panic("Kernelbase not 64K-aligned (0x%lx)!\n",
(unsigned long)_stext);
#endif
}
58 changes: 58 additions & 0 deletions arch/powerpc/kernel/setup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Prototypes for functions that are shared between setup_(32|64|common).c
*
* Copyright 2016 Michael Ellerman, 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.
*/

#ifndef __ARCH_POWERPC_KERNEL_SETUP_H
#define __ARCH_POWERPC_KERNEL_SETUP_H

void initialize_cache_info(void);
void irqstack_early_init(void);

#ifdef CONFIG_PPC32
void setup_power_save(void);
#else
static inline void setup_power_save(void) { };
#endif

#if defined(CONFIG_PPC64) && defined(CONFIG_SMP)
void check_smt_enabled(void);
#else
static inline void check_smt_enabled(void) { };
#endif

#if defined(CONFIG_PPC_BOOK3E) && defined(CONFIG_SMP)
void setup_tlb_core_data(void);
#else
static inline void setup_tlb_core_data(void) { };
#endif

#if defined(CONFIG_PPC_BOOK3E) || defined(CONFIG_BOOKE) || defined(CONFIG_40x)
void exc_lvl_early_init(void);
#else
static inline void exc_lvl_early_init(void) { };
#endif

#ifdef CONFIG_PPC64
void emergency_stack_init(void);
#else
static inline void emergency_stack_init(void) { };
#endif

/*
* Having this in kvm_ppc.h makes include dependencies too
* tricky to solve for setup-common.c so have it here.
*/
#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
void kvm_cma_reserve(void);
#else
static inline void kvm_cma_reserve(void) { };
#endif

#endif /* __ARCH_POWERPC_KERNEL_SETUP_H */
65 changes: 4 additions & 61 deletions arch/powerpc/kernel/setup_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <asm/time.h>
#include <asm/serial.h>
#include <asm/udbg.h>
#include <asm/mmu_context.h>
#include <asm/code-patching.h>

#define DBG(fmt...)
Expand Down Expand Up @@ -191,7 +190,7 @@ int __init ppc_init(void)

arch_initcall(ppc_init);

static void __init irqstack_early_init(void)
void __init irqstack_early_init(void)
{
unsigned int i;

Expand All @@ -206,7 +205,7 @@ static void __init irqstack_early_init(void)
}

#if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
static void __init exc_lvl_early_init(void)
void __init exc_lvl_early_init(void)
{
unsigned int i, hw_cpu;

Expand All @@ -229,11 +228,9 @@ static void __init exc_lvl_early_init(void)
#endif
}
}
#else
#define exc_lvl_early_init()
#endif

static void setup_power_save(void)
void __init setup_power_save(void)
{
#ifdef CONFIG_6xx
if (cpu_has_feature(CPU_FTR_CAN_DOZE) ||
Expand All @@ -248,7 +245,7 @@ static void setup_power_save(void)
#endif
}

static __init void initialize_cache_info(void)
__init void initialize_cache_info(void)
{
/*
* Set cache line size based on type of cpu as a default.
Expand All @@ -261,57 +258,3 @@ static __init void initialize_cache_info(void)
if (cpu_has_feature(CPU_FTR_UNIFIED_ID_CACHE))
ucache_bsize = icache_bsize = dcache_bsize;
}


/* Warning, IO base is not yet inited */
void __init setup_arch(char **cmdline_p)
{
*cmdline_p = boot_command_line;

/* so udelay does something sensible, assume <= 1000 bogomips */
loops_per_jiffy = 500000000 / HZ;

unflatten_device_tree();
initialize_cache_info();
check_for_initrd();

probe_machine();

setup_panic();

setup_power_save();

find_legacy_serial_ports();

/* Register early console */
register_early_udbg_console();

smp_setup_cpu_maps();

xmon_setup();

init_mm.start_code = (unsigned long)_stext;
init_mm.end_code = (unsigned long) _etext;
init_mm.end_data = (unsigned long) _edata;
init_mm.brk = klimit;

exc_lvl_early_init();

irqstack_early_init();

initmem_init();
if ( ppc_md.progress ) ppc_md.progress("setup_arch: initmem", 0x3eab);

#ifdef CONFIG_DUMMY_CONSOLE
conswitchp = &dummy_con;
#endif

if (ppc_md.setup_arch)
ppc_md.setup_arch();
if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);

paging_init();

/* Initialize the MMU context management stuff */
mmu_context_init();
}
Loading

0 comments on commit b1923ca

Please sign in to comment.