From: thockin@hockin.org
To: Andi Kleen <ak@suse.de>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
Alan Cox <alan@lxorguk.ukuu.org.uk>, Gerd Knorr <kraxel@suse.de>,
Linus Torvalds <torvalds@osdl.org>, Dave Jones <davej@redhat.com>,
Zachary Amsden <zach@vmware.com>, Pavel Machek <pavel@ucw.cz>,
Andrew Morton <akpm@osdl.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
"H. Peter Anvin" <hpa@zytor.com>,
Zwane Mwaikambo <zwane@arm.linux.org.uk>,
Pratap Subrahmanyam <pratap@vmware.com>,
Christopher Li <chrisl@vmware.com>, Ingo Molnar <mingo@elte.hu>
Subject: Re: [patch] SMP alternatives
Date: Thu, 24 Nov 2005 11:44:59 -0800 [thread overview]
Message-ID: <20051124194459.GA4069@hockin.org> (raw)
In-Reply-To: <20051124192953.GT20775@brahms.suse.de>
On Thu, Nov 24, 2005 at 08:29:53PM +0100, Andi Kleen wrote:
> > We implemented AMD's reference algorithm, and made it work in the presence
> > of a hardware IO hole. It seems to work beautifully, but the last step is
> > turning a (node:chip-select) into a (node:dimm). Simple boards will use
> > simple mappings, but we can't know that without board specific info.
> > Especially with quad-rank DIMMs. :)
>
> If you get something working it would be good if you could share the code
> (even if it still needs to be tweaked)
The below code works for us. Note that I did not implement the
node-interleaving parts of the AMD algorithm. If that matters, it should
be simple enough to do. The BKDG has good pseudo-code. The only thing it
gets absolutely wrong is the IO hole.
Let me know if you see any problems here. This is a userspace tool, but
should be trivial to adapt.
#include <stdio.h>
#include <stdlib.h>
#include "pci.h"
#define MAX_NODES 8
#define MAX_CS 8
#define NODE_DEV(n) (24+(n))
#define FOUR_GIG 0x01000000 // shifted to hold address[39..8]
static char *progname;
static void
usage(void)
{
fprintf(stderr, "usage: %s <address>\n", progname);
}
/*
* Map a CS to a pair of DIMM slots (for 128 bit operation). This mapping
* is board-specific, and has the potential to be very ugly.
*/
static int cs_to_pair[MAX_CS][2] = {
{ 0, 1 }, { 0, 1 },
{ 2, 3 }, { 2, 3 },
{ 4, 5 }, { 4, 5 },
{ 6, 7 }, { 6, 7 },
};
int
main(int argc, char *argv[])
{
unsigned long long raw_addr;
uint32_t address;
char *endp;
int node;
progname = argv[0];
if (argc != 2) {
usage();
exit(1);
}
raw_addr = strtoull(argv[1], &endp, 0);
if (endp == argv[1]) {
usage();
exit(2);
}
/*
* The address space is 40 bits (for now). We want to use 32 bit
* values, so we convert the input address to hold address[39..8].
* We'll use this format everywhere. This loses the
* low-order bits, so we keep a raw copy around.
*/
address = (raw_addr & 0xffffffffff) >> 8;
/* find the node that holds this address */
for (node = 0; node < MAX_NODES; node++) {
int pci_dev;
uint32_t tmp;
int dram_en;
uint32_t dram_base;
uint32_t dram_limit;
int hole_en;
uint32_t hole_base;
uint32_t hole_size;
int cs;
/*
* The DRAM map and IO hole info are in function 1 of each
* node.
*/
pci_dev = pci_open(0, NODE_DEV(node), 1);
if (pci_dev < 0) {
/* node does not exist */
break;
}
/*
* DRAM_BASE and DRAM_LIMIT already hold address[39..8].
*/
tmp = pci_read32(pci_dev, 0x40+(node*8));
dram_en = tmp & 0x3;
dram_base = tmp & 0xffff0000;
tmp = pci_read32(pci_dev, 0x44+(node*8));
dram_limit = tmp | 0x0000ffff;
/*
* HOLE_BASE holds address[35..4], so we convert it to hold
* address[39..8].
*/
tmp = pci_read32(pci_dev, 0xf0);
hole_en = tmp & 0x1;
hole_base = (tmp & 0xff000000) >> 8;
hole_size = FOUR_GIG - hole_base;
pci_close(pci_dev);
if (!dram_en) {
/* no DRAM here */
continue;
}
if (address > dram_limit) {
/* keep looking */
continue;
}
/*
* The address must be on this node.
*/
/* is the address in the IO hole? */
if (hole_en && address >= hole_base && address < FOUR_GIG) {
/* no DRAM in the IO hole */
break;
}
/* is the address >= 4GB on a node with a hole? */
if (hole_en && address >= FOUR_GIG) {
/* adjust address for the IO hole */
address -= hole_size;
}
/* adjust address to be node-relative */
address -= dram_base;
/* store addr[35..4] */
address <<= 4;
/* The chip-select map is in function 2 of each node. */
pci_dev = pci_open(0, NODE_DEV(node), 2);
/* find the chip-select that has this address */
for (cs = 0; cs < MAX_CS; cs++) {
uint32_t cs_base;
uint32_t cs_mask;
/*
* CS_BASE and CS_MASK hold address[35..0], so we
* convert them to hold address[39..8].
*/
tmp = pci_read32(pci_dev, 0x40+(cs*4));
if ((tmp & 0x1) == 0) {
/* this CS is not enabled */
continue;
}
cs_base = tmp & 0xffe0fe00;
tmp = pci_read32(pci_dev, 0x60+(cs*4));
cs_mask = (tmp | 0x001f01ff) & 0x3fffffff;
/* this should handle interleaving, too */
if ((address & ~cs_mask) == (cs_base & ~cs_mask)) {
int *pair = cs_to_pair[cs];
int dimm;
/* which DIMM is this address on? */
if ((raw_addr & (1<<3)) == 0) {
dimm = pair[0];
} else {
dimm = pair[1];
}
printf("node %d, CS %d, DIMM %d\n",
node, cs, dimm);
break;
}
}
pci_close(pci_dev);
break;
}
return 0;
}
next prev parent reply other threads:[~2005-11-24 19:43 UTC|newest]
Thread overview: 163+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-10 0:32 [PATCH 1/10] Cr4 is valid on some 486s Zachary Amsden
2005-11-11 10:36 ` Pavel Machek
2005-11-11 17:49 ` H. Peter Anvin
2005-11-11 18:00 ` Maciej W. Rozycki
2005-11-11 19:36 ` Zachary Amsden
2005-11-11 19:58 ` Linus Torvalds
2005-11-11 20:14 ` Zachary Amsden
2005-11-11 20:22 ` Linus Torvalds
2005-11-13 7:42 ` Dave Jones
2005-11-13 10:59 ` Andi Kleen
2005-11-13 17:26 ` Alan Cox
2005-11-13 17:09 ` Eric W. Biederman
2005-11-13 19:00 ` Andi Kleen
2005-11-13 19:07 ` Eric W. Biederman
2005-11-13 19:41 ` Alan Cox
2005-11-13 19:36 ` Linus Torvalds
2005-11-13 21:32 ` Alan Cox
2005-11-14 7:46 ` Arjan van de Ven
2005-11-13 19:56 ` H. Peter Anvin
2005-11-13 19:24 ` Linus Torvalds
2005-11-13 20:29 ` Linus Torvalds
2005-11-14 15:06 ` Gerd Knorr
2005-11-14 19:25 ` Linus Torvalds
2005-11-14 19:46 ` Zachary Amsden
2005-11-14 19:52 ` Arjan van de Ven
2005-11-14 20:34 ` Zachary Amsden
2005-11-14 20:52 ` Arjan van de Ven
2005-11-15 14:12 ` Gerd Knorr
2005-11-15 16:01 ` Gerd Knorr
2005-11-15 16:04 ` Zachary Amsden
2005-11-15 16:06 ` Arjan van de Ven
2005-11-15 16:10 ` Dave Jones
2005-11-15 16:14 ` H. Peter Anvin
2005-11-15 16:19 ` Dave Jones
2005-11-15 16:25 ` Arjan van de Ven
2005-11-15 16:34 ` Zachary Amsden
2005-11-15 16:28 ` H. Peter Anvin
2005-11-15 16:24 ` Zachary Amsden
2005-11-15 16:52 ` Linus Torvalds
2005-11-15 16:16 ` Gerd Knorr
2005-11-15 16:08 ` Roland Dreier
2005-11-16 9:58 ` Gerd Knorr
2005-11-15 16:12 ` Linus Torvalds
2005-11-15 16:16 ` Dave Jones
2005-11-15 16:27 ` Gerd Knorr
2005-11-16 16:12 ` [RFC] SMP alternatives Gerd Knorr
2005-11-22 17:48 ` [patch] " Gerd Knorr
2005-11-22 18:01 ` Pavel Machek
2005-11-23 15:12 ` Vincent Hanquez
2005-11-23 19:17 ` Andi Kleen
2005-11-23 15:29 ` Gerd Knorr
2005-11-23 16:42 ` Alan Cox
2005-11-23 16:39 ` Andi Kleen
2005-11-23 17:21 ` Alan Cox
2005-11-23 16:59 ` Andi Kleen
2005-11-23 22:00 ` Alan Cox
2005-11-24 13:13 ` Andi Kleen
2005-11-24 13:30 ` Eric W. Biederman
2005-11-24 13:39 ` Andi Kleen
2005-11-24 13:58 ` Eric W. Biederman
2005-11-24 19:16 ` thockin
2005-11-24 19:26 ` Andi Kleen
2005-11-24 14:34 ` Alan Cox
2005-11-24 14:22 ` Andi Kleen
2005-11-24 15:15 ` Alan Cox
2005-11-24 14:55 ` Andi Kleen
2005-11-24 15:09 ` Eric W. Biederman
2005-11-24 15:36 ` Andi Kleen
2005-11-24 16:49 ` Eric W. Biederman
2005-11-24 19:12 ` thockin
2005-11-24 19:14 ` Andi Kleen
2005-11-24 19:24 ` thockin
2005-11-24 19:29 ` Andi Kleen
2005-11-24 19:44 ` thockin [this message]
2005-11-24 21:20 ` Andi Kleen
2005-11-24 21:40 ` thockin
2005-11-24 23:33 ` Eric W. Biederman
2005-11-24 23:12 ` Alan Cox
2005-11-24 22:48 ` thockin
2005-11-24 23:35 ` Andi Kleen
2005-11-25 0:13 ` Alan Cox
2005-11-25 1:33 ` H. Peter Anvin
2005-11-28 19:15 ` Bill Davidsen
2005-11-24 16:02 ` Alan Cox
2005-11-24 19:09 ` thockin
2005-11-24 14:30 ` Alan Cox
2005-11-23 17:02 ` Linus Torvalds
2005-11-23 18:02 ` H. Peter Anvin
2005-11-23 18:42 ` Linus Torvalds
2005-11-23 17:26 ` Jeff V. Merkey
2005-11-23 19:03 ` Linus Torvalds
2005-11-23 19:31 ` jmerkey
2005-11-23 18:46 ` Andi Kleen
2005-11-23 19:12 ` H. Peter Anvin
2005-11-23 19:30 ` jmerkey
2005-11-23 21:44 ` Alan Cox
2005-11-23 21:13 ` Andi Kleen
2005-11-23 21:46 ` Jeff Garzik
2005-11-23 22:23 ` Andi Kleen
2005-11-23 22:30 ` Pavel Machek
2005-11-23 22:05 ` Alan Cox
2005-11-23 21:36 ` Arjan van de Ven
2005-11-23 21:36 ` Andi Kleen
2005-11-23 22:13 ` Linus Torvalds
2005-11-23 21:36 ` Linus Torvalds
2005-11-23 21:43 ` Andi Kleen
2005-11-23 22:15 ` Linus Torvalds
2005-11-23 22:22 ` Andi Kleen
2005-11-23 22:25 ` H. Peter Anvin
2005-11-23 22:32 ` Andi Kleen
2005-11-23 22:36 ` H. Peter Anvin
2005-11-23 22:40 ` Andi Kleen
2005-11-23 22:52 ` H. Peter Anvin
2005-11-23 23:10 ` Linus Torvalds
2005-11-24 0:55 ` Jeff Garzik
2005-11-23 21:48 ` Daniel Jacobowitz
2005-11-23 21:53 ` H. Peter Anvin
2005-11-23 22:03 ` Daniel Jacobowitz
2005-11-23 22:09 ` H. Peter Anvin
2005-11-23 22:21 ` Linus Torvalds
2005-11-23 23:29 ` Eric W. Biederman
2005-11-23 23:40 ` Linus Torvalds
2005-11-23 22:19 ` Linus Torvalds
2005-11-23 22:20 ` Daniel Jacobowitz
2005-11-23 23:08 ` Linus Torvalds
2005-11-23 23:02 ` Jeff V. Merkey
2005-11-23 23:42 ` Daniel Jacobowitz
2005-11-23 23:59 ` Linus Torvalds
2005-11-24 2:06 ` Daniel Jacobowitz
2005-11-24 22:32 ` Ulrich Drepper
2005-11-28 19:58 ` Bill Davidsen
2005-11-24 1:02 ` Jeff Garzik
2005-11-24 13:01 ` Pádraig Brady
2005-11-24 13:12 ` Arjan van de Ven
2005-11-28 19:52 ` Bill Davidsen
2005-11-28 20:05 ` Zachary Amsden
2005-11-28 22:19 ` Jeff V. Merkey
2005-11-28 23:00 ` Zachary Amsden
2005-11-28 23:07 ` H. Peter Anvin
2005-11-28 23:30 ` Zachary Amsden
2005-11-28 23:32 ` H. Peter Anvin
2005-11-28 23:12 ` Andi Kleen
2005-11-23 22:50 ` Alan Cox
2005-11-23 22:22 ` H. Peter Anvin
2005-11-25 7:38 ` Chris Wedgwood
2005-11-25 17:33 ` Linus Torvalds
2005-11-28 20:25 ` Bill Davidsen
2005-11-25 20:13 ` H. Peter Anvin
2005-11-24 3:23 ` Mikulas Patocka
2005-11-24 3:31 ` Mikulas Patocka
2005-11-24 3:55 ` H. Peter Anvin
2005-11-24 22:30 ` Ulrich Drepper
2005-11-23 16:43 ` Gerd Knorr
2005-11-23 16:51 ` H. Peter Anvin
2005-11-24 17:48 linux
2005-11-24 18:48 ` Linus Torvalds
2005-11-24 18:24 colin
2006-01-24 15:33 [PATCH] " Gerd Hoffmann
2006-01-24 16:22 ` Ben Collins
2006-01-25 9:20 ` Gerd Hoffmann
2006-01-26 10:22 ` Pavel Machek
2006-01-26 11:17 ` Gerd Hoffmann
2006-01-26 11:48 ` Pavel Machek
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=20051124194459.GA4069@hockin.org \
--to=thockin@hockin.org \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=chrisl@vmware.com \
--cc=davej@redhat.com \
--cc=ebiederm@xmission.com \
--cc=hpa@zytor.com \
--cc=kraxel@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=pavel@ucw.cz \
--cc=pratap@vmware.com \
--cc=torvalds@osdl.org \
--cc=zach@vmware.com \
--cc=zwane@arm.linux.org.uk \
/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