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 187cfe40fdbSDoug Thompson 188cfe40fdbSDoug Thompson /* F10 High BASE/LIMIT registers */ 189cfe40fdbSDoug Thompson #define F10_DRAM_BASE_HIGH 0x140 190cfe40fdbSDoug Thompson #define F10_DRAM_LIMIT_HIGH 0x144 191cfe40fdbSDoug Thompson 192cfe40fdbSDoug Thompson 193cfe40fdbSDoug Thompson /* 194cfe40fdbSDoug Thompson * Function 2 - DRAM controller 195cfe40fdbSDoug Thompson */ 196cfe40fdbSDoug Thompson #define K8_DCSB0 0x40 197cfe40fdbSDoug Thompson #define F10_DCSB1 0x140 198cfe40fdbSDoug Thompson 199cfe40fdbSDoug Thompson #define K8_DCSB_CS_ENABLE BIT(0) 200cfe40fdbSDoug Thompson #define K8_DCSB_NPT_SPARE BIT(1) 201cfe40fdbSDoug Thompson #define K8_DCSB_NPT_TESTFAIL BIT(2) 202cfe40fdbSDoug Thompson 203cfe40fdbSDoug Thompson /* 204cfe40fdbSDoug Thompson * REV E: select [31:21] and [15:9] from DCSB and the shift amount to form 205cfe40fdbSDoug Thompson * the address 206cfe40fdbSDoug Thompson */ 207cfe40fdbSDoug Thompson #define REV_E_DCSB_BASE_BITS (0xFFE0FE00ULL) 208cfe40fdbSDoug Thompson #define REV_E_DCS_SHIFT 4 209cfe40fdbSDoug Thompson 210cfe40fdbSDoug Thompson #define REV_F_F1Xh_DCSB_BASE_BITS (0x1FF83FE0ULL) 211cfe40fdbSDoug Thompson #define REV_F_F1Xh_DCS_SHIFT 8 212cfe40fdbSDoug Thompson 213cfe40fdbSDoug Thompson /* 214cfe40fdbSDoug Thompson * REV F and later: selects [28:19] and [13:5] from DCSB and the shift amount 215cfe40fdbSDoug Thompson * to form the address 216cfe40fdbSDoug Thompson */ 217cfe40fdbSDoug Thompson #define REV_F_DCSB_BASE_BITS (0x1FF83FE0ULL) 218cfe40fdbSDoug Thompson #define REV_F_DCS_SHIFT 8 219cfe40fdbSDoug Thompson 220cfe40fdbSDoug Thompson /* DRAM CS Mask Registers */ 221cfe40fdbSDoug Thompson #define K8_DCSM0 0x60 222cfe40fdbSDoug Thompson #define F10_DCSM1 0x160 223cfe40fdbSDoug Thompson 224cfe40fdbSDoug Thompson /* REV E: select [29:21] and [15:9] from DCSM */ 225cfe40fdbSDoug Thompson #define REV_E_DCSM_MASK_BITS 0x3FE0FE00 226cfe40fdbSDoug Thompson 227cfe40fdbSDoug Thompson /* unused bits [24:20] and [12:0] */ 228cfe40fdbSDoug Thompson #define REV_E_DCS_NOTUSED_BITS 0x01F01FFF 229cfe40fdbSDoug Thompson 230cfe40fdbSDoug Thompson /* REV F and later: select [28:19] and [13:5] from DCSM */ 231cfe40fdbSDoug Thompson #define REV_F_F1Xh_DCSM_MASK_BITS 0x1FF83FE0 232cfe40fdbSDoug Thompson 233cfe40fdbSDoug Thompson /* unused bits [26:22] and [12:0] */ 234cfe40fdbSDoug Thompson #define REV_F_F1Xh_DCS_NOTUSED_BITS 0x07C01FFF 235cfe40fdbSDoug Thompson 236cfe40fdbSDoug Thompson #define DBAM0 0x80 237cfe40fdbSDoug Thompson #define DBAM1 0x180 238cfe40fdbSDoug Thompson 239cfe40fdbSDoug Thompson /* Extract the DIMM 'type' on the i'th DIMM from the DBAM reg value passed */ 240cfe40fdbSDoug Thompson #define DBAM_DIMM(i, reg) ((((reg) >> (4*i))) & 0xF) 241cfe40fdbSDoug Thompson 242cfe40fdbSDoug Thompson #define DBAM_MAX_VALUE 11 243cfe40fdbSDoug Thompson 244cfe40fdbSDoug Thompson 245cfe40fdbSDoug Thompson #define F10_DCLR_0 0x90 246cfe40fdbSDoug Thompson #define F10_DCLR_1 0x190 247cfe40fdbSDoug Thompson #define REVE_WIDTH_128 BIT(16) 248cfe40fdbSDoug Thompson #define F10_WIDTH_128 BIT(11) 249cfe40fdbSDoug Thompson 250cfe40fdbSDoug Thompson 251cfe40fdbSDoug Thompson #define F10_DCHR_0 0x94 252cfe40fdbSDoug Thompson #define F10_DCHR_1 0x194 253cfe40fdbSDoug Thompson 254cfe40fdbSDoug Thompson #define F10_DCHR_FOUR_RANK_DIMM BIT(18) 2551433eb99SBorislav Petkov #define DDR3_MODE BIT(8) 256cfe40fdbSDoug Thompson #define F10_DCHR_MblMode BIT(6) 257cfe40fdbSDoug Thompson 258cfe40fdbSDoug Thompson 259cfe40fdbSDoug Thompson #define F10_DCTL_SEL_LOW 0x110 26069542650SBorislav Petkov #define dct_sel_baseaddr(pvt) ((pvt->dram_ctl_select_low) & 0xFFFFF800) 26169542650SBorislav Petkov #define dct_sel_interleave_addr(pvt) (((pvt->dram_ctl_select_low) >> 6) & 0x3) 26269542650SBorislav Petkov #define dct_high_range_enabled(pvt) (pvt->dram_ctl_select_low & BIT(0)) 26369542650SBorislav Petkov #define dct_interleave_enabled(pvt) (pvt->dram_ctl_select_low & BIT(2)) 26469542650SBorislav Petkov #define dct_ganging_enabled(pvt) (pvt->dram_ctl_select_low & BIT(4)) 26569542650SBorislav Petkov #define dct_data_intlv_enabled(pvt) (pvt->dram_ctl_select_low & BIT(5)) 26669542650SBorislav Petkov #define dct_dram_enabled(pvt) (pvt->dram_ctl_select_low & BIT(8)) 26769542650SBorislav Petkov #define dct_memory_cleared(pvt) (pvt->dram_ctl_select_low & BIT(10)) 268cfe40fdbSDoug Thompson 269cfe40fdbSDoug Thompson #define F10_DCTL_SEL_HIGH 0x114 270cfe40fdbSDoug Thompson 271cfe40fdbSDoug Thompson /* 272cfe40fdbSDoug Thompson * Function 3 - Misc Control 273cfe40fdbSDoug Thompson */ 274cfe40fdbSDoug Thompson #define K8_NBCTL 0x40 275cfe40fdbSDoug Thompson 276cfe40fdbSDoug Thompson /* Correctable ECC error reporting enable */ 277cfe40fdbSDoug Thompson #define K8_NBCTL_CECCEn BIT(0) 278cfe40fdbSDoug Thompson 279cfe40fdbSDoug Thompson /* UnCorrectable ECC error reporting enable */ 280cfe40fdbSDoug Thompson #define K8_NBCTL_UECCEn BIT(1) 281cfe40fdbSDoug Thompson 282cfe40fdbSDoug Thompson #define K8_NBCFG 0x44 283cfe40fdbSDoug Thompson #define K8_NBCFG_CHIPKILL BIT(23) 284cfe40fdbSDoug Thompson #define K8_NBCFG_ECC_ENABLE BIT(22) 285cfe40fdbSDoug Thompson 286cfe40fdbSDoug Thompson #define K8_NBSL 0x48 287cfe40fdbSDoug Thompson 288cfe40fdbSDoug Thompson 289cfe40fdbSDoug Thompson /* Family F10h: Normalized Extended Error Codes */ 290cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_RES 0x0 291cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_ECC 0x8 292cfe40fdbSDoug Thompson 293cfe40fdbSDoug Thompson /* Next two are overloaded values */ 294cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_LINK_PROTO 0xB 295cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_L3_PROTO 0xB 296cfe40fdbSDoug Thompson 297cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_NB_ARRAY 0xC 298cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_DRAM_PARITY 0xD 299cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_LINK_RETRY 0xE 300cfe40fdbSDoug Thompson 301cfe40fdbSDoug Thompson /* Next two are overloaded values */ 302cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_GART_WALK 0xF 303cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_DEV_WALK 0xF 304cfe40fdbSDoug Thompson 305cfe40fdbSDoug Thompson /* 0x10 to 0x1B: Reserved */ 306cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_L3_DATA 0x1C 307cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_L3_TAG 0x1D 308cfe40fdbSDoug Thompson #define F10_NBSL_EXT_ERR_L3_LRU 0x1E 309cfe40fdbSDoug Thompson 310cfe40fdbSDoug Thompson /* K8: Normalized Extended Error Codes */ 311cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_ECC 0x0 312cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_CRC 0x1 313cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_SYNC 0x2 314cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_MST 0x3 315cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_TGT 0x4 316cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_GART 0x5 317cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_RMW 0x6 318cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_WDT 0x7 319cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_CHIPKILL_ECC 0x8 320cfe40fdbSDoug Thompson #define K8_NBSL_EXT_ERR_DRAM_PARITY 0xD 321cfe40fdbSDoug Thompson 322cfe40fdbSDoug Thompson /* 323cfe40fdbSDoug Thompson * The following are for BUS type errors AFTER values have been normalized by 324cfe40fdbSDoug Thompson * shifting right 325cfe40fdbSDoug Thompson */ 326cfe40fdbSDoug Thompson #define K8_NBSL_PP_SRC 0x0 327cfe40fdbSDoug Thompson #define K8_NBSL_PP_RES 0x1 328cfe40fdbSDoug Thompson #define K8_NBSL_PP_OBS 0x2 329cfe40fdbSDoug Thompson #define K8_NBSL_PP_GENERIC 0x3 330cfe40fdbSDoug Thompson 331cfe40fdbSDoug Thompson #define EXTRACT_ERR_CPU_MAP(x) ((x) & 0xF) 332cfe40fdbSDoug Thompson 333cfe40fdbSDoug Thompson #define K8_NBEAL 0x50 334cfe40fdbSDoug Thompson #define K8_NBEAH 0x54 335cfe40fdbSDoug Thompson #define K8_SCRCTRL 0x58 336cfe40fdbSDoug Thompson 337cfe40fdbSDoug Thompson #define F10_NB_CFG_LOW 0x88 338cfe40fdbSDoug Thompson 339cfe40fdbSDoug Thompson #define F10_ONLINE_SPARE 0xB0 340cfe40fdbSDoug Thompson #define F10_ONLINE_SPARE_SWAPDONE0(x) ((x) & BIT(1)) 341cfe40fdbSDoug Thompson #define F10_ONLINE_SPARE_SWAPDONE1(x) ((x) & BIT(3)) 342cfe40fdbSDoug Thompson #define F10_ONLINE_SPARE_BADDRAM_CS0(x) (((x) >> 4) & 0x00000007) 343cfe40fdbSDoug Thompson #define F10_ONLINE_SPARE_BADDRAM_CS1(x) (((x) >> 8) & 0x00000007) 344cfe40fdbSDoug Thompson 345cfe40fdbSDoug Thompson #define F10_NB_ARRAY_ADDR 0xB8 346cfe40fdbSDoug Thompson 347cfe40fdbSDoug Thompson #define F10_NB_ARRAY_DRAM_ECC 0x80000000 348cfe40fdbSDoug Thompson 349cfe40fdbSDoug Thompson /* Bits [2:1] are used to select 16-byte section within a 64-byte cacheline */ 350cfe40fdbSDoug Thompson #define SET_NB_ARRAY_ADDRESS(section) (((section) & 0x3) << 1) 351cfe40fdbSDoug Thompson 352cfe40fdbSDoug Thompson #define F10_NB_ARRAY_DATA 0xBC 353cfe40fdbSDoug Thompson 354cfe40fdbSDoug Thompson #define SET_NB_DRAM_INJECTION_WRITE(word, bits) \ 355cfe40fdbSDoug Thompson (BIT(((word) & 0xF) + 20) | \ 35694baaee4SBorislav Petkov BIT(17) | bits) 357cfe40fdbSDoug Thompson 358cfe40fdbSDoug Thompson #define SET_NB_DRAM_INJECTION_READ(word, bits) \ 359cfe40fdbSDoug Thompson (BIT(((word) & 0xF) + 20) | \ 36094baaee4SBorislav Petkov BIT(16) | bits) 361cfe40fdbSDoug Thompson 362cfe40fdbSDoug Thompson #define K8_NBCAP 0xE8 363cfe40fdbSDoug Thompson #define K8_NBCAP_CORES (BIT(12)|BIT(13)) 364cfe40fdbSDoug Thompson #define K8_NBCAP_CHIPKILL BIT(4) 365cfe40fdbSDoug Thompson #define K8_NBCAP_SECDED BIT(3) 366cfe40fdbSDoug Thompson #define K8_NBCAP_DCT_DUAL BIT(0) 367cfe40fdbSDoug Thompson 368ad6a32e9SBorislav Petkov #define EXT_NB_MCA_CFG 0x180 369ad6a32e9SBorislav Petkov 370f6d6ae96SBorislav Petkov /* MSRs */ 371cfe40fdbSDoug Thompson #define K8_MSR_MCGCTL_NBE BIT(4) 372cfe40fdbSDoug Thompson 373cfe40fdbSDoug Thompson #define K8_MSR_MC4CTL 0x0410 374cfe40fdbSDoug Thompson #define K8_MSR_MC4STAT 0x0411 375cfe40fdbSDoug Thompson #define K8_MSR_MC4ADDR 0x0412 376cfe40fdbSDoug Thompson 377cfe40fdbSDoug Thompson /* AMD sets the first MC device at device ID 0x18. */ 37837da0450SBorislav Petkov static inline int get_node_id(struct pci_dev *pdev) 379cfe40fdbSDoug Thompson { 380cfe40fdbSDoug Thompson return PCI_SLOT(pdev->devfn) - 0x18; 381cfe40fdbSDoug Thompson } 382cfe40fdbSDoug Thompson 383cfe40fdbSDoug Thompson enum amd64_chipset_families { 384cfe40fdbSDoug Thompson K8_CPUS = 0, 385cfe40fdbSDoug Thompson F10_CPUS, 386cfe40fdbSDoug Thompson }; 387cfe40fdbSDoug Thompson 388cfe40fdbSDoug Thompson /* Error injection control structure */ 389cfe40fdbSDoug Thompson struct error_injection { 390cfe40fdbSDoug Thompson u32 section; 391cfe40fdbSDoug Thompson u32 word; 392cfe40fdbSDoug Thompson u32 bit_map; 393cfe40fdbSDoug Thompson }; 394cfe40fdbSDoug Thompson 395cfe40fdbSDoug Thompson struct amd64_pvt { 396b8cfa02fSBorislav Petkov struct low_ops *ops; 397b8cfa02fSBorislav Petkov 398cfe40fdbSDoug Thompson /* pci_device handles which we utilize */ 3998d5b5d9cSBorislav Petkov struct pci_dev *F1, *F2, *F3; 400cfe40fdbSDoug Thompson 401cfe40fdbSDoug Thompson int mc_node_id; /* MC index of this MC node */ 402cfe40fdbSDoug Thompson int ext_model; /* extended model value of this node */ 403cfe40fdbSDoug Thompson int channel_count; 404cfe40fdbSDoug Thompson 405cfe40fdbSDoug Thompson /* Raw registers */ 406cfe40fdbSDoug Thompson u32 dclr0; /* DRAM Configuration Low DCT0 reg */ 407cfe40fdbSDoug Thompson u32 dclr1; /* DRAM Configuration Low DCT1 reg */ 408cfe40fdbSDoug Thompson u32 dchr0; /* DRAM Configuration High DCT0 reg */ 409cfe40fdbSDoug Thompson u32 dchr1; /* DRAM Configuration High DCT1 reg */ 410cfe40fdbSDoug Thompson u32 nbcap; /* North Bridge Capabilities */ 411cfe40fdbSDoug Thompson u32 nbcfg; /* F10 North Bridge Configuration */ 412cfe40fdbSDoug Thompson u32 ext_nbcfg; /* Extended F10 North Bridge Configuration */ 413cfe40fdbSDoug Thompson u32 dhar; /* DRAM Hoist reg */ 414cfe40fdbSDoug Thompson u32 dbam0; /* DRAM Base Address Mapping reg for DCT0 */ 415cfe40fdbSDoug Thompson u32 dbam1; /* DRAM Base Address Mapping reg for DCT1 */ 416cfe40fdbSDoug Thompson 417cfe40fdbSDoug Thompson /* DRAM CS Base Address Registers F2x[1,0][5C:40] */ 4189d858bb1SBorislav Petkov u32 dcsb0[MAX_CS_COUNT]; 4199d858bb1SBorislav Petkov u32 dcsb1[MAX_CS_COUNT]; 420cfe40fdbSDoug Thompson 421cfe40fdbSDoug Thompson /* DRAM CS Mask Registers F2x[1,0][6C:60] */ 4229d858bb1SBorislav Petkov u32 dcsm0[MAX_CS_COUNT]; 4239d858bb1SBorislav Petkov u32 dcsm1[MAX_CS_COUNT]; 424cfe40fdbSDoug Thompson 425cfe40fdbSDoug Thompson /* 426cfe40fdbSDoug Thompson * Decoded parts of DRAM BASE and LIMIT Registers 427cfe40fdbSDoug Thompson * F1x[78,70,68,60,58,50,48,40] 428cfe40fdbSDoug Thompson */ 429cfe40fdbSDoug Thompson u64 dram_base[DRAM_REG_COUNT]; 430cfe40fdbSDoug Thompson u64 dram_limit[DRAM_REG_COUNT]; 431cfe40fdbSDoug Thompson u8 dram_IntlvSel[DRAM_REG_COUNT]; 432cfe40fdbSDoug Thompson u8 dram_IntlvEn[DRAM_REG_COUNT]; 433cfe40fdbSDoug Thompson u8 dram_DstNode[DRAM_REG_COUNT]; 434cfe40fdbSDoug Thompson u8 dram_rw_en[DRAM_REG_COUNT]; 435cfe40fdbSDoug Thompson 436cfe40fdbSDoug Thompson /* 437cfe40fdbSDoug Thompson * The following fields are set at (load) run time, after CPU revision 438cfe40fdbSDoug Thompson * has been determined, since the dct_base and dct_mask registers vary 439cfe40fdbSDoug Thompson * based on revision 440cfe40fdbSDoug Thompson */ 441cfe40fdbSDoug Thompson u32 dcsb_base; /* DCSB base bits */ 442cfe40fdbSDoug Thompson u32 dcsm_mask; /* DCSM mask bits */ 4439d858bb1SBorislav Petkov u32 cs_count; /* num chip selects (== num DCSB registers) */ 444cfe40fdbSDoug Thompson u32 num_dcsm; /* Number of DCSM registers */ 445cfe40fdbSDoug Thompson u32 dcs_mask_notused; /* DCSM notused mask bits */ 446cfe40fdbSDoug Thompson u32 dcs_shift; /* DCSB and DCSM shift value */ 447cfe40fdbSDoug Thompson 448cfe40fdbSDoug Thompson u64 top_mem; /* top of memory below 4GB */ 449cfe40fdbSDoug Thompson u64 top_mem2; /* top of memory above 4GB */ 450cfe40fdbSDoug Thompson 451cfe40fdbSDoug Thompson u32 dram_ctl_select_low; /* DRAM Controller Select Low Reg */ 452cfe40fdbSDoug Thompson u32 dram_ctl_select_high; /* DRAM Controller Select High Reg */ 453cfe40fdbSDoug Thompson u32 online_spare; /* On-Line spare Reg */ 454cfe40fdbSDoug Thompson 455ad6a32e9SBorislav Petkov /* x4 or x8 syndromes in use */ 456ad6a32e9SBorislav Petkov u8 syn_type; 457ad6a32e9SBorislav Petkov 458cfe40fdbSDoug Thompson /* temp storage for when input is received from sysfs */ 459ef44cc4cSBorislav Petkov struct err_regs ctl_error_info; 460cfe40fdbSDoug Thompson 461cfe40fdbSDoug Thompson /* place to store error injection parameters prior to issue */ 462cfe40fdbSDoug Thompson struct error_injection injection; 463cfe40fdbSDoug Thompson 464395ae783SBorislav Petkov /* DCT per-family scrubrate setting */ 465395ae783SBorislav Petkov u32 min_scrubrate; 466395ae783SBorislav Petkov 4670092b20dSBorislav Petkov /* family name this instance is running on */ 4680092b20dSBorislav Petkov const char *ctl_name; 4690092b20dSBorislav Petkov 470*ae7bb7c6SBorislav Petkov }; 471*ae7bb7c6SBorislav Petkov 472*ae7bb7c6SBorislav Petkov /* 473*ae7bb7c6SBorislav Petkov * per-node ECC settings descriptor 474*ae7bb7c6SBorislav Petkov */ 475*ae7bb7c6SBorislav Petkov struct ecc_settings { 476*ae7bb7c6SBorislav Petkov u32 old_nbctl; 477*ae7bb7c6SBorislav Petkov bool nbctl_valid; 478*ae7bb7c6SBorislav Petkov 479cfe40fdbSDoug Thompson struct flags { 480d95cf4deSBorislav Petkov unsigned long nb_mce_enable:1; 481d95cf4deSBorislav Petkov unsigned long nb_ecc_prev:1; 482cfe40fdbSDoug Thompson } flags; 483cfe40fdbSDoug Thompson }; 484cfe40fdbSDoug Thompson 485cfe40fdbSDoug Thompson struct scrubrate { 486cfe40fdbSDoug Thompson u32 scrubval; /* bit pattern for scrub rate */ 487cfe40fdbSDoug Thompson u32 bandwidth; /* bandwidth consumed (bytes/sec) */ 488cfe40fdbSDoug Thompson }; 489cfe40fdbSDoug Thompson 490cfe40fdbSDoug Thompson extern struct scrubrate scrubrates[23]; 491cfe40fdbSDoug Thompson extern const char *tt_msgs[4]; 492cfe40fdbSDoug Thompson extern const char *ll_msgs[4]; 493cfe40fdbSDoug Thompson extern const char *rrrr_msgs[16]; 494cfe40fdbSDoug Thompson extern const char *to_msgs[2]; 495cfe40fdbSDoug Thompson extern const char *pp_msgs[4]; 496cfe40fdbSDoug Thompson extern const char *ii_msgs[4]; 497cfe40fdbSDoug Thompson extern const char *htlink_msgs[8]; 498cfe40fdbSDoug Thompson 4997d6034d3SDoug Thompson #ifdef CONFIG_EDAC_DEBUG 5009cdeb404SBorislav Petkov #define NUM_DBG_ATTRS 5 5017d6034d3SDoug Thompson #else 5027d6034d3SDoug Thompson #define NUM_DBG_ATTRS 0 5037d6034d3SDoug Thompson #endif 5047d6034d3SDoug Thompson 5057d6034d3SDoug Thompson #ifdef CONFIG_EDAC_AMD64_ERROR_INJECTION 5067d6034d3SDoug Thompson #define NUM_INJ_ATTRS 5 5077d6034d3SDoug Thompson #else 5087d6034d3SDoug Thompson #define NUM_INJ_ATTRS 0 5097d6034d3SDoug Thompson #endif 5107d6034d3SDoug Thompson 5117d6034d3SDoug Thompson extern struct mcidev_sysfs_attribute amd64_dbg_attrs[NUM_DBG_ATTRS], 5127d6034d3SDoug Thompson amd64_inj_attrs[NUM_INJ_ATTRS]; 5137d6034d3SDoug Thompson 514cfe40fdbSDoug Thompson /* 515cfe40fdbSDoug Thompson * Each of the PCI Device IDs types have their own set of hardware accessor 516cfe40fdbSDoug Thompson * functions and per device encoding/decoding logic. 517cfe40fdbSDoug Thompson */ 518cfe40fdbSDoug Thompson struct low_ops { 519cfe40fdbSDoug Thompson int (*early_channel_count) (struct amd64_pvt *pvt); 520cfe40fdbSDoug Thompson 521cfe40fdbSDoug Thompson u64 (*get_error_address) (struct mem_ctl_info *mci, 522ef44cc4cSBorislav Petkov struct err_regs *info); 523cfe40fdbSDoug Thompson void (*read_dram_base_limit) (struct amd64_pvt *pvt, int dram); 524cfe40fdbSDoug Thompson void (*read_dram_ctl_register) (struct amd64_pvt *pvt); 525cfe40fdbSDoug Thompson void (*map_sysaddr_to_csrow) (struct mem_ctl_info *mci, 5261433eb99SBorislav Petkov struct err_regs *info, u64 SystemAddr); 5271433eb99SBorislav Petkov int (*dbam_to_cs) (struct amd64_pvt *pvt, int cs_mode); 528cfe40fdbSDoug Thompson }; 529cfe40fdbSDoug Thompson 530cfe40fdbSDoug Thompson struct amd64_family_type { 531cfe40fdbSDoug Thompson const char *ctl_name; 5328d5b5d9cSBorislav Petkov u16 f1_id, f3_id; 533cfe40fdbSDoug Thompson struct low_ops ops; 534cfe40fdbSDoug Thompson }; 535cfe40fdbSDoug Thompson 5366ba5dcdcSBorislav Petkov static inline int amd64_read_pci_cfg_dword(struct pci_dev *pdev, int offset, 5376ba5dcdcSBorislav Petkov u32 *val, const char *func) 5386ba5dcdcSBorislav Petkov { 5396ba5dcdcSBorislav Petkov int err = 0; 5406ba5dcdcSBorislav Petkov 5416ba5dcdcSBorislav Petkov err = pci_read_config_dword(pdev, offset, val); 5426ba5dcdcSBorislav Petkov if (err) 54324f9a7feSBorislav Petkov amd64_warn("%s: error reading F%dx%x.\n", 5446ba5dcdcSBorislav Petkov func, PCI_FUNC(pdev->devfn), offset); 5456ba5dcdcSBorislav Petkov 5466ba5dcdcSBorislav Petkov return err; 5476ba5dcdcSBorislav Petkov } 5486ba5dcdcSBorislav Petkov 5496ba5dcdcSBorislav Petkov #define amd64_read_pci_cfg(pdev, offset, val) \ 5506ba5dcdcSBorislav Petkov amd64_read_pci_cfg_dword(pdev, offset, val, __func__) 5516ba5dcdcSBorislav Petkov 552cfe40fdbSDoug Thompson /* 553cfe40fdbSDoug Thompson * For future CPU versions, verify the following as new 'slow' rates appear and 554cfe40fdbSDoug Thompson * modify the necessary skip values for the supported CPU. 555cfe40fdbSDoug Thompson */ 556cfe40fdbSDoug Thompson #define K8_MIN_SCRUB_RATE_BITS 0x0 557cfe40fdbSDoug Thompson #define F10_MIN_SCRUB_RATE_BITS 0x5 558cfe40fdbSDoug Thompson 559cfe40fdbSDoug Thompson int amd64_get_dram_hole_info(struct mem_ctl_info *mci, u64 *hole_base, 560cfe40fdbSDoug Thompson u64 *hole_offset, u64 *hole_size); 561