AF:
NF:0
PS:10
SRH:1
SFN:
DSR:
MID:<20081210165722.58935387@ripper.onstor.net>
CFG:
PT:0
S:andy.sharp@onstor.com
RQ:
SSV:exch1.onstor.net
NSV:
SSH:
R:<bfisher@onstor.com>
MAID:1
X-Sylpheed-Privacy-System:
X-Sylpheed-Sign:0
SCF:#mh/Mailbox/sent
RMID:#imap/andys@onstor.net@exch1.onstor.net/INBOX	0	49406038.6000309@onstor.com
X-Sylpheed-End-Special-Headers: 1
Date: Wed, 10 Dec 2008 16:57:33 -0800
From: Andrew Sharp <andy.sharp@onstor.com>
To: Bill Fisher <bfisher@onstor.com>
Subject: Re: TxRx 0x1A000000 PCI fixup sample code
Message-ID: <20081210165733.0a60dbce@ripper.onstor.net>
In-Reply-To: <49406038.6000309@onstor.com>
References: <49406038.6000309@onstor.com>
Organization: Onstor
X-Mailer: Sylpheed-Claws 2.6.0 (GTK+ 2.8.20; x86_64-pc-linux-gnu)
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="MP_8mezxJoFNBQeKbC/BO8iHzV"

--MP_8mezxJoFNBQeKbC/BO8iHzV
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

attached is program that will load a tuxrx or tuxfp (just thinking
ahead) image from a running SSC.  i just cross compile it on my
workstation.

you will want to modify it to point to files on your own system.  the
nfs_ version load file name is for when I'm running the SSC in NFS root
mode, so /boot/whatever is just a symlink to vmlinux.bin in my kernel
directory so i don't have to do any copying.

compile command:

mips64el-linux-gcc -march=mips32r2 -mtune=sb1 -O2 -o load_vmlinux load_vmlinux.c


On Wed, 10 Dec 2008 16:35:04 -0800 Bill Fisher <bfisher@onstor.com>
wrote:

> #define MGMTBUS_TXRX_SHAREDMEM 0x1A000000
> /*
>   * Routine Description:
>   * Code modeled after EEE txrx code found in
>   * Code/sm-pci/pci-init.c ~100
>   *
>   * Setup the 16MB PCI access window at the beginning of the shared
> memory. *
>   * Each PCI configuration register from 0x44 to 0x80
>   * provides access to 1MB of memory, 0x1 is enable bit.
>   * Map the TxRx Shared Memory region of PCI Address space
>   * to a chunk of physical memory reserved by the kernel.
>   *
>   * The a 16MB hole starting at PCI physical address is
>   * 'MGMTBUS_TXRX_SHAREDMEM' aka 0x1A000000.
>   *
>   * This "hack" relies on the kernel having already allocated
>   * a 16MB chunk of physical memory at 0x1F00000000 to
>   * map the PPCI Space onto.
>   *
>   * Arguments:
>   *  None.
>   *
>   * Return Value:
>   *  None.
>   */
> void
> mgmtbus_init_fixPCIMap(void)
> {
>     uintptr_t pci_phys_start = MGMTBUS_TXRX_SHAREDMEM;
>     uintptr_t pci_phys_end = pci_phys_start + (16 * 1024 * 1024);
>     uintptr_t addr;
>     int n = 0;
> 
>     MGMTBUS_PRINTK("%s: ENTRY\n", __FUNCTION__);
> 
>     /* Enable access to map registers */
>     pci_cfg_write(0, 0, 0, PHB_EXTCONFIGDIS, 1);
> 
>     /*
>      * Enable access to 16 1MB chunks
>      */
>     for (addr = pci_phys_start; addr < pci_phys_end; addr += 1024 *
> 1024) { pci_cfg_write(0, 0, 0, R_BCM1480_PHB_MAP(n), (addr >> 8) |
> 0x1); n++;
>     }
> 
>     /* Disable access to map registers */
>     pci_cfg_write(0, 0, 0, PHB_EXTCONFIGDIS, 0);
> 
>     MGMTBUS_PRINTK("%s: EXIT\n", __FUNCTION__);
>     return;
> }

--MP_8mezxJoFNBQeKbC/BO8iHzV
Content-Type: text/x-csrc; name=load_vmlinux.c
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=load_vmlinux.c

#define _FILE_OFFSET_BITS 64
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

main(int argc, char **argv){

	int sfd;
	char *sname = "/boot/vmlinux-tuxrx.bin";
	char *sbuf;
	int mfd;
	unsigned long long laddr = 0x01a000000ULL; /* physical address */
	int len;
	struct stat stat_buf;
	int rc;
	int i;
	int x;

	if (argc > 1) {
		sname = argv[1];
	}

	if (argc > 2) {
		laddr = strtoull(argv[2], NULL, 0);
	}

printf("argv[0] = '%s'\n", argv[0]);
	if (strstr(argv[0], "nfs_load_tuxrx")) {
		/*
		 * local disk file on ripper
		 */
		sname = "/boot/vmlinux.tuxrx.local";
	} else if (strstr(argv[0], "nfs_load_tuxfp")) {
		/*
		 * local disk file on ripper
		 */
		sname = "/homes/andys/vmlinux.tuxfp.local";
		laddr = 0x01b000000ULL;
	} else if (strstr(argv[0], "load_tuxfp")) {
		/*
		 * standard location
		 */
		sname = "/boot/vmlinux.tuxfp";
		laddr = 0x01b000000ULL;
	}

printf("sname = '%s'\n", sname);
sleep(1); /* before doing anything too catastrophic */

	sfd = open(sname, O_RDONLY);
	if (!sfd) {
		fprintf(stderr, "failed to open file %s: %d\n", sname, errno);
		exit(1);
	}
	mfd = open("/dev/mipsphys", O_WRONLY);
	if (mfd < 0) {
		fprintf(stderr, "failed to open /dev/mipsphys for writing: %d\n",
			errno);
		exit(1);
	}

	laddr |= 0xf800000000ULL; /* PCI base -- 64bit is much more convenient */

	rc = (int)lseek(mfd, laddr, SEEK_SET);
	if (rc == -1) {
		fprintf(stderr, "lseek to %#llx failed on /dev/mipsphys: %d\n", laddr,
			errno);
		exit(1);
	}

	rc = fstat(sfd, &stat_buf);
	if (rc) {
		fprintf(stderr, "stat failed on %s: %d\n", sname, errno);
		exit(1);
	}
	if (!S_ISREG(stat_buf.st_mode)) {
		fprintf(stderr, "error: %s is not a regular file.\n", sname);
		exit(1);
	}
	len = stat_buf.st_size;
	sbuf = (char *)mmap(NULL, len, PROT_READ, MAP_NORESERVE | MAP_SHARED, sfd,
		0LL);
	if (!sbuf) {
		fprintf(stderr, "mmap failed on %s: %d\n", sname, errno);
		exit(1);
	}
	x = 0;
	printf("writing %d bytes to %#llx from %p\n", len, laddr, sbuf);
	while (len) {
		if (len < 8) {
			if (len < 4) {
				for (i = 0; i < len; i++) {
					rc = write(mfd, sbuf + x, 1);
					if (rc != 1) {
						fprintf(stderr,
							"write of 1 byte from offset %d failed: %d\n", x,
							errno);
						exit(1);
					}
					x = x + 1;
				}
				len = 0;
			} else {
				rc = write(mfd, sbuf + x, 4);
				if (rc != 4) {
					fprintf(stderr,
						"write of 4 bytes from offset %d failed: %d\n", x,
						errno);
					exit(1);
				}
				len = len - 4;
				x = x + 4;
			}
		} else {
			rc = write(mfd, sbuf + x, 8);
			if (rc != 8) {
				fprintf(stderr, "write of 8 bytes from offset %d failed: %d, errno %d\n",
					x, rc, errno);
				exit(1);
			}
			len = len - 8;
			x = x + 8;
		}
		if (!(len % 2048)) {
			printf(".");
			fflush(stdout);
		}
	}
	printf("\n");
}

--MP_8mezxJoFNBQeKbC/BO8iHzV--
