// SPDX-License-Identifier: GPL-2.01/*2* ip22-mc.c: Routines for manipulating SGI Memory Controller.3*4* Copyright (C) 1996 David S. Miller ([email protected])5* Copyright (C) 1999 Andrew R. Baker ([email protected]) - Indigo2 changes6* Copyright (C) 2003 Ladislav Michl ([email protected])7* Copyright (C) 2004 Peter Fuerst ([email protected]) - IP288*/910#include <linux/init.h>11#include <linux/export.h>12#include <linux/kernel.h>13#include <linux/memblock.h>14#include <linux/spinlock.h>1516#include <asm/io.h>17#include <asm/bootinfo.h>18#include <asm/sgialib.h>19#include <asm/sgi/mc.h>20#include <asm/sgi/hpc3.h>21#include <asm/sgi/ip22.h>2223struct sgimc_regs *sgimc;2425EXPORT_SYMBOL(sgimc);2627static inline unsigned long get_bank_addr(unsigned int memconfig)28{29return (memconfig & SGIMC_MCONFIG_BASEADDR) << ((sgimc->systemid & SGIMC_SYSID_MASKREV) >= 5 ? 24 : 22);30}3132static inline unsigned long get_bank_size(unsigned int memconfig)33{34return ((memconfig & SGIMC_MCONFIG_RMASK) + 0x0100) << ((sgimc->systemid & SGIMC_SYSID_MASKREV) >= 5 ? 16 : 14);35}3637static inline unsigned int get_bank_config(int bank)38{39unsigned int res = bank > 1 ? sgimc->mconfig1 : sgimc->mconfig0;40return bank % 2 ? res & 0xffff : res >> 16;41}4243#if defined(CONFIG_SGI_IP28) || defined(CONFIG_32BIT)44static void __init probe_memory(void)45{46/* prom detects all usable memory */47}48#else49/*50* Detect installed memory, which PROM misses51*/52static void __init probe_memory(void)53{54unsigned long addr, size;55int i;5657printk(KERN_INFO "MC: Probing memory configuration:\n");58for (i = 0; i < 4; i++) {59unsigned int tmp = get_bank_config(i);60if (!(tmp & SGIMC_MCONFIG_BVALID))61continue;6263size = get_bank_size(tmp);64addr = get_bank_addr(tmp);65printk(KERN_INFO " bank%d: %3ldM @ %08lx\n",66i, size / 1024 / 1024, addr);6768if (addr >= SGIMC_SEG1_BADDR)69memblock_add(addr, size);70}71}72#endif7374void __init sgimc_init(void)75{76u32 tmp;7778/* ioremap can't fail */79sgimc = (struct sgimc_regs *)80ioremap(SGIMC_BASE, sizeof(struct sgimc_regs));8182printk(KERN_INFO "MC: SGI memory controller Revision %d\n",83(int) sgimc->systemid & SGIMC_SYSID_MASKREV);8485/* Place the MC into a known state. This must be done before86* interrupts are first enabled etc.87*/8889/* Step 0: Make sure we turn off the watchdog in case it's90* still running (which might be the case after a91* soft reboot).92*/93tmp = sgimc->cpuctrl0;94tmp &= ~SGIMC_CCTRL0_WDOG;95sgimc->cpuctrl0 = tmp;9697/* Step 1: The CPU/GIO error status registers will not latch98* up a new error status until the register has been99* cleared by the cpu. These status registers are100* cleared by writing any value to them.101*/102sgimc->cstat = sgimc->gstat = 0;103104/* Step 2: Enable all parity checking in cpu control register105* zero.106*/107/* don't touch parity settings for IP28 */108tmp = sgimc->cpuctrl0;109#ifndef CONFIG_SGI_IP28110tmp |= SGIMC_CCTRL0_EPERRGIO | SGIMC_CCTRL0_EPERRMEM;111#endif112tmp |= SGIMC_CCTRL0_R4KNOCHKPARR;113sgimc->cpuctrl0 = tmp;114115/* Step 3: Setup the MC write buffer depth, this is controlled116* in cpu control register 1 in the lower 4 bits.117*/118tmp = sgimc->cpuctrl1;119tmp &= ~0xf;120tmp |= 0xd;121sgimc->cpuctrl1 = tmp;122123/* Step 4: Initialize the RPSS divider register to run as fast124* as it can correctly operate. The register is laid125* out as follows:126*127* ----------------------------------------128* | RESERVED | INCREMENT | DIVIDER |129* ----------------------------------------130* 31 16 15 8 7 0131*132* DIVIDER determines how often a 'tick' happens,133* INCREMENT determines by how the RPSS increment134* registers value increases at each 'tick'. Thus,135* for IP22 we get INCREMENT=1, DIVIDER=1 == 0x101136*/137sgimc->divider = 0x101;138139/* Step 5: Initialize GIO64 arbitrator configuration register.140*141* NOTE: HPC init code in sgihpc_init() must run before us because142* we need to know Guiness vs. FullHouse and the board143* revision on this machine. You have been warned.144*/145146/* First the basic invariants across all GIO64 implementations. */147tmp = sgimc->giopar & SGIMC_GIOPAR_GFX64; /* keep gfx 64bit settings */148tmp |= SGIMC_GIOPAR_HPC64; /* All 1st HPC's interface at 64bits */149tmp |= SGIMC_GIOPAR_ONEBUS; /* Only one physical GIO bus exists */150151if (ip22_is_fullhouse()) {152/* Fullhouse specific settings. */153if (SGIOC_SYSID_BOARDREV(sgioc->sysid) < 2) {154tmp |= SGIMC_GIOPAR_HPC264; /* 2nd HPC at 64bits */155tmp |= SGIMC_GIOPAR_PLINEEXP0; /* exp0 pipelines */156tmp |= SGIMC_GIOPAR_MASTEREXP1; /* exp1 masters */157tmp |= SGIMC_GIOPAR_RTIMEEXP0; /* exp0 is realtime */158} else {159tmp |= SGIMC_GIOPAR_HPC264; /* 2nd HPC 64bits */160tmp |= SGIMC_GIOPAR_PLINEEXP0; /* exp[01] pipelined */161tmp |= SGIMC_GIOPAR_PLINEEXP1;162tmp |= SGIMC_GIOPAR_MASTEREISA; /* EISA masters */163}164} else {165/* Guiness specific settings. */166tmp |= SGIMC_GIOPAR_EISA64; /* MC talks to EISA at 64bits */167tmp |= SGIMC_GIOPAR_MASTEREISA; /* EISA bus can act as master */168}169sgimc->giopar = tmp; /* poof */170171probe_memory();172}173174#ifdef CONFIG_SGI_IP28175void __init prom_cleanup(void)176{177u32 mconfig1;178unsigned long flags;179spinlock_t lock;180181/*182* because ARCS accesses memory uncached we wait until ARCS183* isn't needed any longer, before we switch from slow to184* normal mode185*/186spin_lock_irqsave(&lock, flags);187mconfig1 = sgimc->mconfig1;188/* map ECC register */189sgimc->mconfig1 = (mconfig1 & 0xffff0000) | 0x2060;190iob();191/* switch to normal mode */192*(unsigned long *)PHYS_TO_XKSEG_UNCACHED(0x60000000) = 0;193iob();194/* reduce WR_COL */195sgimc->cmacc = (sgimc->cmacc & ~0xf) | 4;196iob();197/* restore old config */198sgimc->mconfig1 = mconfig1;199iob();200spin_unlock_irqrestore(&lock, flags);201}202#endif203204205