18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2008 Nuovation System Designs, LLC
48c2ecf20Sopenharmony_ci *   Grant Erickson <gerickson@nuovations.com>
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This file defines processor mnemonics for accessing and managing
78c2ecf20Sopenharmony_ci * the IBM DDR1/DDR2 ECC controller found in the 405EX[r], 440SP,
88c2ecf20Sopenharmony_ci * 440SPe, 460EX, 460GT and 460SX.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef __PPC4XX_EDAC_H
128c2ecf20Sopenharmony_ci#define __PPC4XX_EDAC_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/types.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/*
178c2ecf20Sopenharmony_ci * Macro for generating register field mnemonics
188c2ecf20Sopenharmony_ci */
198c2ecf20Sopenharmony_ci#define PPC_REG_BITS			32
208c2ecf20Sopenharmony_ci#define PPC_REG_VAL(bit, val)		((val) << ((PPC_REG_BITS - 1) - (bit)))
218c2ecf20Sopenharmony_ci#define PPC_REG_DECODE(bit, val)	((val) >> ((PPC_REG_BITS - 1) - (bit)))
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/*
248c2ecf20Sopenharmony_ci * IBM 4xx DDR1/DDR2 SDRAM memory controller registers (at least those
258c2ecf20Sopenharmony_ci * relevant to ECC)
268c2ecf20Sopenharmony_ci */
278c2ecf20Sopenharmony_ci#define SDRAM_BESR			0x00	/* Error status (read/clear) */
288c2ecf20Sopenharmony_ci#define SDRAM_BESRT			0x01	/* Error statuss (test/set)  */
298c2ecf20Sopenharmony_ci#define SDRAM_BEARL			0x02	/* Error address low	     */
308c2ecf20Sopenharmony_ci#define SDRAM_BEARH			0x03	/* Error address high	     */
318c2ecf20Sopenharmony_ci#define SDRAM_WMIRQ			0x06	/* Write master (read/clear) */
328c2ecf20Sopenharmony_ci#define SDRAM_WMIRQT			0x07	/* Write master (test/set)   */
338c2ecf20Sopenharmony_ci#define SDRAM_MCOPT1			0x20	/* Controller options 1	     */
348c2ecf20Sopenharmony_ci#define SDRAM_MBXCF_BASE		0x40	/* Bank n configuration base */
358c2ecf20Sopenharmony_ci#define	SDRAM_MBXCF(n)			(SDRAM_MBXCF_BASE + (4 * (n)))
368c2ecf20Sopenharmony_ci#define SDRAM_MB0CF			SDRAM_MBXCF(0)
378c2ecf20Sopenharmony_ci#define SDRAM_MB1CF			SDRAM_MBXCF(1)
388c2ecf20Sopenharmony_ci#define SDRAM_MB2CF			SDRAM_MBXCF(2)
398c2ecf20Sopenharmony_ci#define SDRAM_MB3CF			SDRAM_MBXCF(3)
408c2ecf20Sopenharmony_ci#define SDRAM_ECCCR			0x98	/* ECC error status	     */
418c2ecf20Sopenharmony_ci#define SDRAM_ECCES			SDRAM_ECCCR
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci/*
448c2ecf20Sopenharmony_ci * PLB Master IDs
458c2ecf20Sopenharmony_ci */
468c2ecf20Sopenharmony_ci#define	SDRAM_PLB_M0ID_FIRST		0
478c2ecf20Sopenharmony_ci#define	SDRAM_PLB_M0ID_ICU		SDRAM_PLB_M0ID_FIRST
488c2ecf20Sopenharmony_ci#define	SDRAM_PLB_M0ID_PCIE0		1
498c2ecf20Sopenharmony_ci#define	SDRAM_PLB_M0ID_PCIE1		2
508c2ecf20Sopenharmony_ci#define	SDRAM_PLB_M0ID_DMA		3
518c2ecf20Sopenharmony_ci#define	SDRAM_PLB_M0ID_DCU		4
528c2ecf20Sopenharmony_ci#define	SDRAM_PLB_M0ID_OPB		5
538c2ecf20Sopenharmony_ci#define	SDRAM_PLB_M0ID_MAL		6
548c2ecf20Sopenharmony_ci#define	SDRAM_PLB_M0ID_SEC		7
558c2ecf20Sopenharmony_ci#define	SDRAM_PLB_M0ID_AHB		8
568c2ecf20Sopenharmony_ci#define SDRAM_PLB_M0ID_LAST		SDRAM_PLB_M0ID_AHB
578c2ecf20Sopenharmony_ci#define SDRAM_PLB_M0ID_COUNT		(SDRAM_PLB_M0ID_LAST - \
588c2ecf20Sopenharmony_ci					 SDRAM_PLB_M0ID_FIRST + 1)
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/*
618c2ecf20Sopenharmony_ci * Memory Controller Bus Error Status Register
628c2ecf20Sopenharmony_ci */
638c2ecf20Sopenharmony_ci#define SDRAM_BESR_MASK			PPC_REG_VAL(7, 0xFF)
648c2ecf20Sopenharmony_ci#define SDRAM_BESR_M0ID_MASK		PPC_REG_VAL(3, 0xF)
658c2ecf20Sopenharmony_ci#define	SDRAM_BESR_M0ID_DECODE(n)	PPC_REG_DECODE(3, n)
668c2ecf20Sopenharmony_ci#define SDRAM_BESR_M0ID_ICU		PPC_REG_VAL(3, SDRAM_PLB_M0ID_ICU)
678c2ecf20Sopenharmony_ci#define SDRAM_BESR_M0ID_PCIE0		PPC_REG_VAL(3, SDRAM_PLB_M0ID_PCIE0)
688c2ecf20Sopenharmony_ci#define SDRAM_BESR_M0ID_PCIE1		PPC_REG_VAL(3, SDRAM_PLB_M0ID_PCIE1)
698c2ecf20Sopenharmony_ci#define SDRAM_BESR_M0ID_DMA		PPC_REG_VAL(3, SDRAM_PLB_M0ID_DMA)
708c2ecf20Sopenharmony_ci#define SDRAM_BESR_M0ID_DCU		PPC_REG_VAL(3, SDRAM_PLB_M0ID_DCU)
718c2ecf20Sopenharmony_ci#define SDRAM_BESR_M0ID_OPB		PPC_REG_VAL(3, SDRAM_PLB_M0ID_OPB)
728c2ecf20Sopenharmony_ci#define SDRAM_BESR_M0ID_MAL		PPC_REG_VAL(3, SDRAM_PLB_M0ID_MAL)
738c2ecf20Sopenharmony_ci#define SDRAM_BESR_M0ID_SEC		PPC_REG_VAL(3, SDRAM_PLB_M0ID_SEC)
748c2ecf20Sopenharmony_ci#define SDRAM_BESR_M0ID_AHB		PPC_REG_VAL(3, SDRAM_PLB_M0ID_AHB)
758c2ecf20Sopenharmony_ci#define SDRAM_BESR_M0ET_MASK		PPC_REG_VAL(6, 0x7)
768c2ecf20Sopenharmony_ci#define SDRAM_BESR_M0ET_NONE		PPC_REG_VAL(6, 0)
778c2ecf20Sopenharmony_ci#define SDRAM_BESR_M0ET_ECC		PPC_REG_VAL(6, 1)
788c2ecf20Sopenharmony_ci#define SDRAM_BESR_M0RW_MASK		PPC_REG_VAL(7, 1)
798c2ecf20Sopenharmony_ci#define SDRAM_BESR_M0RW_WRITE		PPC_REG_VAL(7, 0)
808c2ecf20Sopenharmony_ci#define SDRAM_BESR_M0RW_READ		PPC_REG_VAL(7, 1)
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci/*
838c2ecf20Sopenharmony_ci * Memory Controller PLB Write Master Interrupt Register
848c2ecf20Sopenharmony_ci */
858c2ecf20Sopenharmony_ci#define SDRAM_WMIRQ_MASK		PPC_REG_VAL(8, 0x1FF)
868c2ecf20Sopenharmony_ci#define	SDRAM_WMIRQ_ENCODE(id)		PPC_REG_VAL((id % \
878c2ecf20Sopenharmony_ci						     SDRAM_PLB_M0ID_COUNT), 1)
888c2ecf20Sopenharmony_ci#define SDRAM_WMIRQ_ICU			PPC_REG_VAL(SDRAM_PLB_M0ID_ICU, 1)
898c2ecf20Sopenharmony_ci#define SDRAM_WMIRQ_PCIE0		PPC_REG_VAL(SDRAM_PLB_M0ID_PCIE0, 1)
908c2ecf20Sopenharmony_ci#define SDRAM_WMIRQ_PCIE1		PPC_REG_VAL(SDRAM_PLB_M0ID_PCIE1, 1)
918c2ecf20Sopenharmony_ci#define SDRAM_WMIRQ_DMA			PPC_REG_VAL(SDRAM_PLB_M0ID_DMA, 1)
928c2ecf20Sopenharmony_ci#define SDRAM_WMIRQ_DCU			PPC_REG_VAL(SDRAM_PLB_M0ID_DCU, 1)
938c2ecf20Sopenharmony_ci#define SDRAM_WMIRQ_OPB			PPC_REG_VAL(SDRAM_PLB_M0ID_OPB, 1)
948c2ecf20Sopenharmony_ci#define SDRAM_WMIRQ_MAL			PPC_REG_VAL(SDRAM_PLB_M0ID_MAL, 1)
958c2ecf20Sopenharmony_ci#define SDRAM_WMIRQ_SEC			PPC_REG_VAL(SDRAM_PLB_M0ID_SEC, 1)
968c2ecf20Sopenharmony_ci#define SDRAM_WMIRQ_AHB			PPC_REG_VAL(SDRAM_PLB_M0ID_AHB, 1)
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci/*
998c2ecf20Sopenharmony_ci * Memory Controller Options 1 Register
1008c2ecf20Sopenharmony_ci */
1018c2ecf20Sopenharmony_ci#define SDRAM_MCOPT1_MCHK_MASK	    PPC_REG_VAL(3, 0x3)	 /* ECC mask	     */
1028c2ecf20Sopenharmony_ci#define SDRAM_MCOPT1_MCHK_NON	    PPC_REG_VAL(3, 0x0)	 /* No ECC gen	     */
1038c2ecf20Sopenharmony_ci#define SDRAM_MCOPT1_MCHK_GEN	    PPC_REG_VAL(3, 0x2)	 /* ECC gen	     */
1048c2ecf20Sopenharmony_ci#define SDRAM_MCOPT1_MCHK_CHK	    PPC_REG_VAL(3, 0x1)	 /* ECC gen and chk  */
1058c2ecf20Sopenharmony_ci#define SDRAM_MCOPT1_MCHK_CHK_REP   PPC_REG_VAL(3, 0x3)	 /* ECC gen/chk/rpt  */
1068c2ecf20Sopenharmony_ci#define SDRAM_MCOPT1_MCHK_DECODE(n) ((((u32)(n)) >> 28) & 0x3)
1078c2ecf20Sopenharmony_ci#define SDRAM_MCOPT1_RDEN_MASK	    PPC_REG_VAL(4, 0x1)	 /* Rgstrd DIMM mask */
1088c2ecf20Sopenharmony_ci#define SDRAM_MCOPT1_RDEN	    PPC_REG_VAL(4, 0x1)	 /* Rgstrd DIMM enbl */
1098c2ecf20Sopenharmony_ci#define SDRAM_MCOPT1_WDTH_MASK	    PPC_REG_VAL(7, 0x1)	 /* Width mask	     */
1108c2ecf20Sopenharmony_ci#define SDRAM_MCOPT1_WDTH_32	    PPC_REG_VAL(7, 0x0)	 /* 32 bits	     */
1118c2ecf20Sopenharmony_ci#define SDRAM_MCOPT1_WDTH_16	    PPC_REG_VAL(7, 0x1)	 /* 16 bits	     */
1128c2ecf20Sopenharmony_ci#define SDRAM_MCOPT1_DDR_TYPE_MASK  PPC_REG_VAL(11, 0x1) /* DDR type mask    */
1138c2ecf20Sopenharmony_ci#define SDRAM_MCOPT1_DDR1_TYPE	    PPC_REG_VAL(11, 0x0) /* DDR1 type	     */
1148c2ecf20Sopenharmony_ci#define SDRAM_MCOPT1_DDR2_TYPE	    PPC_REG_VAL(11, 0x1) /* DDR2 type	     */
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/*
1178c2ecf20Sopenharmony_ci * Memory Bank 0 - n Configuration Register
1188c2ecf20Sopenharmony_ci */
1198c2ecf20Sopenharmony_ci#define SDRAM_MBCF_BA_MASK		PPC_REG_VAL(12, 0x1FFF)
1208c2ecf20Sopenharmony_ci#define SDRAM_MBCF_SZ_MASK		PPC_REG_VAL(19, 0xF)
1218c2ecf20Sopenharmony_ci#define SDRAM_MBCF_SZ_DECODE(mbxcf)	PPC_REG_DECODE(19, mbxcf)
1228c2ecf20Sopenharmony_ci#define SDRAM_MBCF_SZ_4MB		PPC_REG_VAL(19, 0x0)
1238c2ecf20Sopenharmony_ci#define SDRAM_MBCF_SZ_8MB		PPC_REG_VAL(19, 0x1)
1248c2ecf20Sopenharmony_ci#define SDRAM_MBCF_SZ_16MB		PPC_REG_VAL(19, 0x2)
1258c2ecf20Sopenharmony_ci#define SDRAM_MBCF_SZ_32MB		PPC_REG_VAL(19, 0x3)
1268c2ecf20Sopenharmony_ci#define SDRAM_MBCF_SZ_64MB		PPC_REG_VAL(19, 0x4)
1278c2ecf20Sopenharmony_ci#define SDRAM_MBCF_SZ_128MB		PPC_REG_VAL(19, 0x5)
1288c2ecf20Sopenharmony_ci#define SDRAM_MBCF_SZ_256MB		PPC_REG_VAL(19, 0x6)
1298c2ecf20Sopenharmony_ci#define SDRAM_MBCF_SZ_512MB		PPC_REG_VAL(19, 0x7)
1308c2ecf20Sopenharmony_ci#define SDRAM_MBCF_SZ_1GB		PPC_REG_VAL(19, 0x8)
1318c2ecf20Sopenharmony_ci#define SDRAM_MBCF_SZ_2GB		PPC_REG_VAL(19, 0x9)
1328c2ecf20Sopenharmony_ci#define SDRAM_MBCF_SZ_4GB		PPC_REG_VAL(19, 0xA)
1338c2ecf20Sopenharmony_ci#define SDRAM_MBCF_SZ_8GB		PPC_REG_VAL(19, 0xB)
1348c2ecf20Sopenharmony_ci#define SDRAM_MBCF_AM_MASK		PPC_REG_VAL(23, 0xF)
1358c2ecf20Sopenharmony_ci#define SDRAM_MBCF_AM_MODE0		PPC_REG_VAL(23, 0x0)
1368c2ecf20Sopenharmony_ci#define SDRAM_MBCF_AM_MODE1		PPC_REG_VAL(23, 0x1)
1378c2ecf20Sopenharmony_ci#define SDRAM_MBCF_AM_MODE2		PPC_REG_VAL(23, 0x2)
1388c2ecf20Sopenharmony_ci#define SDRAM_MBCF_AM_MODE3		PPC_REG_VAL(23, 0x3)
1398c2ecf20Sopenharmony_ci#define SDRAM_MBCF_AM_MODE4		PPC_REG_VAL(23, 0x4)
1408c2ecf20Sopenharmony_ci#define SDRAM_MBCF_AM_MODE5		PPC_REG_VAL(23, 0x5)
1418c2ecf20Sopenharmony_ci#define SDRAM_MBCF_AM_MODE6		PPC_REG_VAL(23, 0x6)
1428c2ecf20Sopenharmony_ci#define SDRAM_MBCF_AM_MODE7		PPC_REG_VAL(23, 0x7)
1438c2ecf20Sopenharmony_ci#define SDRAM_MBCF_AM_MODE8		PPC_REG_VAL(23, 0x8)
1448c2ecf20Sopenharmony_ci#define SDRAM_MBCF_AM_MODE9		PPC_REG_VAL(23, 0x9)
1458c2ecf20Sopenharmony_ci#define SDRAM_MBCF_BE_MASK		PPC_REG_VAL(31, 0x1)
1468c2ecf20Sopenharmony_ci#define SDRAM_MBCF_BE_DISABLE		PPC_REG_VAL(31, 0x0)
1478c2ecf20Sopenharmony_ci#define SDRAM_MBCF_BE_ENABLE		PPC_REG_VAL(31, 0x1)
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci/*
1508c2ecf20Sopenharmony_ci * ECC Error Status
1518c2ecf20Sopenharmony_ci */
1528c2ecf20Sopenharmony_ci#define SDRAM_ECCES_MASK		PPC_REG_VAL(21, 0x3FFFFF)
1538c2ecf20Sopenharmony_ci#define SDRAM_ECCES_BNCE_MASK		PPC_REG_VAL(15, 0xFFFF)
1548c2ecf20Sopenharmony_ci#define SDRAM_ECCES_BNCE_ENCODE(lane)	PPC_REG_VAL(((lane) & 0xF), 1)
1558c2ecf20Sopenharmony_ci#define SDRAM_ECCES_CKBER_MASK		PPC_REG_VAL(17, 0x3)
1568c2ecf20Sopenharmony_ci#define SDRAM_ECCES_CKBER_NONE		PPC_REG_VAL(17, 0)
1578c2ecf20Sopenharmony_ci#define SDRAM_ECCES_CKBER_16_ECC_0_3	PPC_REG_VAL(17, 2)
1588c2ecf20Sopenharmony_ci#define SDRAM_ECCES_CKBER_32_ECC_0_3	PPC_REG_VAL(17, 1)
1598c2ecf20Sopenharmony_ci#define SDRAM_ECCES_CKBER_32_ECC_4_8	PPC_REG_VAL(17, 2)
1608c2ecf20Sopenharmony_ci#define SDRAM_ECCES_CKBER_32_ECC_0_8	PPC_REG_VAL(17, 3)
1618c2ecf20Sopenharmony_ci#define SDRAM_ECCES_CE			PPC_REG_VAL(18, 1)
1628c2ecf20Sopenharmony_ci#define SDRAM_ECCES_UE			PPC_REG_VAL(19, 1)
1638c2ecf20Sopenharmony_ci#define SDRAM_ECCES_BKNER_MASK		PPC_REG_VAL(21, 0x3)
1648c2ecf20Sopenharmony_ci#define SDRAM_ECCES_BK0ER		PPC_REG_VAL(20, 1)
1658c2ecf20Sopenharmony_ci#define SDRAM_ECCES_BK1ER		PPC_REG_VAL(21, 1)
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci#endif /* __PPC4XX_EDAC_H */
168