mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Borislav Petkov <borislav.petkov@amd.com>
To: <akpm@linux-foundation.org>, <greg@kroah.com>, <mingo@elte.hu>
Cc: <norsk5@yahoo.com>, <tglx@linutronix.de>, <hpa@zytor.com>,
	<mchehab@redhat.com>, <aris@redhat.com>,
	edt@aei.ca, <linux-kernel@vger.kernel.org>,
	Doug Thompson <dougthompson@xmission.com>,
	Borislav Petkov <borislav.petkov@amd.com>
Subject: [PATCH 07/21] amd64_edac: add sys addr to memory controller mapping helpers
Date: Thu, 7 May 2009 15:49:29 +0200	[thread overview]
Message-ID: <1241704183-29223-8-git-send-email-borislav.petkov@amd.com> (raw)
In-Reply-To: <1241704183-29223-1-git-send-email-borislav.petkov@amd.com>

From: Doug Thompson <dougthompson@xmission.com>

Reviewed-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Signed-off-by: Doug Thompson <dougthompson@xmission.com>
Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 drivers/edac/amd64_edac.c |  164 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 164 insertions(+), 0 deletions(-)

diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index df72ecc..44aa102 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -132,3 +132,167 @@ static int amd64_get_scrub_rate(struct mem_ctl_info *mci, u32 *bw)
 	return status;
 }
 
+/*
+ * amd64_map_to_dcs_mask
+ *
+ *	Map from a CSROW entry to the mask entry that operates on it
+ */
+static inline u32 amd64_map_to_dcs_mask(struct amd64_pvt *pvt, int csrow)
+{
+	return csrow >> (pvt->num_dcsm >> 3);
+}
+
+/*
+ * amd64_get_dct_base()
+ *
+ *	getter function to return the 'base' address the i'th CS entry
+ *	of the 'dct' DRAM controller
+ */
+static u32 amd64_get_dct_base(struct amd64_pvt *pvt, int dct, int csrow)
+{
+	if (dct == 0)
+		return pvt->dcsb0[csrow];
+	else
+		return pvt->dcsb1[csrow];
+}
+
+/*
+ * amd64_get_dct_mask()
+ *
+ *	getter function to return the 'mask' address the i'th CS entry.
+ *	This getter function is needed because there different number
+ *	of DCSM registers on Rev E and prior vs Rev F and later
+ */
+static u32 amd64_get_dct_mask(struct amd64_pvt *pvt, int dct, int csrow)
+{
+	if (dct == 0)
+		return pvt->dcsm0[amd64_map_to_dcs_mask(pvt, csrow)];
+	else
+		return pvt->dcsm1[amd64_map_to_dcs_mask(pvt, csrow)];
+}
+
+
+/*
+ * amd64_get_base_and_limit()
+ *
+ * In *base and *limit, pass back the full 40-bit base and limit physical
+ * addresses for the node given by node_id.  This information is obtained from
+ * DRAM Base (section 3.4.4.1) and DRAM Limit (section 3.4.4.2) registers. The
+ * base and limit addresses are of type SysAddr, as defined at the start of
+ * section 3.4.4 (p. 70).  They are the lowest and highest physical addresses
+ * in the address range they represent.
+ */
+static void amd64_get_base_and_limit(struct amd64_pvt *pvt, int node_id,
+			       u64 *base, u64 *limit)
+{
+	*base = pvt->dram_base[node_id];
+	*limit = pvt->dram_limit[node_id];
+}
+
+/*
+ * Return 1 if the SysAddr given by sys_addr matches the base/limit associated
+ * with node_id
+ */
+static int amd64_base_limit_match(struct amd64_pvt *pvt,
+					u64 sys_addr, int node_id)
+{
+	u64 base, limit, addr;
+
+	amd64_get_base_and_limit(pvt, node_id, &base, &limit);
+
+	/* The K8 treats this as a 40-bit value.  However, bits 63-40 will be
+	 * all ones if the most significant implemented address bit is 1.
+	 * Here we discard bits 63-40.  See section 3.4.2 of AMD publication
+	 * 24592: AMD x86-64 Architecture Programmer's Manual Volume 1
+	 * Application Programming.
+	 */
+	addr = sys_addr & 0x000000ffffffffffull;
+
+	return (addr >= base) && (addr <= limit);
+}
+
+/* find_mc_by_sys_addr
+ *
+ *	Attempt to map a SysAddr to a node.
+ *
+ *	On success, return a pointer to the mem_ctl_info structure for
+ *	the node that the SysAddr maps to.
+ *
+ *	On failure, return NULL
+ */
+static struct mem_ctl_info *find_mc_by_sys_addr(struct mem_ctl_info *mci,
+						u64 sys_addr)
+{
+	struct amd64_pvt *pvt;
+	int node_id;
+	u32 intlv_en, bits;
+
+	/*
+	 * Here we use the DRAM Base (section 3.4.4.1) and DRAM Limit (section
+	 * 3.4.4.2) registers to map the SysAddr to a node ID.
+	 */
+	pvt = mci->pvt_info;
+
+	/* The value of this field should be the same for all DRAM Base
+	 * registers.  Therefore we arbitrarily choose to read it from the
+	 * register for node 0.
+	 */
+	intlv_en = pvt->dram_IntlvEn[0];
+
+	if (intlv_en == 0) {
+		debugf2("%s(): node interleaving disabled\n", __func__);
+		for (node_id = 0; ; ) {
+			if (amd64_base_limit_match(pvt, sys_addr, node_id))
+				break;
+
+			if (++node_id >= DRAM_REG_COUNT) {
+				debugf2("%s(): sys_addr 0x%lx "
+					"does not match any node\n", __func__,
+					(unsigned long)sys_addr);
+				return NULL;
+			}
+		}
+
+		goto found;
+	}
+
+	if (unlikely((intlv_en != (0x01 << 8)) &&
+		     (intlv_en != (0x03 << 8)) && (intlv_en != (0x07 << 8)))) {
+		amd64_printk(KERN_WARNING,
+			  "%s(): junk value of 0x%x extracted from IntlvEn "
+			  "field of DRAM Base Register for node 0: This "
+			  "probably indicates a BIOS bug.\n", __func__,
+			  intlv_en);
+		return NULL;
+	}
+
+	debugf2("%s(): node interleaving enabled\n", __func__);
+	bits = (((u32) sys_addr) >> 12) & intlv_en;
+
+	for (node_id = 0; ; ) {
+		if ((pvt->dram_limit[node_id] & intlv_en) == bits)
+			break;	/* intlv_sel field matches */
+
+		if (++node_id >= DRAM_REG_COUNT) {
+			debugf2("%s(): sys_addr 0x%lx does not match any "
+				"node\n", __func__, (unsigned long)sys_addr);
+			return NULL;
+		}
+	}
+
+	/* sanity test for sys_addr */
+	if (unlikely(!amd64_base_limit_match(pvt, sys_addr, node_id))) {
+		amd64_printk(KERN_WARNING,
+			  "%s(): sys_addr 0x%lx falls outside base/limit "
+			  "address range for node %d with node interleaving "
+			  "enabled.\n", __func__, (unsigned long)sys_addr,
+			  node_id);
+		return NULL;
+	}
+
+found:
+	debugf2("%s(): sys_addr 0x%lx matches node %d\n", __func__,
+		(unsigned long)sys_addr, node_id);
+
+	return edac_mc_find(node_id);
+}
-- 
1.6.2.4



  parent reply	other threads:[~2009-05-07 13:52 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-07 13:49 [RFC PATCH 00/21 v3] amd64_edac: EDAC module for AMD64 Borislav Petkov
2009-05-07 13:49 ` [PATCH 01/21] x86: add methods for writing of an MSR on several CPUs Borislav Petkov
2009-05-07 13:49 ` [PATCH 02/21] amd64_edac: add driver header Borislav Petkov
2009-05-07 13:49 ` [PATCH 03/21] amd64_edac: add debugging/testing code Borislav Petkov
2009-05-08 10:01   ` Mauro Carvalho Chehab
2009-05-07 13:49 ` [PATCH 04/21] amd64_edac: add DRAM error injection logic using sysfs Borislav Petkov
2009-05-08 10:01   ` Mauro Carvalho Chehab
2009-05-07 13:49 ` [PATCH 05/21] amd64_edac: add MCA error types Borislav Petkov
2009-05-08 10:01   ` Mauro Carvalho Chehab
2009-05-07 13:49 ` [PATCH 06/21] amd64_edac: add memory scrubber interface Borislav Petkov
2009-05-07 13:49 ` Borislav Petkov [this message]
2009-05-07 13:49 ` [PATCH 08/21] amd64_edac: add functionality to compute the DRAM hole Borislav Petkov
2009-05-07 13:49 ` [PATCH 09/21] amd64_edac: add DRAM address type conversion facilities Borislav Petkov
2009-05-07 13:49 ` [PATCH 10/21] amd64_edac: add helper to dump relevant registers Borislav Petkov
2009-05-07 13:49 ` [PATCH 11/21] amd64_edac: assign DRAM chip select base and mask in a family-specific way Borislav Petkov
2009-05-07 13:49 ` [PATCH 12/21] amd64_edac: add k8-specific methods Borislav Petkov
2009-05-07 13:49 ` [PATCH 13/21] amd64_edac: add F10h-and-later methods-p1 Borislav Petkov
2009-05-07 13:49 ` [PATCH 14/21] amd64_edac: add F10h-and-later methods-p2 Borislav Petkov
2009-05-07 13:49 ` [PATCH 15/21] amd64_edac: add F10h-and-later methods-p3 Borislav Petkov
2009-05-08  9:39   ` Mauro Carvalho Chehab
2009-05-07 13:49 ` [PATCH 16/21] amd64_edac: add per-family descriptors Borislav Petkov
2009-05-07 13:49 ` [PATCH 17/21] amd64_edac: add ECC chipkill syndrome mapping table Borislav Petkov
2009-05-08  9:40   ` Mauro Carvalho Chehab
2009-05-07 13:49 ` [PATCH 18/21] amd64_edac: add error decoding logic Borislav Petkov
2009-05-07 13:49 ` [PATCH 19/21] amd64_edac: add EDAC core-related initializers Borislav Petkov
2009-05-07 13:49 ` [PATCH 20/21] amd64_edac: add ECC reporting initializers Borislav Petkov
2009-05-07 22:00   ` Ingo Molnar
2009-05-07 13:49 ` [PATCH 21/21] amd64_edac: add module registration routines Borislav Petkov
2009-05-07 21:58   ` Ingo Molnar
2009-05-14 17:52     ` Borislav Petkov
2009-05-14 18:43       ` Doug Thompson
2009-05-08 10:00   ` Mauro Carvalho Chehab
2009-05-07 14:27 ` [RFC PATCH 00/21 v3] amd64_edac: EDAC module for AMD64 Ingo Molnar
2009-05-07 14:38   ` Borislav Petkov
2009-05-07 20:52     ` Andrew Morton
2009-05-07 21:18       ` Ingo Molnar
2009-05-08 10:07         ` Borislav Petkov
2009-05-08 10:32           ` Mauro Carvalho Chehab
2009-05-08 10:46           ` Ingo Molnar
2009-05-07 20:51 ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1241704183-29223-8-git-send-email-borislav.petkov@amd.com \
    --to=borislav.petkov@amd.com \
    --cc=akpm@linux-foundation.org \
    --cc=aris@redhat.com \
    --cc=dougthompson@xmission.com \
    --cc=edt@aei.ca \
    --cc=greg@kroah.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@redhat.com \
    --cc=mingo@elte.hu \
    --cc=norsk5@yahoo.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome