1cfe40fdbSDoug Thompson /* 2cfe40fdbSDoug Thompson * AMD64 class Memory Controller kernel module 3cfe40fdbSDoug Thompson * 4cfe40fdbSDoug Thompson * Copyright (c) 2009 SoftwareBitMaker. 5cfe40fdbSDoug Thompson * Copyright (c) 2009 Advanced Micro Devices, Inc. 6cfe40fdbSDoug Thompson * 7cfe40fdbSDoug Thompson * This file may be distributed under the terms of the 8cfe40fdbSDoug Thompson * GNU General Public License. 9cfe40fdbSDoug Thompson * 10cfe40fdbSDoug Thompson * Originally Written by Thayne Harbaugh 11cfe40fdbSDoug Thompson * 12cfe40fdbSDoug Thompson * Changes by Douglas "norsk" Thompson <dougthompson@xmission.com>: 13cfe40fdbSDoug Thompson * - K8 CPU Revision D and greater support 14cfe40fdbSDoug Thompson * 15cfe40fdbSDoug Thompson * Changes by Dave Peterson <dsp@llnl.gov> <dave_peterson@pobox.com>: 16cfe40fdbSDoug Thompson * - Module largely rewritten, with new (and hopefully correct) 17cfe40fdbSDoug Thompson * code for dealing with node and chip select interleaving, 18cfe40fdbSDoug Thompson * various code cleanup, and bug fixes 19cfe40fdbSDoug Thompson * - Added support for memory hoisting using DRAM hole address 20cfe40fdbSDoug Thompson * register 21cfe40fdbSDoug Thompson * 22cfe40fdbSDoug Thompson * Changes by Douglas "norsk" Thompson <dougthompson@xmission.com>: 23cfe40fdbSDoug Thompson * -K8 Rev (1207) revision support added, required Revision 24cfe40fdbSDoug Thompson * specific mini-driver code to support Rev F as well as 25cfe40fdbSDoug Thompson * prior revisions 26cfe40fdbSDoug Thompson * 27cfe40fdbSDoug Thompson * Changes by Douglas "norsk" Thompson <dougthompson@xmission.com>: 28cfe40fdbSDoug Thompson * -Family 10h revision support added. New PCI Device IDs, 29cfe40fdbSDoug Thompson * indicating new changes. Actual registers modified 30cfe40fdbSDoug Thompson * were slight, less than the Rev E to Rev F transition 31cfe40fdbSDoug Thompson * but changing the PCI Device ID was the proper thing to 32cfe40fdbSDoug Thompson * do, as it provides for almost automactic family 33cfe40fdbSDoug Thompson * detection. The mods to Rev F required more family 34cfe40fdbSDoug Thompson * information detection. 35cfe40fdbSDoug Thompson * 36cfe40fdbSDoug Thompson * Changes/Fixes by Borislav Petkov <borislav.petkov@amd.com>: 37cfe40fdbSDoug Thompson * - misc fixes and code cleanups 38cfe40fdbSDoug Thompson * 39cfe40fdbSDoug Thompson * This module is based on the following documents 40cfe40fdbSDoug Thompson * (available from http://www.amd.com/): 41cfe40fdbSDoug Thompson * 42cfe40fdbSDoug Thompson * Title: BIOS and Kernel Developer's Guide for AMD Athlon 64 and AMD 43cfe40fdbSDoug Thompson * Opteron Processors 44cfe40fdbSDoug Thompson * AMD publication #: 26094 45cfe40fdbSDoug Thompson *` Revision: 3.26 46cfe40fdbSDoug Thompson * 47cfe40fdbSDoug Thompson * Title: BIOS and Kernel Developer's Guide for AMD NPT Family 0Fh 48cfe40fdbSDoug Thompson * Processors 49cfe40fdbSDoug Thompson * AMD publication #: 32559 50cfe40fdbSDoug Thompson * Revision: 3.00 51cfe40fdbSDoug Thompson * Issue Date: May 2006 52cfe40fdbSDoug Thompson * 53cfe40fdbSDoug Thompson * Title: BIOS and Kernel Developer's Guide (BKDG) For AMD Family 10h 54cfe40fdbSDoug Thompson * Processors 55cfe40fdbSDoug Thompson * AMD publication #: 31116 56cfe40fdbSDoug Thompson * Revision: 3.00 57cfe40fdbSDoug Thompson * Issue Date: September 07, 2007 58cfe40fdbSDoug Thompson * 59cfe40fdbSDoug Thompson * Sections in the first 2 documents are no longer in sync with each other. 60cfe40fdbSDoug Thompson * The Family 10h BKDG was totally re-written from scratch with a new 61cfe40fdbSDoug Thompson * presentation model. 62cfe40fdbSDoug Thompson * Therefore, comments that refer to a Document section might be off. 63cfe40fdbSDoug Thompson */ 64cfe40fdbSDoug Thompson 65cfe40fdbSDoug Thompson #include <linux/module.h> 66cfe40fdbSDoug Thompson #include <linux/ctype.h> 67cfe40fdbSDoug Thompson #include <linux/init.h> 68cfe40fdbSDoug Thompson #include <linux/pci.h> 69cfe40fdbSDoug Thompson #include <linux/pci_ids.h> 70cfe40fdbSDoug Thompson #include <linux/slab.h> 71cfe40fdbSDoug Thompson #include <linux/mmzone.h> 72cfe40fdbSDoug Thompson #include <linux/edac.h> 73f9431992SDoug Thompson #include <asm/msr.h> 74cfe40fdbSDoug Thompson #include "edac_core.h" 7547ca08a4SBorislav Petkov #include "mce_amd.h" 76cfe40fdbSDoug Thompson 7724f9a7feSBorislav Petkov #define amd64_debug(fmt, arg...) \ 7824f9a7feSBorislav Petkov edac_printk(KERN_DEBUG, "amd64", fmt, ##arg) 79cfe40fdbSDoug Thompson 8024f9a7feSBorislav Petkov #define amd64_info(fmt, arg...) \ 8124f9a7feSBorislav Petkov edac_printk(KERN_INFO, "amd64", fmt, ##arg) 8224f9a7feSBorislav Petkov 8324f9a7feSBorislav Petkov #define amd64_notice(fmt, arg...) \ 8424f9a7feSBorislav Petkov edac_printk(KERN_NOTICE, "amd64", fmt, ##arg) 8524f9a7feSBorislav Petkov 8624f9a7feSBorislav Petkov #define amd64_warn(fmt, arg...) \ 8724f9a7feSBorislav Petkov edac_printk(KERN_WARNING, "amd64", fmt, ##arg) 8824f9a7feSBorislav Petkov 8924f9a7feSBorislav Petkov #define amd64_err(fmt, arg...) \ 9024f9a7feSBorislav Petkov edac_printk(KERN_ERR, "amd64", fmt, ##arg) 9124f9a7feSBorislav Petkov 9224f9a7feSBorislav Petkov #define amd64_mc_warn(mci, fmt, arg...) \ 9324f9a7feSBorislav Petkov edac_mc_chipset_printk(mci, KERN_WARNING, "amd64", fmt, ##arg) 9424f9a7feSBorislav Petkov 9524f9a7feSBorislav Petkov #define amd64_mc_err(mci, fmt, arg...) \ 9624f9a7feSBorislav Petkov edac_mc_chipset_printk(mci, KERN_ERR, "amd64", fmt, ##arg) 97cfe40fdbSDoug Thompson 98cfe40fdbSDoug Thompson /* 99cfe40fdbSDoug Thompson * Throughout the comments in this code, the following terms are used: 100cfe40fdbSDoug Thompson * 101cfe40fdbSDoug Thompson * SysAddr, DramAddr, and InputAddr 102cfe40fdbSDoug Thompson * 103cfe40fdbSDoug Thompson * These terms come directly from the amd64 documentation 104cfe40fdbSDoug Thompson * (AMD publication #26094). They are defined as follows: 105cfe40fdbSDoug Thompson * 106cfe40fdbSDoug Thompson * SysAddr: 107cfe40fdbSDoug Thompson * This is a physical address generated by a CPU core or a device 108cfe40fdbSDoug Thompson * doing DMA. If generated by a CPU core, a SysAddr is the result of 109cfe40fdbSDoug Thompson * a virtual to physical address translation by the CPU core's address 110cfe40fdbSDoug Thompson * translation mechanism (MMU). 111cfe40fdbSDoug Thompson * 112cfe40fdbSDoug Thompson * DramAddr: 113cfe40fdbSDoug Thompson * A DramAddr is derived from a SysAddr by subtracting an offset that 114cfe40fdbSDoug Thompson * depends on which node the SysAddr maps to and whether the SysAddr 115cfe40fdbSDoug Thompson * is within a range affected by memory hoisting. The DRAM Base 116cfe40fdbSDoug Thompson * (section 3.4.4.1) and DRAM Limit (section 3.4.4.2) registers 117cfe40fdbSDoug Thompson * determine which node a SysAddr maps to. 118cfe40fdbSDoug Thompson * 119cfe40fdbSDoug Thompson * If the DRAM Hole Address Register (DHAR) is enabled and the SysAddr 120cfe40fdbSDoug Thompson * is within the range of addresses specified by this register, then 121cfe40fdbSDoug Thompson * a value x from the DHAR is subtracted from the SysAddr to produce a 122cfe40fdbSDoug Thompson * DramAddr. Here, x represents the base address for the node that 123cfe40fdbSDoug Thompson * the SysAddr maps to plus an offset due to memory hoisting. See 124cfe40fdbSDoug Thompson * section 3.4.8 and the comments in amd64_get_dram_hole_info() and 125cfe40fdbSDoug Thompson * sys_addr_to_dram_addr() below for more information. 126cfe40fdbSDoug Thompson * 127cfe40fdbSDoug Thompson * If the SysAddr is not affected by the DHAR then a value y is 128cfe40fdbSDoug Thompson * subtracted from the SysAddr to produce a DramAddr. Here, y is the 129cfe40fdbSDoug Thompson * base address for the node that the SysAddr maps to. See section 130cfe40fdbSDoug Thompson * 3.4.4 and the comments in sys_addr_to_dram_addr() below for more 131cfe40fdbSDoug Thompson * information. 132cfe40fdbSDoug Thompson * 133cfe40fdbSDoug Thompson * InputAddr: 134cfe40fdbSDoug Thompson * A DramAddr is translated to an InputAddr before being passed to the 135cfe40fdbSDoug Thompson * memory controller for the node that the DramAddr is associated 136cfe40fdbSDoug Thompson * with. The memory controller then maps the InputAddr to a csrow. 137cfe40fdbSDoug Thompson * If node interleaving is not in use, then the InputAddr has the same 138cfe40fdbSDoug Thompson * value as the DramAddr. Otherwise, the InputAddr is produced by 139cfe40fdbSDoug Thompson * discarding the bits used for node interleaving from the DramAddr. 140cfe40fdbSDoug Thompson * See section 3.4.4 for more information. 141cfe40fdbSDoug Thompson * 142cfe40fdbSDoug Thompson * The memory controller for a given node uses its DRAM CS Base and 143cfe40fdbSDoug Thompson * DRAM CS Mask registers to map an InputAddr to a csrow. See 144cfe40fdbSDoug Thompson * sections 3.5.4 and 3.5.5 for more information. 145cfe40fdbSDoug Thompson */ 146cfe40fdbSDoug Thompson 14724f9a7feSBorislav Petkov #define EDAC_AMD64_VERSION "v3.3.0" 148cfe40fdbSDoug Thompson #define EDAC_MOD_STR "amd64_edac" 149cfe40fdbSDoug Thompson 150cfe40fdbSDoug Thompson /* Extended Model from CPUID, for CPU Revision numbers */ 1511433eb99SBorislav Petkov #define K8_REV_D 1 1521433eb99SBorislav Petkov #define K8_REV_E 2 1531433eb99SBorislav Petkov #define K8_REV_F 4 154cfe40fdbSDoug Thompson 155cfe40fdbSDoug Thompson /* Hardware limit on ChipSelect rows per MC and processors per system */ 1569d858bb1SBorislav Petkov #define MAX_CS_COUNT 8 157cfe40fdbSDoug Thompson #define DRAM_REG_COUNT 8 158cfe40fdbSDoug Thompson 159f6d6ae96SBorislav Petkov #define ON true 160f6d6ae96SBorislav Petkov #define OFF false 161cfe40fdbSDoug Thompson 162cfe40fdbSDoug Thompson /* 163cfe40fdbSDoug Thompson * PCI-defined configuration space registers 164cfe40fdbSDoug Thompson */ 165cfe40fdbSDoug Thompson 166cfe40fdbSDoug Thompson 167cfe40fdbSDoug Thompson /* 168cfe40fdbSDoug Thompson * Function 1 - Address Map 169cfe40fdbSDoug Thompson */ 170cfe40fdbSDoug Thompson #define K8_DRAM_BASE_LOW 0x40 171cfe40fdbSDoug Thompson #define K8_DRAM_LIMIT_LOW 0x44 172cfe40fdbSDoug Thompson #define K8_DHAR 0xf0 173cfe40fdbSDoug Thompson 174cfe40fdbSDoug Thompson #define DHAR_VALID BIT(0) 175cfe40fdbSDoug Thompson #define F10_DRAM_MEM_HOIST_VALID BIT(1) 176cfe40fdbSDoug Thompson 177cfe40fdbSDoug Thompson #define DHAR_BASE_MASK 0xff000000 178cfe40fdbSDoug Thompson #define dhar_base(dhar) (dhar & DHAR_BASE_MASK) 179cfe40fdbSDoug Thompson 180cfe40fdbSDoug Thompson #define K8_DHAR_OFFSET_MASK 0x0000ff00 181cfe40fdbSDoug Thompson #define k8_dhar_offset(dhar) ((dhar & K8_DHAR_OFFSET_MASK) << 16) 182cfe40fdbSDoug Thompson 183cfe40fdbSDoug Thompson #define F10_DHAR_OFFSET_MASK 0x0000ff80 184cfe40fdbSDoug Thompson /* NOTE: Extra mask bit vs K8 */ 185cfe40fdbSDoug Thompson #define f10_dhar_offset(dhar) ((dhar & F10_DHAR_OFFSET_MASK) << 16) 186cfe40fdbSDoug Thompson 187*b2b0c605SBorislav Petkov #define DCT_CFG_SEL 0x10C 188cfe40fdbSDoug Thompson 189cfe40fdbSDoug Thompson /* F10 High BASE/LIMIT registers */ 190cfe40fdbSDoug Thompson #define F10_DRAM_BASE_HIGH 0x140 191cfe40fdbSDoug Thompson #define F10_DRAM_LIMIT_HIGH 0x144 192cfe40fdbSDoug Thompson 193cfe40fdbSDoug Thompson 194cfe40fdbSDoug Thompson /* 195cfe40fdbSDoug Thompson * Function 2 - DRAM controller 196cfe40fdbSDoug Thompson */ 197cfe40fdbSDoug Thompson #define K8_DCSB0 0x40 198cfe40fdbSDoug Thompson #define F10_DCSB1 0x140 199cfe40fdbSDoug Thompson 200cfe40fdbSDoug Thompson #define K8_DCSB_CS_ENABLE BIT(0) 201cfe40fdbSDoug Thompson #define K8_DCSB_NPT_SPARE BIT(1) 202cfe40fdbSDoug Thompson #define K8_DCSB_NPT_TESTFAIL BIT(2) 203cfe40fdbSDoug Thompson 204cfe40fdbSDoug Thompson /* 205cfe40fdbSDoug Thompson * REV E: select [31:21] and [15:9] from DCSB and the shift amount to form 206cfe40fdbSDoug Thompson * the address 207cfe40fdbSDoug Thompson */ 208cfe40fdbSDoug Thompson #define REV_E_DCSB_BASE_BITS (0xFFE0FE00ULL) 209cfe40fdbSDoug Thompson #define REV_E_DCS_SHIFT 4 210cfe40fdbSDoug Thompson 211cfe40fdbSDoug Thompson #define REV_F_F1Xh_DCSB_BASE_BITS (0x1FF83FE0ULL) 212cfe40fdbSDoug Thompson #define REV_F_F1Xh_DCS_SHIFT 8 213cfe40fdbSDoug Thompson 214cfe40fdbSDoug Thompson /* 215cfe40fdbSDoug Thompson * REV F and later: selects [28:19] and [13:5] from DCSB and the shift amount 216cfe40fdbSDoug Thompson * to form the address 217cfe40fdbSDoug Thompson */ 218cfe40fdbSDoug Thompson #define REV_F_DCSB_BASE_BITS (0x1FF83FE0ULL) 219cfe40fdbSDoug Thompson #define REV_F_DCS_SHIFT 8 220cfe40fdbSDoug Thompson 221cfe40fdbSDoug Thompson /* DRAM CS Mask Registers */ 222cfe40fdbSDoug Thompson #define K8_DCSM0 0x60 223cfe40fdbSDoug Thompson #define F10_DCSM1 0x160 224cfe40fdbSDoug Thompson 225cfe40fdbSDoug Thompson /* REV E: select [29:21] and [15:9] from DCSM */ 226cfe40fdbSDoug Thompson #define REV_E_DCSM_MASK_BITS 0x3FE0FE00 227cfe40fdbSDoug Thompson 228cfe40fdbSDoug Thompson /* unused bits [24:20] and [12:0] */ 229cfe40fdbSDoug Thompson #define REV_E_DCS_NOTUSED_BITS 0x01F01FFF 230cfe40fdbSDoug Thompson 231cfe40fdbSDoug Thompson /* REV F and later: select [28:19] and [13:5] from DCSM */ 232cfe40fdbSDoug Thompson #define REV_F_F1Xh_DCSM_MASK_BITS 0x1FF83FE0 233cfe40fdbSDoug Thompson 234cfe40fdbSDoug Thompson /* unused bits [26:22] and [12:0] */ 235cfe40fdbSDoug Thompson #define REV_F_F1Xh_DCS_NOTUSED_BITS 0x07C01FFF 236cfe40fdbSDoug Thompson 237cfe40fdbSDoug Thompson #define DBAM0 0x80 238cfe40fdbSDoug Thompson #define DBAM1 0x180 239cfe40fdbSDoug Thompson 240cfe40fdbSDoug Thompson /* Extract the DIMM 'type' on the i'th DIMM from the DBAM reg value passed */ 241cfe40fdbSDoug Thompson #define DBAM_DIMM(i, reg) ((((reg) >> (4*i))) & 0xF) 242cfe40fdbSDoug Thompson 243cfe40fdbSDoug Thompson #define DBAM_MAX_VALUE 11 244cfe40fdbSDoug Thompson 245cfe40fdbSDoug Thompson 246cfe40fdbSDoug Thompson #define F10_DCLR_0 0x90 247cfe40fdbSDoug Thompson #define F10_DCLR_1 0x190 248cfe40fdbSDoug Thompson #define REVE_WIDTH_128 BIT(16) 249cfe40fdbSDoug Thompson #define F10_WIDTH_128 BIT(11) 250cfe40fdbSDoug Thompson 251cfe40fdbSDoug Thompson 252cfe40fdbSDoug Thompson #define F10_DCHR_0 0x94 253cfe40fdbSDoug Thompson #define F10_DCHR_1 0x194 254cfe40fdbSDoug Thompson 255cfe40fdbSDoug Thompson #define F10_DCHR_FOUR_RANK_DIMM BIT(18) 2561433eb99SBorislav Petkov #define DDR3_MODE BIT(8) 257cfe40fdbSDoug Thompson #define F10_DCHR_MblMode BIT(6) 258cfe40fdbSDoug Thompson 259cfe40fdbSDoug Thompson 260cfe40fdbSDoug Thompson #define F10_DCTL_SEL_LOW 0x110 261*b2b0c605SBorislav Petkov #define dct_sel_baseaddr(pvt) ((pvt->dct_sel_low) & 0xFFFFF800) 262*b2b0c605SBorislav Petkov #define dct_sel_interleave_addr(pvt) (((pvt->dct_sel_low) >> 6) & 0x3) 263*b2b0c605SBorislav Petkov #define dct_high_range_enabled(pvt) (pvt->dct_sel_low & BIT(0)) 264*b2b0c605SBorislav Petkov #define dct_interleave_enabled(pvt) (pvt->dct_sel_low & BIT(2)) 265*b2b0c605SBorislav Petkov #define dct_ganging_enabled(pvt) (pvt->dct_sel_low & BIT(4)) 266*b2b0c605SBorislav Petkov #define dct_data_intlv_enabled(pvt) (pvt->dct_sel_low & BIT(5)) 267*b2b0c605SBorislav Petkov #define dct_dram_enabled(pvt) (pvt->dct_sel_low & BIT(8)) 268*b2b0c605SBorislav Petkov #define dct_memory_cleared(pvt) (pvt->dct_sel_low & BIT(10)) 269cfe40fdbSDoug Thompson 270cfe40fdbSDoug Thompson #define F10_DCTL_SEL_HIGH 0x114 271cfe40fdbSDoug Thompson 272cfe40fdbSDoug Thompson /* 273cfe40fdbSDoug Thompson * Function 3 - Misc Control 274cfe40fdbSDoug Thompson */ 275cfe40fdbSDoug Thompson #define K8_NBCTL 0x40 276cfe40fdbSDoug Thompson 277cfe40fdbSDoug Thompson /* Correctable ECC error reporting enable */ 278cfe40fdbSDoug Thompson #define K8_NBCTL_CECCEn BIT(0) 279cfe40fdbSDoug Thompson 280cfe40fdbSDoug Thompson /* UnCorrectable ECC error reporting enable */ 281cfe40fdbSDoug Thompson #define K8_NBCTL_UECCEn BIT(1) 282cfe40fdbSDoug Thompson 283cfe40fdbSDoug Thompson #define K8_NBCFG 0x44 284cfe40fdbSDoug Thompson #define K8_NBCFG_CHIPKILL BIT(23) 285cfe40fdbSDoug Thompson #define K8_NBCFG_ECC_ENABLE BIT(22) 286cfe40fdbSDoug Thompson 287cfe40fdbSDoug Thompson #define K8_NBSL 0x48 288cfe40fdbSDoug Thompson 289cfe40fdbSDoug Thompson 290cfe40fdbSDoug Thompson /* Family F10h: Normalized Extended Error Codes */ 291cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_RES 0x0 292cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_ECC 0x8 293cfe40fdbSDoug Thompson 294cfe40fdbSDoug Thompson /* Next two are overloaded values */ 295cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_LINK_PROTO 0xB 296cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_L3_PROTO 0xB 297cfe40fdbSDoug Thompson 298cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_NB_ARRAY 0xC 299cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_DRAM_PARITY 0xD 300cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_LINK_RETRY 0xE 301cfe40fdbSDoug Thompson 302cfe40fdbSDoug Thompson /* Next two are overloaded values */ 303cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_GART_WALK 0xF 304cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_DEV_WALK 0xF 305cfe40fdbSDoug Thompson 306cfe40fdbSDoug Thompson /* 0x10 to 0x1B: Reserved */ 307cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_L3_DATA 0x1C 308cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_L3_TAG 0x1D 309cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_L3_LRU 0x1E 310cfe40fdbSDoug Thompson 311cfe40fdbSDoug Thompson /* K8: Normalized Extended Error Codes */ 312cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_ECC 0x0 313cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_CRC 0x1 314cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_SYNC 0x2 315cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_MST 0x3 316cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_TGT 0x4 317cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_GART 0x5 318cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_RMW 0x6 319cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_WDT 0x7 320cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_CHIPKILL_ECC 0x8 321cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_DRAM_PARITY 0xD 322cfe40fdbSDoug Thompson 323cfe40fdbSDoug Thompson /* 324cfe40fdbSDoug Thompson * The following are for BUS type errors AFTER values have been normalized by 325cfe40fdbSDoug Thompson * shifting right 326cfe40fdbSDoug Thompson */ 327cfe40fdbSDoug Thompson #define K8_NBSL_PP_SRC 0x0 328cfe40fdbSDoug Thompson #define K8_NBSL_PP_RES 0x1 329cfe40fdbSDoug Thompson #define K8_NBSL_PP_OBS 0x2 330cfe40fdbSDoug Thompson #define K8_NBSL_PP_GENERIC 0x3 331cfe40fdbSDoug Thompson 332cfe40fdbSDoug Thompson #define EXTRACT_ERR_CPU_MAP(x) ((x) & 0xF) 333cfe40fdbSDoug Thompson 334cfe40fdbSDoug Thompson #define K8_NBEAL 0x50 335cfe40fdbSDoug Thompson #define K8_NBEAH 0x54 336cfe40fdbSDoug Thompson #define K8_SCRCTRL 0x58 337cfe40fdbSDoug Thompson 338cfe40fdbSDoug Thompson #define F10_NB_CFG_LOW 0x88 339cfe40fdbSDoug Thompson 340cfe40fdbSDoug Thompson #define F10_ONLINE_SPARE 0xB0 341cfe40fdbSDoug Thompson #define F10_ONLINE_SPARE_SWAPDONE0(x) ((x) & BIT(1)) 342cfe40fdbSDoug Thompson #define F10_ONLINE_SPARE_SWAPDONE1(x) ((x) & BIT(3)) 343cfe40fdbSDoug Thompson #define F10_ONLINE_SPARE_BADDRAM_CS0(x) (((x) >> 4) & 0x00000007) 344cfe40fdbSDoug Thompson #define F10_ONLINE_SPARE_BADDRAM_CS1(x) (((x) >> 8) & 0x00000007) 345cfe40fdbSDoug Thompson 346cfe40fdbSDoug Thompson #define F10_NB_ARRAY_ADDR 0xB8 347cfe40fdbSDoug Thompson 348cfe40fdbSDoug Thompson #define F10_NB_ARRAY_DRAM_ECC 0x80000000 349cfe40fdbSDoug Thompson 350cfe40fdbSDoug Thompson /* Bits [2:1] are used to select 16-byte section within a 64-byte cacheline */ 351cfe40fdbSDoug Thompson #define SET_NB_ARRAY_ADDRESS(section) (((section) & 0x3) << 1) 352cfe40fdbSDoug Thompson 353cfe40fdbSDoug Thompson #define F10_NB_ARRAY_DATA 0xBC 354cfe40fdbSDoug Thompson 355cfe40fdbSDoug Thompson #define SET_NB_DRAM_INJECTION_WRITE(word, bits) \ 356cfe40fdbSDoug Thompson (BIT(((word) & 0xF) + 20) | \ 35794baaee4SBorislav Petkov BIT(17) | bits) 358cfe40fdbSDoug Thompson 359cfe40fdbSDoug Thompson #define SET_NB_DRAM_INJECTION_READ(word, bits) \ 360cfe40fdbSDoug Thompson (BIT(((word) & 0xF) + 20) | \ 36194baaee4SBorislav Petkov BIT(16) | bits) 362cfe40fdbSDoug Thompson 363cfe40fdbSDoug Thompson #define K8_NBCAP 0xE8 364cfe40fdbSDoug Thompson #define K8_NBCAP_CORES (BIT(12)|BIT(13)) 365cfe40fdbSDoug Thompson #define K8_NBCAP_CHIPKILL BIT(4) 366cfe40fdbSDoug Thompson #define K8_NBCAP_SECDED BIT(3) 367cfe40fdbSDoug Thompson #define K8_NBCAP_DCT_DUAL BIT(0) 368cfe40fdbSDoug Thompson 369ad6a32e9SBorislav Petkov #define EXT_NB_MCA_CFG 0x180 370ad6a32e9SBorislav Petkov 371f6d6ae96SBorislav Petkov /* MSRs */ 372cfe40fdbSDoug Thompson #define K8_MSR_MCGCTL_NBE BIT(4) 373cfe40fdbSDoug Thompson 374cfe40fdbSDoug Thompson #define K8_MSR_MC4CTL 0x0410 375cfe40fdbSDoug Thompson #define K8_MSR_MC4STAT 0x0411 376cfe40fdbSDoug Thompson #define K8_MSR_MC4ADDR 0x0412 377cfe40fdbSDoug Thompson 378cfe40fdbSDoug Thompson /* AMD sets the first MC device at device ID 0x18. */ 37937da0450SBorislav Petkov static inline int get_node_id(struct pci_dev *pdev) 380cfe40fdbSDoug Thompson { 381cfe40fdbSDoug Thompson return PCI_SLOT(pdev->devfn) - 0x18; 382cfe40fdbSDoug Thompson } 383cfe40fdbSDoug Thompson 384*b2b0c605SBorislav Petkov enum amd_families { 385cfe40fdbSDoug Thompson K8_CPUS = 0, 386cfe40fdbSDoug Thompson F10_CPUS, 387*b2b0c605SBorislav Petkov F15_CPUS, 388*b2b0c605SBorislav Petkov NUM_FAMILIES, 389cfe40fdbSDoug Thompson }; 390cfe40fdbSDoug Thompson 391cfe40fdbSDoug Thompson /* Error injection control structure */ 392cfe40fdbSDoug Thompson struct error_injection { 393cfe40fdbSDoug Thompson u32 section; 394cfe40fdbSDoug Thompson u32 word; 395cfe40fdbSDoug Thompson u32 bit_map; 396cfe40fdbSDoug Thompson }; 397cfe40fdbSDoug Thompson 398cfe40fdbSDoug Thompson struct amd64_pvt { 399b8cfa02fSBorislav Petkov struct low_ops *ops; 400b8cfa02fSBorislav Petkov 401cfe40fdbSDoug Thompson /* pci_device handles which we utilize */ 4028d5b5d9cSBorislav Petkov struct pci_dev *F1, *F2, *F3; 403cfe40fdbSDoug Thompson 404cfe40fdbSDoug Thompson int mc_node_id; /* MC index of this MC node */ 405cfe40fdbSDoug Thompson int ext_model; /* extended model value of this node */ 406cfe40fdbSDoug Thompson int channel_count; 407cfe40fdbSDoug Thompson 408cfe40fdbSDoug Thompson /* Raw registers */ 409cfe40fdbSDoug Thompson u32 dclr0; /* DRAM Configuration Low DCT0 reg */ 410cfe40fdbSDoug Thompson u32 dclr1; /* DRAM Configuration Low DCT1 reg */ 411cfe40fdbSDoug Thompson u32 dchr0; /* DRAM Configuration High DCT0 reg */ 412cfe40fdbSDoug Thompson u32 dchr1; /* DRAM Configuration High DCT1 reg */ 413cfe40fdbSDoug Thompson u32 nbcap; /* North Bridge Capabilities */ 414cfe40fdbSDoug Thompson u32 nbcfg; /* F10 North Bridge Configuration */ 415cfe40fdbSDoug Thompson u32 ext_nbcfg; /* Extended F10 North Bridge Configuration */ 416cfe40fdbSDoug Thompson u32 dhar; /* DRAM Hoist reg */ 417cfe40fdbSDoug Thompson u32 dbam0; /* DRAM Base Address Mapping reg for DCT0 */ 418cfe40fdbSDoug Thompson u32 dbam1; /* DRAM Base Address Mapping reg for DCT1 */ 419cfe40fdbSDoug Thompson 420cfe40fdbSDoug Thompson /* DRAM CS Base Address Registers F2x[1,0][5C:40] */ 4219d858bb1SBorislav Petkov u32 dcsb0[MAX_CS_COUNT]; 4229d858bb1SBorislav Petkov u32 dcsb1[MAX_CS_COUNT]; 423cfe40fdbSDoug Thompson 424cfe40fdbSDoug Thompson /* DRAM CS Mask Registers F2x[1,0][6C:60] */ 4259d858bb1SBorislav Petkov u32 dcsm0[MAX_CS_COUNT]; 4269d858bb1SBorislav Petkov u32 dcsm1[MAX_CS_COUNT]; 427cfe40fdbSDoug Thompson 428cfe40fdbSDoug Thompson /* 429cfe40fdbSDoug Thompson * Decoded parts of DRAM BASE and LIMIT Registers 430cfe40fdbSDoug Thompson * F1x[78,70,68,60,58,50,48,40] 431cfe40fdbSDoug Thompson */ 432cfe40fdbSDoug Thompson u64 dram_base[DRAM_REG_COUNT]; 433cfe40fdbSDoug Thompson u64 dram_limit[DRAM_REG_COUNT]; 434cfe40fdbSDoug Thompson u8 dram_IntlvSel[DRAM_REG_COUNT]; 435cfe40fdbSDoug Thompson u8 dram_IntlvEn[DRAM_REG_COUNT]; 436cfe40fdbSDoug Thompson u8 dram_DstNode[DRAM_REG_COUNT]; 437cfe40fdbSDoug Thompson u8 dram_rw_en[DRAM_REG_COUNT]; 438cfe40fdbSDoug Thompson 439cfe40fdbSDoug Thompson /* 440cfe40fdbSDoug Thompson * The following fields are set at (load) run time, after CPU revision 441cfe40fdbSDoug Thompson * has been determined, since the dct_base and dct_mask registers vary 442cfe40fdbSDoug Thompson * based on revision 443cfe40fdbSDoug Thompson */ 444cfe40fdbSDoug Thompson u32 dcsb_base; /* DCSB base bits */ 445cfe40fdbSDoug Thompson u32 dcsm_mask; /* DCSM mask bits */ 4469d858bb1SBorislav Petkov u32 cs_count; /* num chip selects (== num DCSB registers) */ 447cfe40fdbSDoug Thompson u32 num_dcsm; /* Number of DCSM registers */ 448cfe40fdbSDoug Thompson u32 dcs_mask_notused; /* DCSM notused mask bits */ 449cfe40fdbSDoug Thompson u32 dcs_shift; /* DCSB and DCSM shift value */ 450cfe40fdbSDoug Thompson 451cfe40fdbSDoug Thompson u64 top_mem; /* top of memory below 4GB */ 452cfe40fdbSDoug Thompson u64 top_mem2; /* top of memory above 4GB */ 453cfe40fdbSDoug Thompson 454*b2b0c605SBorislav Petkov u32 dct_sel_low; /* DRAM Controller Select Low Reg */ 455*b2b0c605SBorislav Petkov u32 dct_sel_hi; /* DRAM Controller Select High Reg */ 456cfe40fdbSDoug Thompson u32 online_spare; /* On-Line spare Reg */ 457cfe40fdbSDoug Thompson 458ad6a32e9SBorislav Petkov /* x4 or x8 syndromes in use */ 459ad6a32e9SBorislav Petkov u8 syn_type; 460ad6a32e9SBorislav Petkov 461cfe40fdbSDoug Thompson /* temp storage for when input is received from sysfs */ 462ef44cc4cSBorislav Petkov struct err_regs ctl_error_info; 463cfe40fdbSDoug Thompson 464cfe40fdbSDoug Thompson /* place to store error injection parameters prior to issue */ 465cfe40fdbSDoug Thompson struct error_injection injection; 466cfe40fdbSDoug Thompson 467395ae783SBorislav Petkov /* DCT per-family scrubrate setting */ 468395ae783SBorislav Petkov u32 min_scrubrate; 469395ae783SBorislav Petkov 4700092b20dSBorislav Petkov /* family name this instance is running on */ 4710092b20dSBorislav Petkov const char *ctl_name; 4720092b20dSBorislav Petkov 473ae7bb7c6SBorislav Petkov }; 474ae7bb7c6SBorislav Petkov 475ae7bb7c6SBorislav Petkov /* 476ae7bb7c6SBorislav Petkov * per-node ECC settings descriptor 477ae7bb7c6SBorislav Petkov */ 478ae7bb7c6SBorislav Petkov struct ecc_settings { 479ae7bb7c6SBorislav Petkov u32 old_nbctl; 480ae7bb7c6SBorislav Petkov bool nbctl_valid; 481ae7bb7c6SBorislav Petkov 482cfe40fdbSDoug Thompson struct flags { 483d95cf4deSBorislav Petkov unsigned long nb_mce_enable:1; 484d95cf4deSBorislav Petkov unsigned long nb_ecc_prev:1; 485cfe40fdbSDoug Thompson } flags; 486cfe40fdbSDoug Thompson }; 487cfe40fdbSDoug Thompson 488cfe40fdbSDoug Thompson extern const char *tt_msgs[4]; 489cfe40fdbSDoug Thompson extern const char *ll_msgs[4]; 490cfe40fdbSDoug Thompson extern const char *rrrr_msgs[16]; 491cfe40fdbSDoug Thompson extern const char *to_msgs[2]; 492cfe40fdbSDoug Thompson extern const char *pp_msgs[4]; 493cfe40fdbSDoug Thompson extern const char *ii_msgs[4]; 494cfe40fdbSDoug Thompson extern const char *htlink_msgs[8]; 495cfe40fdbSDoug Thompson 4967d6034d3SDoug Thompson #ifdef CONFIG_EDAC_DEBUG 4979cdeb404SBorislav Petkov #define NUM_DBG_ATTRS 5 4987d6034d3SDoug Thompson #else 4997d6034d3SDoug Thompson #define NUM_DBG_ATTRS 0 5007d6034d3SDoug Thompson #endif 5017d6034d3SDoug Thompson 5027d6034d3SDoug Thompson #ifdef CONFIG_EDAC_AMD64_ERROR_INJECTION 5037d6034d3SDoug Thompson #define NUM_INJ_ATTRS 5 5047d6034d3SDoug Thompson #else 5057d6034d3SDoug Thompson #define NUM_INJ_ATTRS 0 5067d6034d3SDoug Thompson #endif 5077d6034d3SDoug Thompson 5087d6034d3SDoug Thompson extern struct mcidev_sysfs_attribute amd64_dbg_attrs[NUM_DBG_ATTRS], 5097d6034d3SDoug Thompson amd64_inj_attrs[NUM_INJ_ATTRS]; 5107d6034d3SDoug Thompson 511cfe40fdbSDoug Thompson /* 512cfe40fdbSDoug Thompson * Each of the PCI Device IDs types have their own set of hardware accessor 513cfe40fdbSDoug Thompson * functions and per device encoding/decoding logic. 514cfe40fdbSDoug Thompson */ 515cfe40fdbSDoug Thompson struct low_ops { 516cfe40fdbSDoug Thompson int (*early_channel_count) (struct amd64_pvt *pvt); 517cfe40fdbSDoug Thompson 518cfe40fdbSDoug Thompson u64 (*get_error_address) (struct mem_ctl_info *mci, 519ef44cc4cSBorislav Petkov struct err_regs *info); 520cfe40fdbSDoug Thompson void (*read_dram_base_limit) (struct amd64_pvt *pvt, int dram); 521cfe40fdbSDoug Thompson void (*read_dram_ctl_register) (struct amd64_pvt *pvt); 522cfe40fdbSDoug Thompson void (*map_sysaddr_to_csrow) (struct mem_ctl_info *mci, 5231433eb99SBorislav Petkov struct err_regs *info, u64 SystemAddr); 5241433eb99SBorislav Petkov int (*dbam_to_cs) (struct amd64_pvt *pvt, int cs_mode); 525*b2b0c605SBorislav Petkov int (*read_dct_pci_cfg) (struct amd64_pvt *pvt, int offset, 526*b2b0c605SBorislav Petkov u32 *val, const char *func); 527cfe40fdbSDoug Thompson }; 528cfe40fdbSDoug Thompson 529cfe40fdbSDoug Thompson struct amd64_family_type { 530cfe40fdbSDoug Thompson const char *ctl_name; 5318d5b5d9cSBorislav Petkov u16 f1_id, f3_id; 532cfe40fdbSDoug Thompson struct low_ops ops; 533cfe40fdbSDoug Thompson }; 534cfe40fdbSDoug Thompson 535*b2b0c605SBorislav Petkov int __amd64_write_pci_cfg_dword(struct pci_dev *pdev, int offset, 536*b2b0c605SBorislav Petkov u32 val, const char *func); 5376ba5dcdcSBorislav Petkov 5386ba5dcdcSBorislav Petkov #define amd64_read_pci_cfg(pdev, offset, val) \ 539*b2b0c605SBorislav Petkov __amd64_read_pci_cfg_dword(pdev, offset, val, __func__) 540*b2b0c605SBorislav Petkov 541*b2b0c605SBorislav Petkov #define amd64_write_pci_cfg(pdev, offset, val) \ 542*b2b0c605SBorislav Petkov __amd64_write_pci_cfg_dword(pdev, offset, val, __func__) 543*b2b0c605SBorislav Petkov 544*b2b0c605SBorislav Petkov #define amd64_read_dct_pci_cfg(pvt, offset, val) \ 545*b2b0c605SBorislav Petkov pvt->ops->read_dct_pci_cfg(pvt, offset, val, __func__) 5466ba5dcdcSBorislav Petkov 547cfe40fdbSDoug Thompson /* 548cfe40fdbSDoug Thompson * For future CPU versions, verify the following as new 'slow' rates appear and 549cfe40fdbSDoug Thompson * modify the necessary skip values for the supported CPU. 550cfe40fdbSDoug Thompson */ 551cfe40fdbSDoug Thompson #define K8_MIN_SCRUB_RATE_BITS 0x0 552cfe40fdbSDoug Thompson #define F10_MIN_SCRUB_RATE_BITS 0x5 553cfe40fdbSDoug Thompson 554cfe40fdbSDoug Thompson int amd64_get_dram_hole_info(struct mem_ctl_info *mci, u64 *hole_base, 555cfe40fdbSDoug Thompson u64 *hole_offset, u64 *hole_size); 556