Skip to content

Commit 7981a28

Browse files
Aravind Gopalakrishnansuryasaimadhu
authored andcommitted
amd64_edac: Modify usage of amd64_read_dct_pci_cfg()
Rationale behind this change: - F2x1xx addresses were stopped from being mapped explicitly to DCT1 from F15h (OR) onwards. They use _dct[0:1] mechanism to access the registers. So we should move away from using address ranges to select DCT for these families. - On newer processors, the address ranges used to indicate DCT1 (0x140, 0x1a0) have different meanings than what is assumed currently. Changes introduced: - amd64_read_dct_pci_cfg() now takes in dct value and uses it for 'selecting the dct' - Update usage of the function. Keep in mind that different families have specific handling requirements - Remove [k8|f10]_read_dct_pci_cfg() as they don't do much different from amd64_read_pci_cfg() - Move the k8 specific check to amd64_read_pci_cfg - Remove f15_read_dct_pci_cfg() and move logic to amd64_read_dct_pci_cfg() - Remove now needless .read_dct_pci_cfg Testing: - Tested on Fam 10h; Fam15h Models: 00h, 30h; Fam16h using 'EDAC_DEBUG' and mce_amd_inj - driver obtains info from F2x registers and caches it in pvt structures correctly - ECC decoding works fine Signed-off-by: Aravind Gopalakrishnan <aravind.gopalakrishnan@amd.com> Link: http://lkml.kernel.org/r/1410799058-3149-1-git-send-email-aravind.gopalakrishnan@amd.com Signed-off-by: Borislav Petkov <bp@suse.de>
1 parent 2d34056 commit 7981a28

2 files changed

Lines changed: 80 additions & 71 deletions

File tree

‎drivers/edac/amd64_edac.c‎

Lines changed: 80 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -86,62 +86,74 @@ int __amd64_write_pci_cfg_dword(struct pci_dev *pdev, int offset,
8686
return err;
8787
}
8888

89+
/*
90+
* Select DCT to which PCI cfg accesses are routed
91+
*/
92+
static void f15h_select_dct(struct amd64_pvt *pvt, u8 dct)
93+
{
94+
u32 reg = 0;
95+
96+
amd64_read_pci_cfg(pvt->F1, DCT_CFG_SEL, &reg);
97+
reg &= (pvt->model == 0x30) ? ~3 : ~1;
98+
reg |= dct;
99+
amd64_write_pci_cfg(pvt->F1, DCT_CFG_SEL, reg);
100+
}
101+
89102
/*
90103
*
91104
* Depending on the family, F2 DCT reads need special handling:
92105
*
93-
* K8: has a single DCT only
106+
* K8: has a single DCT only and no address offsets >= 0x100
94107
*
95108
* F10h: each DCT has its own set of regs
96109
* DCT0 -> F2x040..
97110
* DCT1 -> F2x140..
98111
*
99-
* F15h: we select which DCT we access using F1x10C[DctCfgSel]
100-
*
101112
* F16h: has only 1 DCT
113+
*
114+
* F15h: we select which DCT we access using F1x10C[DctCfgSel]
102115
*/
103-
static int k8_read_dct_pci_cfg(struct amd64_pvt *pvt, int addr, u32 *val,
104-
const char *func)
116+
static inline int amd64_read_dct_pci_cfg(struct amd64_pvt *pvt, u8 dct,
117+
int offset, u32 *val)
105118
{
106-
if (addr >= 0x100)
107-
return -EINVAL;
108-
109-
return __amd64_read_pci_cfg_dword(pvt->F2, addr, val, func);
110-
}
119+
switch (pvt->fam) {
120+
case 0xf:
121+
if (dct || offset >= 0x100)
122+
return -EINVAL;
123+
break;
111124

112-
static int f10_read_dct_pci_cfg(struct amd64_pvt *pvt, int addr, u32 *val,
113-
const char *func)
114-
{
115-
return __amd64_read_pci_cfg_dword(pvt->F2, addr, val, func);
116-
}
125+
case 0x10:
126+
if (dct) {
127+
/*
128+
* Note: If ganging is enabled, barring the regs
129+
* F2x[1,0]98 and F2x[1,0]9C; reads reads to F2x1xx
130+
* return 0. (cf. Section 2.8.1 F10h BKDG)
131+
*/
132+
if (dct_ganging_enabled(pvt))
133+
return 0;
117134

118-
/*
119-
* Select DCT to which PCI cfg accesses are routed
120-
*/
121-
static void f15h_select_dct(struct amd64_pvt *pvt, u8 dct)
122-
{
123-
u32 reg = 0;
135+
offset += 0x100;
136+
}
137+
break;
124138

125-
amd64_read_pci_cfg(pvt->F1, DCT_CFG_SEL, &reg);
126-
reg &= (pvt->model >= 0x30) ? ~3 : ~1;
127-
reg |= dct;
128-
amd64_write_pci_cfg(pvt->F1, DCT_CFG_SEL, reg);
129-
}
139+
case 0x15:
140+
/*
141+
* F15h: F2x1xx addresses do not map explicitly to DCT1.
142+
* We should select which DCT we access using F1x10C[DctCfgSel]
143+
*/
144+
dct = (dct && pvt->model == 0x30) ? 3 : dct;
145+
f15h_select_dct(pvt, dct);
146+
break;
130147

131-
static int f15_read_dct_pci_cfg(struct amd64_pvt *pvt, int addr, u32 *val,
132-
const char *func)
133-
{
134-
u8 dct = 0;
148+
case 0x16:
149+
if (dct)
150+
return -EINVAL;
151+
break;
135152

136-
/* For F15 M30h, the second dct is DCT 3, refer to BKDG Section 2.10 */
137-
if (addr >= 0x140 && addr <= 0x1a0) {
138-
dct = (pvt->model >= 0x30) ? 3 : 1;
139-
addr -= 0x100;
153+
default:
154+
break;
140155
}
141-
142-
f15h_select_dct(pvt, dct);
143-
144-
return __amd64_read_pci_cfg_dword(pvt->F2, addr, val, func);
156+
return amd64_read_pci_cfg(pvt->F2, offset, val);
145157
}
146158

147159
/*
@@ -768,16 +780,17 @@ static void read_dct_base_mask(struct amd64_pvt *pvt)
768780
u32 *base0 = &pvt->csels[0].csbases[cs];
769781
u32 *base1 = &pvt->csels[1].csbases[cs];
770782

771-
if (!amd64_read_dct_pci_cfg(pvt, reg0, base0))
783+
if (!amd64_read_dct_pci_cfg(pvt, 0, reg0, base0))
772784
edac_dbg(0, " DCSB0[%d]=0x%08x reg: F2x%x\n",
773785
cs, *base0, reg0);
774786

775-
if (pvt->fam == 0xf || dct_ganging_enabled(pvt))
787+
if (pvt->fam == 0xf)
776788
continue;
777789

778-
if (!amd64_read_dct_pci_cfg(pvt, reg1, base1))
790+
if (!amd64_read_dct_pci_cfg(pvt, 1, reg0, base1))
779791
edac_dbg(0, " DCSB1[%d]=0x%08x reg: F2x%x\n",
780-
cs, *base1, reg1);
792+
cs, *base1, (pvt->fam == 0x10) ? reg1
793+
: reg0);
781794
}
782795

783796
for_each_chip_select_mask(cs, 0, pvt) {
@@ -786,16 +799,17 @@ static void read_dct_base_mask(struct amd64_pvt *pvt)
786799
u32 *mask0 = &pvt->csels[0].csmasks[cs];
787800
u32 *mask1 = &pvt->csels[1].csmasks[cs];
788801

789-
if (!amd64_read_dct_pci_cfg(pvt, reg0, mask0))
802+
if (!amd64_read_dct_pci_cfg(pvt, 0, reg0, mask0))
790803
edac_dbg(0, " DCSM0[%d]=0x%08x reg: F2x%x\n",
791804
cs, *mask0, reg0);
792805

793-
if (pvt->fam == 0xf || dct_ganging_enabled(pvt))
806+
if (pvt->fam == 0xf)
794807
continue;
795808

796-
if (!amd64_read_dct_pci_cfg(pvt, reg1, mask1))
809+
if (!amd64_read_dct_pci_cfg(pvt, 1, reg0, mask1))
797810
edac_dbg(0, " DCSM1[%d]=0x%08x reg: F2x%x\n",
798-
cs, *mask1, reg1);
811+
cs, *mask1, (pvt->fam == 0x10) ? reg1
812+
: reg0);
799813
}
800814
}
801815

@@ -1198,7 +1212,7 @@ static void read_dram_ctl_register(struct amd64_pvt *pvt)
11981212
if (pvt->fam == 0xf)
11991213
return;
12001214

1201-
if (!amd64_read_dct_pci_cfg(pvt, DCT_SEL_LO, &pvt->dct_sel_lo)) {
1215+
if (!amd64_read_pci_cfg(pvt->F2, DCT_SEL_LO, &pvt->dct_sel_lo)) {
12021216
edac_dbg(0, "F2x110 (DCTSelLow): 0x%08x, High range addrs at: 0x%x\n",
12031217
pvt->dct_sel_lo, dct_sel_baseaddr(pvt));
12041218

@@ -1219,7 +1233,7 @@ static void read_dram_ctl_register(struct amd64_pvt *pvt)
12191233
dct_sel_interleave_addr(pvt));
12201234
}
12211235

1222-
amd64_read_dct_pci_cfg(pvt, DCT_SEL_HI, &pvt->dct_sel_hi);
1236+
amd64_read_pci_cfg(pvt->F2, DCT_SEL_HI, &pvt->dct_sel_hi);
12231237
}
12241238

12251239
/*
@@ -1430,7 +1444,7 @@ static u64 f1x_swap_interleaved_region(struct amd64_pvt *pvt, u64 sys_addr)
14301444
return sys_addr;
14311445
}
14321446

1433-
amd64_read_dct_pci_cfg(pvt, SWAP_INTLV_REG, &swap_reg);
1447+
amd64_read_pci_cfg(pvt->F2, SWAP_INTLV_REG, &swap_reg);
14341448

14351449
if (!(swap_reg & 0x1))
14361450
return sys_addr;
@@ -1723,10 +1737,16 @@ static void debug_display_dimm_sizes(struct amd64_pvt *pvt, u8 ctrl)
17231737
WARN_ON(ctrl != 0);
17241738
}
17251739

1726-
dbam = (ctrl && !dct_ganging_enabled(pvt)) ? pvt->dbam1 : pvt->dbam0;
1727-
dcsb = (ctrl && !dct_ganging_enabled(pvt)) ? pvt->csels[1].csbases
1728-
: pvt->csels[0].csbases;
1729-
1740+
if (pvt->fam == 0x10) {
1741+
dbam = (ctrl && !dct_ganging_enabled(pvt)) ? pvt->dbam1
1742+
: pvt->dbam0;
1743+
dcsb = (ctrl && !dct_ganging_enabled(pvt)) ?
1744+
pvt->csels[1].csbases :
1745+
pvt->csels[0].csbases;
1746+
} else if (ctrl) {
1747+
dbam = pvt->dbam0;
1748+
dcsb = pvt->csels[1].csbases;
1749+
}
17301750
edac_dbg(1, "F2x%d80 (DRAM Bank Address Mapping): 0x%08x\n",
17311751
ctrl, dbam);
17321752

@@ -1760,7 +1780,6 @@ static struct amd64_family_type family_types[] = {
17601780
.early_channel_count = k8_early_channel_count,
17611781
.map_sysaddr_to_csrow = k8_map_sysaddr_to_csrow,
17621782
.dbam_to_cs = k8_dbam_to_chip_select,
1763-
.read_dct_pci_cfg = k8_read_dct_pci_cfg,
17641783
}
17651784
},
17661785
[F10_CPUS] = {
@@ -1771,7 +1790,6 @@ static struct amd64_family_type family_types[] = {
17711790
.early_channel_count = f1x_early_channel_count,
17721791
.map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow,
17731792
.dbam_to_cs = f10_dbam_to_chip_select,
1774-
.read_dct_pci_cfg = f10_read_dct_pci_cfg,
17751793
}
17761794
},
17771795
[F15_CPUS] = {
@@ -1782,7 +1800,6 @@ static struct amd64_family_type family_types[] = {
17821800
.early_channel_count = f1x_early_channel_count,
17831801
.map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow,
17841802
.dbam_to_cs = f15_dbam_to_chip_select,
1785-
.read_dct_pci_cfg = f15_read_dct_pci_cfg,
17861803
}
17871804
},
17881805
[F15_M30H_CPUS] = {
@@ -1793,7 +1810,6 @@ static struct amd64_family_type family_types[] = {
17931810
.early_channel_count = f1x_early_channel_count,
17941811
.map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow,
17951812
.dbam_to_cs = f16_dbam_to_chip_select,
1796-
.read_dct_pci_cfg = f15_read_dct_pci_cfg,
17971813
}
17981814
},
17991815
[F16_CPUS] = {
@@ -1804,7 +1820,6 @@ static struct amd64_family_type family_types[] = {
18041820
.early_channel_count = f1x_early_channel_count,
18051821
.map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow,
18061822
.dbam_to_cs = f16_dbam_to_chip_select,
1807-
.read_dct_pci_cfg = f10_read_dct_pci_cfg,
18081823
}
18091824
},
18101825
[F16_M30H_CPUS] = {
@@ -1815,7 +1830,6 @@ static struct amd64_family_type family_types[] = {
18151830
.early_channel_count = f1x_early_channel_count,
18161831
.map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow,
18171832
.dbam_to_cs = f16_dbam_to_chip_select,
1818-
.read_dct_pci_cfg = f10_read_dct_pci_cfg,
18191833
}
18201834
},
18211835
};
@@ -2148,25 +2162,25 @@ static void read_mc_regs(struct amd64_pvt *pvt)
21482162
read_dct_base_mask(pvt);
21492163

21502164
amd64_read_pci_cfg(pvt->F1, DHAR, &pvt->dhar);
2151-
amd64_read_dct_pci_cfg(pvt, DBAM0, &pvt->dbam0);
2165+
amd64_read_dct_pci_cfg(pvt, 0, DBAM0, &pvt->dbam0);
21522166

21532167
amd64_read_pci_cfg(pvt->F3, F10_ONLINE_SPARE, &pvt->online_spare);
21542168

2155-
amd64_read_dct_pci_cfg(pvt, DCLR0, &pvt->dclr0);
2156-
amd64_read_dct_pci_cfg(pvt, DCHR0, &pvt->dchr0);
2169+
amd64_read_dct_pci_cfg(pvt, 0, DCLR0, &pvt->dclr0);
2170+
amd64_read_dct_pci_cfg(pvt, 0, DCHR0, &pvt->dchr0);
21572171

21582172
if (!dct_ganging_enabled(pvt)) {
2159-
amd64_read_dct_pci_cfg(pvt, DCLR1, &pvt->dclr1);
2160-
amd64_read_dct_pci_cfg(pvt, DCHR1, &pvt->dchr1);
2173+
amd64_read_dct_pci_cfg(pvt, 1, DCLR0, &pvt->dclr1);
2174+
amd64_read_dct_pci_cfg(pvt, 1, DCHR0, &pvt->dchr1);
21612175
}
21622176

21632177
pvt->ecc_sym_sz = 4;
21642178

21652179
if (pvt->fam >= 0x10) {
21662180
amd64_read_pci_cfg(pvt->F3, EXT_NB_MCA_CFG, &tmp);
2181+
/* F16h has only DCT0, so no need to read dbam1 */
21672182
if (pvt->fam != 0x16)
2168-
/* F16h has only DCT0 */
2169-
amd64_read_dct_pci_cfg(pvt, DBAM1, &pvt->dbam1);
2183+
amd64_read_dct_pci_cfg(pvt, 1, DBAM0, &pvt->dbam1);
21702184

21712185
/* F10h, revD and later can do x8 ECC too */
21722186
if ((pvt->fam > 0x10 || pvt->model > 7) && tmp & BIT(25))

‎drivers/edac/amd64_edac.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,6 @@ struct low_ops {
481481
void (*map_sysaddr_to_csrow) (struct mem_ctl_info *mci, u64 sys_addr,
482482
struct err_info *);
483483
int (*dbam_to_cs) (struct amd64_pvt *pvt, u8 dct, unsigned cs_mode);
484-
int (*read_dct_pci_cfg) (struct amd64_pvt *pvt, int offset,
485-
u32 *val, const char *func);
486484
};
487485

488486
struct amd64_family_type {
@@ -502,9 +500,6 @@ int __amd64_write_pci_cfg_dword(struct pci_dev *pdev, int offset,
502500
#define amd64_write_pci_cfg(pdev, offset, val) \
503501
__amd64_write_pci_cfg_dword(pdev, offset, val, __func__)
504502

505-
#define amd64_read_dct_pci_cfg(pvt, offset, val) \
506-
pvt->ops->read_dct_pci_cfg(pvt, offset, val, __func__)
507-
508503
int amd64_get_dram_hole_info(struct mem_ctl_info *mci, u64 *hole_base,
509504
u64 *hole_offset, u64 *hole_size);
510505

0 commit comments

Comments
 (0)