Path: blob/master/arch/powerpc/platforms/powermac/setup.c
26481 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* Powermac setup and early boot code plus other random bits.3*4* PowerPC version5* Copyright (C) 1995-1996 Gary Thomas ([email protected])6*7* Adapted for Power Macintosh by Paul Mackerras8* Copyright (C) 1996 Paul Mackerras ([email protected])9*10* Derived from "arch/alpha/kernel/setup.c"11* Copyright (C) 1995 Linus Torvalds12*13* Maintained by Benjamin Herrenschmidt ([email protected])14*/1516/*17* bootup setup stuff..18*/1920#include <linux/init.h>21#include <linux/errno.h>22#include <linux/sched.h>23#include <linux/kernel.h>24#include <linux/mm.h>25#include <linux/stddef.h>26#include <linux/unistd.h>27#include <linux/ptrace.h>28#include <linux/export.h>29#include <linux/user.h>30#include <linux/string.h>31#include <linux/delay.h>32#include <linux/ioport.h>33#include <linux/major.h>34#include <linux/initrd.h>35#include <linux/console.h>36#include <linux/pci.h>37#include <linux/adb.h>38#include <linux/cuda.h>39#include <linux/pmu.h>40#include <linux/irq.h>41#include <linux/seq_file.h>42#include <linux/root_dev.h>43#include <linux/bitops.h>44#include <linux/suspend.h>45#include <linux/string_choices.h>46#include <linux/of.h>47#include <linux/of_platform.h>4849#include <asm/reg.h>50#include <asm/sections.h>51#include <asm/io.h>52#include <asm/pci-bridge.h>53#include <asm/ohare.h>54#include <asm/mediabay.h>55#include <asm/machdep.h>56#include <asm/dma.h>57#include <asm/cputable.h>58#include <asm/btext.h>59#include <asm/pmac_feature.h>60#include <asm/time.h>61#include <asm/mmu_context.h>62#include <asm/iommu.h>63#include <asm/smu.h>64#include <asm/pmc.h>65#include <asm/udbg.h>6667#include "pmac.h"6869#undef SHOW_GATWICK_IRQS7071static int has_l2cache;7273int pmac_newworld;7475static int current_root_goodness = -1;7677/* sda1 - slightly silly choice */78#define DEFAULT_ROOT_DEVICE MKDEV(SCSI_DISK0_MAJOR, 1)7980sys_ctrler_t sys_ctrler = SYS_CTRLER_UNKNOWN;81EXPORT_SYMBOL(sys_ctrler);8283static void pmac_show_cpuinfo(struct seq_file *m)84{85struct device_node *np;86const char *pp;87int plen;88int mbmodel;89unsigned int mbflags;90char* mbname;9192mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,93PMAC_MB_INFO_MODEL, 0);94mbflags = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,95PMAC_MB_INFO_FLAGS, 0);96if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME,97(long) &mbname) != 0)98mbname = "Unknown";99100/* find motherboard type */101seq_printf(m, "machine\t\t: ");102np = of_find_node_by_path("/");103if (np != NULL) {104pp = of_get_property(np, "model", NULL);105if (pp != NULL)106seq_printf(m, "%s\n", pp);107else108seq_printf(m, "PowerMac\n");109pp = of_get_property(np, "compatible", &plen);110if (pp != NULL) {111seq_printf(m, "motherboard\t:");112while (plen > 0) {113int l = strlen(pp) + 1;114seq_printf(m, " %s", pp);115plen -= l;116pp += l;117}118seq_printf(m, "\n");119}120of_node_put(np);121} else122seq_printf(m, "PowerMac\n");123124/* print parsed model */125seq_printf(m, "detected as\t: %d (%s)\n", mbmodel, mbname);126seq_printf(m, "pmac flags\t: %08x\n", mbflags);127128/* find l2 cache info */129np = of_find_node_by_name(NULL, "l2-cache");130if (np == NULL)131np = of_find_node_by_type(NULL, "cache");132if (np != NULL) {133const unsigned int *ic =134of_get_property(np, "i-cache-size", NULL);135const unsigned int *dc =136of_get_property(np, "d-cache-size", NULL);137seq_printf(m, "L2 cache\t:");138has_l2cache = 1;139if (of_property_read_bool(np, "cache-unified") && dc) {140seq_printf(m, " %dK unified", *dc / 1024);141} else {142if (ic)143seq_printf(m, " %dK instruction", *ic / 1024);144if (dc)145seq_printf(m, "%s %dK data",146(ic? " +": ""), *dc / 1024);147}148pp = of_get_property(np, "ram-type", NULL);149if (pp)150seq_printf(m, " %s", pp);151seq_printf(m, "\n");152of_node_put(np);153}154155/* Indicate newworld/oldworld */156seq_printf(m, "pmac-generation\t: %s\n",157pmac_newworld ? "NewWorld" : "OldWorld");158}159160#ifndef CONFIG_ADB_CUDA161int __init find_via_cuda(void)162{163struct device_node *dn = of_find_node_by_name(NULL, "via-cuda");164165if (!dn)166return 0;167of_node_put(dn);168printk("WARNING ! Your machine is CUDA-based but your kernel\n");169printk(" wasn't compiled with CONFIG_ADB_CUDA option !\n");170return 0;171}172#endif173174#ifndef CONFIG_ADB_PMU175int __init find_via_pmu(void)176{177struct device_node *dn = of_find_node_by_name(NULL, "via-pmu");178179if (!dn)180return 0;181of_node_put(dn);182printk("WARNING ! Your machine is PMU-based but your kernel\n");183printk(" wasn't compiled with CONFIG_ADB_PMU option !\n");184return 0;185}186#endif187188#ifndef CONFIG_PMAC_SMU189int __init smu_init(void)190{191/* should check and warn if SMU is present */192return 0;193}194#endif195196#ifdef CONFIG_PPC32197static volatile u32 *sysctrl_regs;198199static void __init ohare_init(void)200{201struct device_node *dn;202203/* this area has the CPU identification register204and some registers used by smp boards */205sysctrl_regs = (volatile u32 *) ioremap(0xf8000000, 0x1000);206207/*208* Turn on the L2 cache.209* We assume that we have a PSX memory controller iff210* we have an ohare I/O controller.211*/212dn = of_find_node_by_name(NULL, "ohare");213if (dn) {214of_node_put(dn);215if (((sysctrl_regs[2] >> 24) & 0xf) >= 3) {216if (sysctrl_regs[4] & 0x10)217sysctrl_regs[4] |= 0x04000020;218else219sysctrl_regs[4] |= 0x04000000;220if(has_l2cache)221printk(KERN_INFO "Level 2 cache enabled\n");222}223}224}225226static void __init l2cr_init(void)227{228/* Checks "l2cr-value" property in the registry */229if (cpu_has_feature(CPU_FTR_L2CR)) {230struct device_node *np;231232for_each_of_cpu_node(np) {233const unsigned int *l2cr =234of_get_property(np, "l2cr-value", NULL);235if (l2cr) {236_set_L2CR(0);237_set_L2CR(*l2cr);238pr_info("L2CR overridden (0x%x), backside cache is %s\n",239*l2cr, str_enabled_disabled((*l2cr) & 0x80000000));240}241of_node_put(np);242break;243}244}245}246#endif247248static void __init pmac_setup_arch(void)249{250struct device_node *cpu, *ic;251const int *fp;252unsigned long pvr;253254pvr = PVR_VER(mfspr(SPRN_PVR));255256/* Set loops_per_jiffy to a half-way reasonable value,257for use until calibrate_delay gets called. */258loops_per_jiffy = 50000000 / HZ;259260for_each_of_cpu_node(cpu) {261fp = of_get_property(cpu, "clock-frequency", NULL);262if (fp != NULL) {263if (pvr >= 0x30 && pvr < 0x80)264/* PPC970 etc. */265loops_per_jiffy = *fp / (3 * HZ);266else if (pvr == 4 || pvr >= 8)267/* 604, G3, G4 etc. */268loops_per_jiffy = *fp / HZ;269else270/* 603, etc. */271loops_per_jiffy = *fp / (2 * HZ);272of_node_put(cpu);273break;274}275}276277/* See if newworld or oldworld */278ic = of_find_node_with_property(NULL, "interrupt-controller");279if (ic) {280pmac_newworld = 1;281of_node_put(ic);282}283284#ifdef CONFIG_PPC32285ohare_init();286l2cr_init();287#endif /* CONFIG_PPC32 */288289find_via_cuda();290find_via_pmu();291smu_init();292293#if IS_ENABLED(CONFIG_NVRAM)294pmac_nvram_init();295#endif296#ifdef CONFIG_PPC32297#ifdef CONFIG_BLK_DEV_INITRD298if (initrd_start)299ROOT_DEV = Root_RAM0;300else301#endif302ROOT_DEV = DEFAULT_ROOT_DEVICE;303#endif304305#ifdef CONFIG_ADB306if (strstr(boot_command_line, "adb_sync")) {307extern int __adb_probe_sync;308__adb_probe_sync = 1;309}310#endif /* CONFIG_ADB */311}312313static int initializing = 1;314315static int pmac_late_init(void)316{317initializing = 0;318return 0;319}320machine_late_initcall(powermac, pmac_late_init);321322void note_bootable_part(dev_t dev, int part, int goodness);323/*324* This is __ref because we check for "initializing" before325* touching any of the __init sensitive things and "initializing"326* will be false after __init time. This can't be __init because it327* can be called whenever a disk is first accessed.328*/329void __ref note_bootable_part(dev_t dev, int part, int goodness)330{331char *p;332333if (!initializing)334return;335if ((goodness <= current_root_goodness) &&336ROOT_DEV != DEFAULT_ROOT_DEVICE)337return;338p = strstr(boot_command_line, "root=");339if (p != NULL && (p == boot_command_line || p[-1] == ' '))340return;341342ROOT_DEV = dev + part;343current_root_goodness = goodness;344}345346#ifdef CONFIG_ADB_CUDA347static void __noreturn cuda_restart(void)348{349struct adb_request req;350351cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM);352for (;;)353cuda_poll();354}355356static void __noreturn cuda_shutdown(void)357{358struct adb_request req;359360cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN);361for (;;)362cuda_poll();363}364365#else366#define cuda_restart()367#define cuda_shutdown()368#endif369370#ifndef CONFIG_ADB_PMU371#define pmu_restart()372#define pmu_shutdown()373#endif374375#ifndef CONFIG_PMAC_SMU376#define smu_restart()377#define smu_shutdown()378#endif379380static void __noreturn pmac_restart(char *cmd)381{382switch (sys_ctrler) {383case SYS_CTRLER_CUDA:384cuda_restart();385break;386case SYS_CTRLER_PMU:387pmu_restart();388break;389case SYS_CTRLER_SMU:390smu_restart();391break;392default: ;393}394while (1) ;395}396397static void __noreturn pmac_power_off(void)398{399switch (sys_ctrler) {400case SYS_CTRLER_CUDA:401cuda_shutdown();402break;403case SYS_CTRLER_PMU:404pmu_shutdown();405break;406case SYS_CTRLER_SMU:407smu_shutdown();408break;409default: ;410}411while (1) ;412}413414static void __noreturn415pmac_halt(void)416{417pmac_power_off();418}419420/*421* Early initialization.422*/423static void __init pmac_init(void)424{425/* Enable early btext debug if requested */426if (strstr(boot_command_line, "btextdbg")) {427udbg_adb_init_early();428register_early_udbg_console();429}430431/* Probe motherboard chipset */432pmac_feature_init();433434/* Initialize debug stuff */435udbg_scc_init(!!strstr(boot_command_line, "sccdbg"));436udbg_adb_init(!!strstr(boot_command_line, "btextdbg"));437438#ifdef CONFIG_PPC64439iommu_init_early_dart(&pmac_pci_controller_ops);440#endif441442/* SMP Init has to be done early as we need to patch up443* cpu_possible_mask before interrupt stacks are allocated444* or kaboom...445*/446#ifdef CONFIG_SMP447pmac_setup_smp();448#endif449}450451static int __init pmac_declare_of_platform_devices(void)452{453struct device_node *np;454455np = of_find_node_by_name(NULL, "valkyrie");456if (np) {457of_platform_device_create(np, "valkyrie", NULL);458of_node_put(np);459}460np = of_find_node_by_name(NULL, "platinum");461if (np) {462of_platform_device_create(np, "platinum", NULL);463of_node_put(np);464}465np = of_find_node_by_type(NULL, "smu");466if (np) {467of_platform_device_create(np, "smu", NULL);468of_node_put(np);469}470np = of_find_node_by_type(NULL, "fcu");471if (np == NULL) {472/* Some machines have strangely broken device-tree */473np = of_find_node_by_path("/u3@0,f8000000/i2c@f8001000/fan@15e");474}475if (np) {476of_platform_device_create(np, "temperature", NULL);477of_node_put(np);478}479480return 0;481}482machine_device_initcall(powermac, pmac_declare_of_platform_devices);483484#ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE485/*486* This is called very early, as part of console_init() (typically just after487* time_init()). This function is respondible for trying to find a good488* default console on serial ports. It tries to match the open firmware489* default output with one of the available serial console drivers.490*/491static int __init check_pmac_serial_console(void)492{493struct device_node *prom_stdout = NULL;494int offset = 0;495const char *name;496#ifdef CONFIG_SERIAL_PMACZILOG_TTYS497char *devname = "ttyS";498#else499char *devname = "ttyPZ";500#endif501502pr_debug(" -> check_pmac_serial_console()\n");503504/* The user has requested a console so this is already set up. */505if (strstr(boot_command_line, "console=")) {506pr_debug(" console was specified !\n");507return -EBUSY;508}509510if (!of_chosen) {511pr_debug(" of_chosen is NULL !\n");512return -ENODEV;513}514515/* We are getting a weird phandle from OF ... */516/* ... So use the full path instead */517name = of_get_property(of_chosen, "linux,stdout-path", NULL);518if (name == NULL) {519pr_debug(" no linux,stdout-path !\n");520return -ENODEV;521}522prom_stdout = of_find_node_by_path(name);523if (!prom_stdout) {524pr_debug(" can't find stdout package %s !\n", name);525return -ENODEV;526}527pr_debug("stdout is %pOF\n", prom_stdout);528529if (of_node_name_eq(prom_stdout, "ch-a"))530offset = 0;531else if (of_node_name_eq(prom_stdout, "ch-b"))532offset = 1;533else534goto not_found;535of_node_put(prom_stdout);536537pr_debug("Found serial console at %s%d\n", devname, offset);538539return add_preferred_console(devname, offset, NULL);540541not_found:542pr_debug("No preferred console found !\n");543of_node_put(prom_stdout);544return -ENODEV;545}546console_initcall(check_pmac_serial_console);547548#endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */549550/*551* Called very early, MMU is off, device-tree isn't unflattened552*/553static int __init pmac_probe(void)554{555if (!of_machine_is_compatible("Power Macintosh") &&556!of_machine_is_compatible("MacRISC"))557return 0;558559#ifdef CONFIG_PPC32560/* isa_io_base gets set in pmac_pci_init */561DMA_MODE_READ = 1;562DMA_MODE_WRITE = 2;563#endif /* CONFIG_PPC32 */564565pm_power_off = pmac_power_off;566567pmac_init();568569return 1;570}571572define_machine(powermac) {573.name = "PowerMac",574.probe = pmac_probe,575.setup_arch = pmac_setup_arch,576.discover_phbs = pmac_pci_init,577.show_cpuinfo = pmac_show_cpuinfo,578.init_IRQ = pmac_pic_init,579.get_irq = NULL, /* changed later */580.pci_irq_fixup = pmac_pci_irq_fixup,581.restart = pmac_restart,582.halt = pmac_halt,583.time_init = pmac_time_init,584.get_boot_time = pmac_get_boot_time,585.set_rtc_time = pmac_set_rtc_time,586.get_rtc_time = pmac_get_rtc_time,587.calibrate_decr = pmac_calibrate_decr,588.feature_call = pmac_do_feature_call,589.progress = udbg_progress,590#ifdef CONFIG_PPC64591.power_save = power4_idle,592.enable_pmcs = power4_enable_pmcs,593#endif /* CONFIG_PPC64 */594#ifdef CONFIG_PPC32595.pcibios_after_init = pmac_pcibios_after_init,596.phys_mem_access_prot = pci_phys_mem_access_prot,597#endif598};599600601