/*1* Initial setup-routines for HP 9000 based hardware.2*3* Copyright (C) 1991, 1992, 1995 Linus Torvalds4* Modifications for PA-RISC (C) 1999-2008 Helge Deller <[email protected]>5* Modifications copyright 1999 SuSE GmbH (Philipp Rumpf)6* Modifications copyright 2000 Martin K. Petersen <[email protected]>7* Modifications copyright 2000 Philipp Rumpf <[email protected]>8* Modifications copyright 2001 Ryan Bradetich <[email protected]>9*10* Initial PA-RISC Version: 04-23-1999 by Helge Deller11*12* This program is free software; you can redistribute it and/or modify13* it under the terms of the GNU General Public License as published by14* the Free Software Foundation; either version 2, or (at your option)15* any later version.16*17* This program is distributed in the hope that it will be useful,18* but WITHOUT ANY WARRANTY; without even the implied warranty of19* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the20* GNU General Public License for more details.21*22* You should have received a copy of the GNU General Public License23* along with this program; if not, write to the Free Software24* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.25*26*/27#include <linux/delay.h>28#include <linux/init.h>29#include <linux/mm.h>30#include <linux/module.h>31#include <linux/seq_file.h>32#include <linux/slab.h>33#include <linux/cpu.h>34#include <asm/param.h>35#include <asm/cache.h>36#include <asm/hardware.h> /* for register_parisc_driver() stuff */37#include <asm/processor.h>38#include <asm/page.h>39#include <asm/pdc.h>40#include <asm/pdcpat.h>41#include <asm/irq.h> /* for struct irq_region */42#include <asm/parisc-device.h>4344struct system_cpuinfo_parisc boot_cpu_data __read_mostly;45EXPORT_SYMBOL(boot_cpu_data);4647DEFINE_PER_CPU(struct cpuinfo_parisc, cpu_data);4849extern int update_cr16_clocksource(void); /* from time.c */5051/*52** PARISC CPU driver - claim "device" and initialize CPU data structures.53**54** Consolidate per CPU initialization into (mostly) one module.55** Monarch CPU will initialize boot_cpu_data which shouldn't56** change once the system has booted.57**58** The callback *should* do per-instance initialization of59** everything including the monarch. "Per CPU" init code in60** setup.c:start_parisc() has migrated here and start_parisc()61** will call register_parisc_driver(&cpu_driver) before calling do_inventory().62**63** The goal of consolidating CPU initialization into one place is64** to make sure all CPUs get initialized the same way.65** The code path not shared is how PDC hands control of the CPU to the OS.66** The initialization of OS data structures is the same (done below).67*/6869/**70* init_cpu_profiler - enable/setup per cpu profiling hooks.71* @cpunum: The processor instance.72*73* FIXME: doesn't do much yet...74*/75static void __cpuinit76init_percpu_prof(unsigned long cpunum)77{78struct cpuinfo_parisc *p;7980p = &per_cpu(cpu_data, cpunum);81p->prof_counter = 1;82p->prof_multiplier = 1;83}848586/**87* processor_probe - Determine if processor driver should claim this device.88* @dev: The device which has been found.89*90* Determine if processor driver should claim this chip (return 0) or not91* (return 1). If so, initialize the chip and tell other partners in crime92* they have work to do.93*/94static int __cpuinit processor_probe(struct parisc_device *dev)95{96unsigned long txn_addr;97unsigned long cpuid;98struct cpuinfo_parisc *p;99100#ifdef CONFIG_SMP101if (num_online_cpus() >= nr_cpu_ids) {102printk(KERN_INFO "num_online_cpus() >= nr_cpu_ids\n");103return 1;104}105#else106if (boot_cpu_data.cpu_count > 0) {107printk(KERN_INFO "CONFIG_SMP=n ignoring additional CPUs\n");108return 1;109}110#endif111112/* logical CPU ID and update global counter113* May get overwritten by PAT code.114*/115cpuid = boot_cpu_data.cpu_count;116txn_addr = dev->hpa.start; /* for legacy PDC */117118#ifdef CONFIG_64BIT119if (is_pdc_pat()) {120ulong status;121unsigned long bytecnt;122pdc_pat_cell_mod_maddr_block_t *pa_pdc_cell;123#undef USE_PAT_CPUID124#ifdef USE_PAT_CPUID125struct pdc_pat_cpu_num cpu_info;126#endif127128pa_pdc_cell = kmalloc(sizeof (*pa_pdc_cell), GFP_KERNEL);129if (!pa_pdc_cell)130panic("couldn't allocate memory for PDC_PAT_CELL!");131132status = pdc_pat_cell_module(&bytecnt, dev->pcell_loc,133dev->mod_index, PA_VIEW, pa_pdc_cell);134135BUG_ON(PDC_OK != status);136137/* verify it's the same as what do_pat_inventory() found */138BUG_ON(dev->mod_info != pa_pdc_cell->mod_info);139BUG_ON(dev->pmod_loc != pa_pdc_cell->mod_location);140141txn_addr = pa_pdc_cell->mod[0]; /* id_eid for IO sapic */142143kfree(pa_pdc_cell);144145#ifdef USE_PAT_CPUID146/* We need contiguous numbers for cpuid. Firmware's notion147* of cpuid is for physical CPUs and we just don't care yet.148* We'll care when we need to query PAT PDC about a CPU *after*149* boot time (ie shutdown a CPU from an OS perspective).150*/151/* get the cpu number */152status = pdc_pat_cpu_get_number(&cpu_info, dev->hpa.start);153154BUG_ON(PDC_OK != status);155156if (cpu_info.cpu_num >= NR_CPUS) {157printk(KERN_WARNING "IGNORING CPU at 0x%x,"158" cpu_slot_id > NR_CPUS"159" (%ld > %d)\n",160dev->hpa.start, cpu_info.cpu_num, NR_CPUS);161/* Ignore CPU since it will only crash */162boot_cpu_data.cpu_count--;163return 1;164} else {165cpuid = cpu_info.cpu_num;166}167#endif168}169#endif170171p = &per_cpu(cpu_data, cpuid);172boot_cpu_data.cpu_count++;173174/* initialize counters - CPU 0 gets it_value set in time_init() */175if (cpuid)176memset(p, 0, sizeof(struct cpuinfo_parisc));177178p->loops_per_jiffy = loops_per_jiffy;179p->dev = dev; /* Save IODC data in case we need it */180p->hpa = dev->hpa.start; /* save CPU hpa */181p->cpuid = cpuid; /* save CPU id */182p->txn_addr = txn_addr; /* save CPU IRQ address */183#ifdef CONFIG_SMP184/*185** FIXME: review if any other initialization is clobbered186** for boot_cpu by the above memset().187*/188init_percpu_prof(cpuid);189#endif190191/*192** CONFIG_SMP: init_smp_config() will attempt to get CPUs into193** OS control. RENDEZVOUS is the default state - see mem_set above.194** p->state = STATE_RENDEZVOUS;195*/196197#if 0198/* CPU 0 IRQ table is statically allocated/initialized */199if (cpuid) {200struct irqaction actions[];201202/*203** itimer and ipi IRQ handlers are statically initialized in204** arch/parisc/kernel/irq.c. ie Don't need to register them.205*/206actions = kmalloc(sizeof(struct irqaction)*MAX_CPU_IRQ, GFP_ATOMIC);207if (!actions) {208/* not getting it's own table, share with monarch */209actions = cpu_irq_actions[0];210}211212cpu_irq_actions[cpuid] = actions;213}214#endif215216/*217* Bring this CPU up now! (ignore bootstrap cpuid == 0)218*/219#ifdef CONFIG_SMP220if (cpuid) {221set_cpu_present(cpuid, true);222cpu_up(cpuid);223}224#endif225226/* If we've registered more than one cpu,227* we'll use the jiffies clocksource since cr16228* is not synchronized between CPUs.229*/230update_cr16_clocksource();231232return 0;233}234235/**236* collect_boot_cpu_data - Fill the boot_cpu_data structure.237*238* This function collects and stores the generic processor information239* in the boot_cpu_data structure.240*/241void __init collect_boot_cpu_data(void)242{243memset(&boot_cpu_data, 0, sizeof(boot_cpu_data));244245boot_cpu_data.cpu_hz = 100 * PAGE0->mem_10msec; /* Hz of this PARISC */246247/* get CPU-Model Information... */248#define p ((unsigned long *)&boot_cpu_data.pdc.model)249if (pdc_model_info(&boot_cpu_data.pdc.model) == PDC_OK)250printk(KERN_INFO251"model %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",252p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8]);253#undef p254255if (pdc_model_versions(&boot_cpu_data.pdc.versions, 0) == PDC_OK)256printk(KERN_INFO "vers %08lx\n",257boot_cpu_data.pdc.versions);258259if (pdc_model_cpuid(&boot_cpu_data.pdc.cpuid) == PDC_OK)260printk(KERN_INFO "CPUID vers %ld rev %ld (0x%08lx)\n",261(boot_cpu_data.pdc.cpuid >> 5) & 127,262boot_cpu_data.pdc.cpuid & 31,263boot_cpu_data.pdc.cpuid);264265if (pdc_model_capabilities(&boot_cpu_data.pdc.capabilities) == PDC_OK)266printk(KERN_INFO "capabilities 0x%lx\n",267boot_cpu_data.pdc.capabilities);268269if (pdc_model_sysmodel(boot_cpu_data.pdc.sys_model_name) == PDC_OK)270printk(KERN_INFO "model %s\n",271boot_cpu_data.pdc.sys_model_name);272273boot_cpu_data.hversion = boot_cpu_data.pdc.model.hversion;274boot_cpu_data.sversion = boot_cpu_data.pdc.model.sversion;275276boot_cpu_data.cpu_type = parisc_get_cpu_type(boot_cpu_data.hversion);277boot_cpu_data.cpu_name = cpu_name_version[boot_cpu_data.cpu_type][0];278boot_cpu_data.family_name = cpu_name_version[boot_cpu_data.cpu_type][1];279}280281282283/**284* init_per_cpu - Handle individual processor initializations.285* @cpunum: logical processor number.286*287* This function handles initialization for *every* CPU288* in the system:289*290* o Set "default" CPU width for trap handlers291*292* o Enable FP coprocessor293* REVISIT: this could be done in the "code 22" trap handler.294* (frowands idea - that way we know which processes need FP295* registers saved on the interrupt stack.)296* NEWS FLASH: wide kernels need FP coprocessor enabled to handle297* formatted printing of %lx for example (double divides I think)298*299* o Enable CPU profiling hooks.300*/301int __cpuinit init_per_cpu(int cpunum)302{303int ret;304struct pdc_coproc_cfg coproc_cfg;305306set_firmware_width();307ret = pdc_coproc_cfg(&coproc_cfg);308309if(ret >= 0 && coproc_cfg.ccr_functional) {310mtctl(coproc_cfg.ccr_functional, 10); /* 10 == Coprocessor Control Reg */311312/* FWIW, FP rev/model is a more accurate way to determine313** CPU type. CPU rev/model has some ambiguous cases.314*/315per_cpu(cpu_data, cpunum).fp_rev = coproc_cfg.revision;316per_cpu(cpu_data, cpunum).fp_model = coproc_cfg.model;317318printk(KERN_INFO "FP[%d] enabled: Rev %ld Model %ld\n",319cpunum, coproc_cfg.revision, coproc_cfg.model);320321/*322** store status register to stack (hopefully aligned)323** and clear the T-bit.324*/325asm volatile ("fstd %fr0,8(%sp)");326327} else {328printk(KERN_WARNING "WARNING: No FP CoProcessor?!"329" (coproc_cfg.ccr_functional == 0x%lx, expected 0xc0)\n"330#ifdef CONFIG_64BIT331"Halting Machine - FP required\n"332#endif333, coproc_cfg.ccr_functional);334#ifdef CONFIG_64BIT335mdelay(100); /* previous chars get pushed to console */336panic("FP CoProc not reported");337#endif338}339340/* FUTURE: Enable Performance Monitor : ccr bit 0x20 */341init_percpu_prof(cpunum);342343return ret;344}345346/*347* Display CPU info for all CPUs.348*/349int350show_cpuinfo (struct seq_file *m, void *v)351{352unsigned long cpu;353354for_each_online_cpu(cpu) {355const struct cpuinfo_parisc *cpuinfo = &per_cpu(cpu_data, cpu);356#ifdef CONFIG_SMP357if (0 == cpuinfo->hpa)358continue;359#endif360seq_printf(m, "processor\t: %lu\n"361"cpu family\t: PA-RISC %s\n",362cpu, boot_cpu_data.family_name);363364seq_printf(m, "cpu\t\t: %s\n", boot_cpu_data.cpu_name );365366/* cpu MHz */367seq_printf(m, "cpu MHz\t\t: %d.%06d\n",368boot_cpu_data.cpu_hz / 1000000,369boot_cpu_data.cpu_hz % 1000000 );370371seq_printf(m, "capabilities\t:");372if (boot_cpu_data.pdc.capabilities & PDC_MODEL_OS32)373seq_printf(m, " os32");374if (boot_cpu_data.pdc.capabilities & PDC_MODEL_OS64)375seq_printf(m, " os64");376seq_printf(m, "\n");377378seq_printf(m, "model\t\t: %s\n"379"model name\t: %s\n",380boot_cpu_data.pdc.sys_model_name,381cpuinfo->dev ?382cpuinfo->dev->name : "Unknown");383384seq_printf(m, "hversion\t: 0x%08x\n"385"sversion\t: 0x%08x\n",386boot_cpu_data.hversion,387boot_cpu_data.sversion );388389/* print cachesize info */390show_cache_info(m);391392seq_printf(m, "bogomips\t: %lu.%02lu\n",393cpuinfo->loops_per_jiffy / (500000 / HZ),394(cpuinfo->loops_per_jiffy / (5000 / HZ)) % 100);395396seq_printf(m, "software id\t: %ld\n\n",397boot_cpu_data.pdc.model.sw_id);398}399return 0;400}401402static const struct parisc_device_id processor_tbl[] = {403{ HPHW_NPROC, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, SVERSION_ANY_ID },404{ 0, }405};406407static struct parisc_driver cpu_driver = {408.name = "CPU",409.id_table = processor_tbl,410.probe = processor_probe411};412413/**414* processor_init - Processor initialization procedure.415*416* Register this driver.417*/418void __init processor_init(void)419{420register_parisc_driver(&cpu_driver);421}422423424