Skip to content

Commit 9a97a7f

Browse files
yghannambp3tk0v
authored andcommitted
EDAC/amd64: Rework hw_info_{get,put}
The bulk of system-specific information is gathered at init time with hw_info_get(). This function calls a number of helper functions, and many of these helper functions are split between a modern UMC/DF path and a legacy DCT path. Split hw_info_get() into legacy and modern versions. This creates two separate code paths early on, and legacy and modern helper functions can be called directly in the appropriate code path. Also, simplify hw_info_put() and share it between legacy and modern systems. NULL pointer checks are done in pci_dev_put() and kfree(), so they can be called unconditionally. Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20230127170419.1824692-12-yazen.ghannam@amd.com
1 parent ed623d5 commit 9a97a7f

2 files changed

Lines changed: 34 additions & 45 deletions

File tree

drivers/edac/amd64_edac.c

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,9 +3045,6 @@ static void decode_umc_error(int node_id, struct mce *m)
30453045
static int
30463046
reserve_mc_sibling_devs(struct amd64_pvt *pvt, u16 pci_id1, u16 pci_id2)
30473047
{
3048-
if (pvt->umc)
3049-
return 0;
3050-
30513048
/* Reserve the ADDRESS MAP Device */
30523049
pvt->F1 = pci_get_related_function(pvt->F3->vendor, pci_id1, pvt->F3);
30533050
if (!pvt->F1) {
@@ -3075,16 +3072,6 @@ reserve_mc_sibling_devs(struct amd64_pvt *pvt, u16 pci_id1, u16 pci_id2)
30753072
return 0;
30763073
}
30773074

3078-
static void free_mc_sibling_devs(struct amd64_pvt *pvt)
3079-
{
3080-
if (pvt->umc) {
3081-
return;
3082-
} else {
3083-
pci_dev_put(pvt->F1);
3084-
pci_dev_put(pvt->F2);
3085-
}
3086-
}
3087-
30883075
static void determine_ecc_sym_sz(struct amd64_pvt *pvt)
30893076
{
30903077
pvt->ecc_sym_sz = 4;
@@ -3671,13 +3658,45 @@ static void setup_mci_misc_attrs(struct mem_ctl_info *mci)
36713658
mci->get_sdram_scrub_rate = get_scrub_rate;
36723659
}
36733660

3661+
static int dct_hw_info_get(struct amd64_pvt *pvt)
3662+
{
3663+
int ret = reserve_mc_sibling_devs(pvt, pvt->f1_id, pvt->f2_id);
3664+
3665+
if (ret)
3666+
return ret;
3667+
3668+
read_mc_regs(pvt);
3669+
3670+
return 0;
3671+
}
3672+
3673+
static int umc_hw_info_get(struct amd64_pvt *pvt)
3674+
{
3675+
pvt->umc = kcalloc(pvt->max_mcs, sizeof(struct amd64_umc), GFP_KERNEL);
3676+
if (!pvt->umc)
3677+
return -ENOMEM;
3678+
3679+
read_mc_regs(pvt);
3680+
3681+
return 0;
3682+
}
3683+
3684+
static void hw_info_put(struct amd64_pvt *pvt)
3685+
{
3686+
pci_dev_put(pvt->F1);
3687+
pci_dev_put(pvt->F2);
3688+
kfree(pvt->umc);
3689+
}
3690+
36743691
static struct low_ops umc_ops = {
3692+
.hw_info_get = umc_hw_info_get,
36753693
};
36763694

36773695
/* Use Family 16h versions for defaults and adjust as needed below. */
36783696
static struct low_ops dct_ops = {
36793697
.map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow,
36803698
.dbam_to_cs = f16_dbam_to_chip_select,
3699+
.hw_info_get = dct_hw_info_get,
36813700
};
36823701

36833702
static int per_family_init(struct amd64_pvt *pvt)
@@ -3820,37 +3839,6 @@ static const struct attribute_group *amd64_edac_attr_groups[] = {
38203839
NULL
38213840
};
38223841

3823-
static int hw_info_get(struct amd64_pvt *pvt)
3824-
{
3825-
u16 pci_id1 = 0, pci_id2 = 0;
3826-
int ret;
3827-
3828-
if (pvt->fam >= 0x17) {
3829-
pvt->umc = kcalloc(pvt->max_mcs, sizeof(struct amd64_umc), GFP_KERNEL);
3830-
if (!pvt->umc)
3831-
return -ENOMEM;
3832-
} else {
3833-
pci_id1 = pvt->f1_id;
3834-
pci_id2 = pvt->f2_id;
3835-
}
3836-
3837-
ret = reserve_mc_sibling_devs(pvt, pci_id1, pci_id2);
3838-
if (ret)
3839-
return ret;
3840-
3841-
read_mc_regs(pvt);
3842-
3843-
return 0;
3844-
}
3845-
3846-
static void hw_info_put(struct amd64_pvt *pvt)
3847-
{
3848-
if (pvt->F1)
3849-
free_mc_sibling_devs(pvt);
3850-
3851-
kfree(pvt->umc);
3852-
}
3853-
38543842
static int init_one_instance(struct amd64_pvt *pvt)
38553843
{
38563844
struct mem_ctl_info *mci = NULL;
@@ -3924,7 +3912,7 @@ static int probe_one_instance(unsigned int nid)
39243912
if (ret < 0)
39253913
goto err_enable;
39263914

3927-
ret = hw_info_get(pvt);
3915+
ret = pvt->ops->hw_info_get(pvt);
39283916
if (ret < 0)
39293917
goto err_enable;
39303918

drivers/edac/amd64_edac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ struct low_ops {
466466
struct err_info *err);
467467
int (*dbam_to_cs)(struct amd64_pvt *pvt, u8 dct,
468468
unsigned int cs_mode, int cs_mask_nr);
469+
int (*hw_info_get)(struct amd64_pvt *pvt);
469470
};
470471

471472
int __amd64_read_pci_cfg_dword(struct pci_dev *pdev, int offset,

0 commit comments

Comments
 (0)