65 #include <linux/module.h>
66 #include <linux/ctype.h>
68 #include <linux/pci.h>
70 #include <linux/slab.h>
77 #define amd64_debug(fmt, arg...) \
78 edac_printk(KERN_DEBUG, "amd64", fmt, ##arg)
80 #define amd64_info(fmt, arg...) \
81 edac_printk(KERN_INFO, "amd64", fmt, ##arg)
83 #define amd64_notice(fmt, arg...) \
84 edac_printk(KERN_NOTICE, "amd64", fmt, ##arg)
86 #define amd64_warn(fmt, arg...) \
87 edac_printk(KERN_WARNING, "amd64", fmt, ##arg)
89 #define amd64_err(fmt, arg...) \
90 edac_printk(KERN_ERR, "amd64", fmt, ##arg)
92 #define amd64_mc_warn(mci, fmt, arg...) \
93 edac_mc_chipset_printk(mci, KERN_WARNING, "amd64", fmt, ##arg)
95 #define amd64_mc_err(mci, fmt, arg...) \
96 edac_mc_chipset_printk(mci, KERN_ERR, "amd64", fmt, ##arg)
147 #define EDAC_AMD64_VERSION "3.4.0"
148 #define EDAC_MOD_STR "amd64_edac"
156 #define NUM_CHIPSELECTS 8
157 #define DRAM_RANGES 8
168 #define GENMASK(lo, hi) (((1ULL << ((hi) - (lo) + 1)) - 1) << (lo))
173 #define PCI_DEVICE_ID_AMD_15H_NB_F1 0x1601
174 #define PCI_DEVICE_ID_AMD_15H_NB_F2 0x1602
180 #define DRAM_BASE_LO 0x40
181 #define DRAM_LIMIT_LO 0x44
183 #define dram_intlv_en(pvt, i) ((u8)((pvt->ranges[i].base.lo >> 8) & 0x7))
184 #define dram_rw(pvt, i) ((u8)(pvt->ranges[i].base.lo & 0x3))
185 #define dram_intlv_sel(pvt, i) ((u8)((pvt->ranges[i].lim.lo >> 8) & 0x7))
186 #define dram_dst_node(pvt, i) ((u8)(pvt->ranges[i].lim.lo & 0x7))
189 #define dhar_valid(pvt) ((pvt)->dhar & BIT(0))
190 #define dhar_mem_hoist_valid(pvt) ((pvt)->dhar & BIT(1))
191 #define dhar_base(pvt) ((pvt)->dhar & 0xff000000)
192 #define k8_dhar_offset(pvt) (((pvt)->dhar & 0x0000ff00) << 16)
195 #define f10_dhar_offset(pvt) (((pvt)->dhar & 0x0000ff80) << 16)
197 #define DCT_CFG_SEL 0x10C
199 #define DRAM_LOCAL_NODE_BASE 0x120
200 #define DRAM_LOCAL_NODE_LIM 0x124
202 #define DRAM_BASE_HI 0x140
203 #define DRAM_LIMIT_HI 0x144
211 #define DCSB_CS_ENABLE BIT(0)
216 #define csrow_enabled(i, dct, pvt) ((pvt)->csels[(dct)].csbases[(i)] & DCSB_CS_ENABLE)
222 #define DBAM_DIMM(i, reg) ((((reg) >> (4*i))) & 0xF)
224 #define DBAM_MAX_VALUE 11
228 #define REVE_WIDTH_128 BIT(16)
229 #define WIDTH_128 BIT(11)
233 #define DDR3_MODE BIT(8)
235 #define DCT_SEL_LO 0x110
236 #define dct_sel_baseaddr(pvt) ((pvt)->dct_sel_lo & 0xFFFFF800)
237 #define dct_sel_interleave_addr(pvt) (((pvt)->dct_sel_lo >> 6) & 0x3)
238 #define dct_high_range_enabled(pvt) ((pvt)->dct_sel_lo & BIT(0))
239 #define dct_interleave_enabled(pvt) ((pvt)->dct_sel_lo & BIT(2))
241 #define dct_ganging_enabled(pvt) ((boot_cpu_data.x86 == 0x10) && ((pvt)->dct_sel_lo & BIT(4)))
243 #define dct_data_intlv_enabled(pvt) ((pvt)->dct_sel_lo & BIT(5))
244 #define dct_memory_cleared(pvt) ((pvt)->dct_sel_lo & BIT(10))
246 #define SWAP_INTLV_REG 0x10c
248 #define DCT_SEL_HI 0x114
256 #define NBCFG_CHIPKILL BIT(23)
257 #define NBCFG_ECC_ENABLE BIT(22)
260 #define F10_NBSL_EXT_ERR_ECC 0x8
261 #define NBSL_PP_OBS 0x2
265 #define F10_ONLINE_SPARE 0xB0
266 #define online_spare_swap_done(pvt, c) (((pvt)->online_spare >> (1 + 2 * (c))) & 0x1)
267 #define online_spare_bad_dramcs(pvt, c) (((pvt)->online_spare >> (4 + 4 * (c))) & 0x7)
269 #define F10_NB_ARRAY_ADDR 0xB8
270 #define F10_NB_ARRAY_DRAM_ECC BIT(31)
273 #define SET_NB_ARRAY_ADDRESS(section) (((section) & 0x3) << 1)
275 #define F10_NB_ARRAY_DATA 0xBC
276 #define SET_NB_DRAM_INJECTION_WRITE(word, bits) \
277 (BIT(((word) & 0xF) + 20) | \
279 #define SET_NB_DRAM_INJECTION_READ(word, bits) \
280 (BIT(((word) & 0xF) + 20) | \
284 #define NBCAP_CHIPKILL BIT(4)
285 #define NBCAP_SECDED BIT(3)
286 #define NBCAP_DCT_DUAL BIT(0)
288 #define EXT_NB_MCA_CFG 0x180
291 #define MSR_MCGCTL_NBE BIT(4)
294 static inline u8 get_node_id(
struct pci_dev *pdev)
377 static inline u64 get_dram_base(
struct amd64_pvt *pvt,
unsigned i)
387 static inline u64 get_dram_limit(
struct amd64_pvt *pvt,
unsigned i)
389 u64 lim = (((
u64)pvt->
ranges[i].lim.lo & 0xffff0000) << 8) | 0x00ffffff;
394 return (((
u64)pvt->
ranges[
i].lim.hi & 0x000000ff) << 40) | lim;
399 return ((status >> 47) & 0xff) | ((status >> 16) & 0xff00);
415 #ifdef CONFIG_EDAC_DEBUG
429 #ifdef CONFIG_EDAC_AMD64_ERROR_INJECTION
465 #define amd64_read_pci_cfg(pdev, offset, val) \
466 __amd64_read_pci_cfg_dword(pdev, offset, val, __func__)
468 #define amd64_write_pci_cfg(pdev, offset, val) \
469 __amd64_write_pci_cfg_dword(pdev, offset, val, __func__)
471 #define amd64_read_dct_pci_cfg(pvt, offset, val) \
472 pvt->ops->read_dct_pci_cfg(pvt, offset, val, __func__)
475 u64 *hole_offset,
u64 *hole_size);
477 #define to_mci(k) container_of(k, struct mem_ctl_info, dev)