18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * identify.c: machine identification code.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 1998 Harald Koerfgen and Paul M. Antoine
68c2ecf20Sopenharmony_ci * Copyright (C) 2002, 2003, 2004, 2005  Maciej W. Rozycki
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci#include <linux/init.h>
98c2ecf20Sopenharmony_ci#include <linux/kernel.h>
108c2ecf20Sopenharmony_ci#include <linux/mc146818rtc.h>
118c2ecf20Sopenharmony_ci#include <linux/export.h>
128c2ecf20Sopenharmony_ci#include <linux/string.h>
138c2ecf20Sopenharmony_ci#include <linux/types.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <asm/bootinfo.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <asm/dec/ioasic.h>
188c2ecf20Sopenharmony_ci#include <asm/dec/ioasic_addrs.h>
198c2ecf20Sopenharmony_ci#include <asm/dec/kn01.h>
208c2ecf20Sopenharmony_ci#include <asm/dec/kn02.h>
218c2ecf20Sopenharmony_ci#include <asm/dec/kn02ba.h>
228c2ecf20Sopenharmony_ci#include <asm/dec/kn02ca.h>
238c2ecf20Sopenharmony_ci#include <asm/dec/kn03.h>
248c2ecf20Sopenharmony_ci#include <asm/dec/kn230.h>
258c2ecf20Sopenharmony_ci#include <asm/dec/prom.h>
268c2ecf20Sopenharmony_ci#include <asm/dec/system.h>
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#include "dectypes.h"
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistatic const char *dec_system_strings[] = {
318c2ecf20Sopenharmony_ci	[MACH_DSUNKNOWN]	"unknown DECstation",
328c2ecf20Sopenharmony_ci	[MACH_DS23100]		"DECstation 2100/3100",
338c2ecf20Sopenharmony_ci	[MACH_DS5100]		"DECsystem 5100",
348c2ecf20Sopenharmony_ci	[MACH_DS5000_200]	"DECstation 5000/200",
358c2ecf20Sopenharmony_ci	[MACH_DS5000_1XX]	"DECstation 5000/1xx",
368c2ecf20Sopenharmony_ci	[MACH_DS5000_XX]	"Personal DECstation 5000/xx",
378c2ecf20Sopenharmony_ci	[MACH_DS5000_2X0]	"DECstation 5000/2x0",
388c2ecf20Sopenharmony_ci	[MACH_DS5400]		"DECsystem 5400",
398c2ecf20Sopenharmony_ci	[MACH_DS5500]		"DECsystem 5500",
408c2ecf20Sopenharmony_ci	[MACH_DS5800]		"DECsystem 5800",
418c2ecf20Sopenharmony_ci	[MACH_DS5900]		"DECsystem 5900",
428c2ecf20Sopenharmony_ci};
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ciconst char *get_system_type(void)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci#define STR_BUF_LEN	64
478c2ecf20Sopenharmony_ci	static char system[STR_BUF_LEN];
488c2ecf20Sopenharmony_ci	static int called = 0;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	if (called == 0) {
518c2ecf20Sopenharmony_ci		called = 1;
528c2ecf20Sopenharmony_ci		snprintf(system, STR_BUF_LEN, "Digital %s",
538c2ecf20Sopenharmony_ci			 dec_system_strings[mips_machtype]);
548c2ecf20Sopenharmony_ci	}
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	return system;
578c2ecf20Sopenharmony_ci}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/*
618c2ecf20Sopenharmony_ci * Setup essential system-specific memory addresses.  We need them
628c2ecf20Sopenharmony_ci * early.  Semantically the functions belong to prom/init.c, but they
638c2ecf20Sopenharmony_ci * are compact enough we want them inlined. --macro
648c2ecf20Sopenharmony_ci */
658c2ecf20Sopenharmony_civolatile u8 *dec_rtc_base;
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ciEXPORT_SYMBOL(dec_rtc_base);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cistatic inline void prom_init_kn01(void)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	dec_kn_slot_base = KN01_SLOT_BASE;
728c2ecf20Sopenharmony_ci	dec_kn_slot_size = KN01_SLOT_SIZE;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	dec_rtc_base = (void *)CKSEG1ADDR(dec_kn_slot_base + KN01_RTC);
758c2ecf20Sopenharmony_ci}
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_cistatic inline void prom_init_kn230(void)
788c2ecf20Sopenharmony_ci{
798c2ecf20Sopenharmony_ci	dec_kn_slot_base = KN01_SLOT_BASE;
808c2ecf20Sopenharmony_ci	dec_kn_slot_size = KN01_SLOT_SIZE;
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	dec_rtc_base = (void *)CKSEG1ADDR(dec_kn_slot_base + KN01_RTC);
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic inline void prom_init_kn02(void)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci	dec_kn_slot_base = KN02_SLOT_BASE;
888c2ecf20Sopenharmony_ci	dec_kn_slot_size = KN02_SLOT_SIZE;
898c2ecf20Sopenharmony_ci	dec_tc_bus = 1;
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	dec_rtc_base = (void *)CKSEG1ADDR(dec_kn_slot_base + KN02_RTC);
928c2ecf20Sopenharmony_ci}
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cistatic inline void prom_init_kn02xa(void)
958c2ecf20Sopenharmony_ci{
968c2ecf20Sopenharmony_ci	dec_kn_slot_base = KN02XA_SLOT_BASE;
978c2ecf20Sopenharmony_ci	dec_kn_slot_size = IOASIC_SLOT_SIZE;
988c2ecf20Sopenharmony_ci	dec_tc_bus = 1;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	ioasic_base = (void *)CKSEG1ADDR(dec_kn_slot_base + IOASIC_IOCTL);
1018c2ecf20Sopenharmony_ci	dec_rtc_base = (void *)CKSEG1ADDR(dec_kn_slot_base + IOASIC_TOY);
1028c2ecf20Sopenharmony_ci}
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistatic inline void prom_init_kn03(void)
1058c2ecf20Sopenharmony_ci{
1068c2ecf20Sopenharmony_ci	dec_kn_slot_base = KN03_SLOT_BASE;
1078c2ecf20Sopenharmony_ci	dec_kn_slot_size = IOASIC_SLOT_SIZE;
1088c2ecf20Sopenharmony_ci	dec_tc_bus = 1;
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	ioasic_base = (void *)CKSEG1ADDR(dec_kn_slot_base + IOASIC_IOCTL);
1118c2ecf20Sopenharmony_ci	dec_rtc_base = (void *)CKSEG1ADDR(dec_kn_slot_base + IOASIC_TOY);
1128c2ecf20Sopenharmony_ci}
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_civoid __init prom_identify_arch(u32 magic)
1168c2ecf20Sopenharmony_ci{
1178c2ecf20Sopenharmony_ci	unsigned char dec_cpunum, dec_firmrev, dec_etc, dec_systype;
1188c2ecf20Sopenharmony_ci	u32 dec_sysid;
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	if (!prom_is_rex(magic)) {
1218c2ecf20Sopenharmony_ci		dec_sysid = simple_strtoul(prom_getenv("systype"),
1228c2ecf20Sopenharmony_ci					   (char **)0, 0);
1238c2ecf20Sopenharmony_ci	} else {
1248c2ecf20Sopenharmony_ci		dec_sysid = rex_getsysid();
1258c2ecf20Sopenharmony_ci		if (dec_sysid == 0) {
1268c2ecf20Sopenharmony_ci			printk("Zero sysid returned from PROM! "
1278c2ecf20Sopenharmony_ci			       "Assuming a PMAX-like machine.\n");
1288c2ecf20Sopenharmony_ci			dec_sysid = 1;
1298c2ecf20Sopenharmony_ci		}
1308c2ecf20Sopenharmony_ci	}
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	dec_cpunum = (dec_sysid & 0xff000000) >> 24;
1338c2ecf20Sopenharmony_ci	dec_systype = (dec_sysid & 0xff0000) >> 16;
1348c2ecf20Sopenharmony_ci	dec_firmrev = (dec_sysid & 0xff00) >> 8;
1358c2ecf20Sopenharmony_ci	dec_etc = dec_sysid & 0xff;
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	/*
1388c2ecf20Sopenharmony_ci	 * FIXME: This may not be an exhaustive list of DECStations/Servers!
1398c2ecf20Sopenharmony_ci	 * Put all model-specific initialisation calls here.
1408c2ecf20Sopenharmony_ci	 */
1418c2ecf20Sopenharmony_ci	switch (dec_systype) {
1428c2ecf20Sopenharmony_ci	case DS2100_3100:
1438c2ecf20Sopenharmony_ci		mips_machtype = MACH_DS23100;
1448c2ecf20Sopenharmony_ci		prom_init_kn01();
1458c2ecf20Sopenharmony_ci		break;
1468c2ecf20Sopenharmony_ci	case DS5100:		/* DS5100 MIPSMATE */
1478c2ecf20Sopenharmony_ci		mips_machtype = MACH_DS5100;
1488c2ecf20Sopenharmony_ci		prom_init_kn230();
1498c2ecf20Sopenharmony_ci		break;
1508c2ecf20Sopenharmony_ci	case DS5000_200:	/* DS5000 3max */
1518c2ecf20Sopenharmony_ci		mips_machtype = MACH_DS5000_200;
1528c2ecf20Sopenharmony_ci		prom_init_kn02();
1538c2ecf20Sopenharmony_ci		break;
1548c2ecf20Sopenharmony_ci	case DS5000_1XX:	/* DS5000/100 3min */
1558c2ecf20Sopenharmony_ci		mips_machtype = MACH_DS5000_1XX;
1568c2ecf20Sopenharmony_ci		prom_init_kn02xa();
1578c2ecf20Sopenharmony_ci		break;
1588c2ecf20Sopenharmony_ci	case DS5000_2X0:	/* DS5000/240 3max+ or DS5900 bigmax */
1598c2ecf20Sopenharmony_ci		mips_machtype = MACH_DS5000_2X0;
1608c2ecf20Sopenharmony_ci		prom_init_kn03();
1618c2ecf20Sopenharmony_ci		if (!(ioasic_read(IO_REG_SIR) & KN03_IO_INR_3MAXP))
1628c2ecf20Sopenharmony_ci			mips_machtype = MACH_DS5900;
1638c2ecf20Sopenharmony_ci		break;
1648c2ecf20Sopenharmony_ci	case DS5000_XX:		/* Personal DS5000/xx maxine */
1658c2ecf20Sopenharmony_ci		mips_machtype = MACH_DS5000_XX;
1668c2ecf20Sopenharmony_ci		prom_init_kn02xa();
1678c2ecf20Sopenharmony_ci		break;
1688c2ecf20Sopenharmony_ci	case DS5800:		/* DS5800 Isis */
1698c2ecf20Sopenharmony_ci		mips_machtype = MACH_DS5800;
1708c2ecf20Sopenharmony_ci		break;
1718c2ecf20Sopenharmony_ci	case DS5400:		/* DS5400 MIPSfair */
1728c2ecf20Sopenharmony_ci		mips_machtype = MACH_DS5400;
1738c2ecf20Sopenharmony_ci		break;
1748c2ecf20Sopenharmony_ci	case DS5500:		/* DS5500 MIPSfair-2 */
1758c2ecf20Sopenharmony_ci		mips_machtype = MACH_DS5500;
1768c2ecf20Sopenharmony_ci		break;
1778c2ecf20Sopenharmony_ci	default:
1788c2ecf20Sopenharmony_ci		mips_machtype = MACH_DSUNKNOWN;
1798c2ecf20Sopenharmony_ci		break;
1808c2ecf20Sopenharmony_ci	}
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	if (mips_machtype == MACH_DSUNKNOWN)
1838c2ecf20Sopenharmony_ci		printk("This is an %s, id is %x\n",
1848c2ecf20Sopenharmony_ci		       dec_system_strings[mips_machtype], dec_systype);
1858c2ecf20Sopenharmony_ci	else
1868c2ecf20Sopenharmony_ci		printk("This is a %s\n", dec_system_strings[mips_machtype]);
1878c2ecf20Sopenharmony_ci}
188