Module Name: src
Committed By: phx
Date: Sat Jun 26 21:45:49 UTC 2010
Modified Files:
src/sys/arch/sandpoint/stand/netboot: Makefile brdsetup.c dev_net.c
devopen.c globals.h main.c nif.c pci.c pciide.c siisata.c
Log Message:
- add IDE/SATA diskboot facility
known ok with KuroBox PCIIDE, need more debug on SiI3512 SATA
which fails reading sectors from a drive.
- now capable of TFTP loading
Code submitted by Toru Nishimura.
To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/sandpoint/stand/netboot/Makefile
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/sandpoint/stand/netboot/brdsetup.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/sandpoint/stand/netboot/dev_net.c \
src/sys/arch/sandpoint/stand/netboot/siisata.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/sandpoint/stand/netboot/devopen.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/sandpoint/stand/netboot/globals.h
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/sandpoint/stand/netboot/main.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/sandpoint/stand/netboot/nif.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/sandpoint/stand/netboot/pci.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/sandpoint/stand/netboot/pciide.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/sandpoint/stand/netboot/Makefile
diff -u src/sys/arch/sandpoint/stand/netboot/Makefile:1.19 src/sys/arch/sandpoint/stand/netboot/Makefile:1.20
--- src/sys/arch/sandpoint/stand/netboot/Makefile:1.19 Thu May 27 06:58:15 2010
+++ src/sys/arch/sandpoint/stand/netboot/Makefile Sat Jun 26 21:45:49 2010
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.19 2010/05/27 06:58:15 dholland Exp $
+# $NetBSD: Makefile,v 1.20 2010/06/26 21:45:49 phx Exp $
S= ${.CURDIR}/../../../..
PROG= netboot
SRCS= entry.S main.c brdsetup.c pci.c devopen.c dev_net.c nif.c \
- fxp.c tlp.c rge.c skg.c printf.c
+ fxp.c tlp.c rge.c skg.c dsk.c pciide.c siisata.c printf.c
CLEANFILES+= vers.c vers.o ${PROG} ${PROG}.bin
CFLAGS+= -Wall -Wno-main -ffreestanding -msoft-float -mmultiple
CFLAGS+= -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith
Index: src/sys/arch/sandpoint/stand/netboot/brdsetup.c
diff -u src/sys/arch/sandpoint/stand/netboot/brdsetup.c:1.20 src/sys/arch/sandpoint/stand/netboot/brdsetup.c:1.21
--- src/sys/arch/sandpoint/stand/netboot/brdsetup.c:1.20 Fri May 28 15:45:11 2010
+++ src/sys/arch/sandpoint/stand/netboot/brdsetup.c Sat Jun 26 21:45:49 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: brdsetup.c,v 1.20 2010/05/28 15:45:11 phx Exp $ */
+/* $NetBSD: brdsetup.c,v 1.21 2010/06/26 21:45:49 phx Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -37,6 +37,8 @@
#include <lib/libsa/net.h>
#include <lib/libkern/libkern.h>
+#include <machine/bootinfo.h>
+
#include "globals.h"
#define BRD_DECL(xxx) \
@@ -105,7 +107,7 @@
};
static struct brdprop *brdprop;
-static uint32_t ns_per_tick;
+static uint32_t ticks_per_sec, ns_per_tick;
static void brdfixup(void);
static void setup(void);
@@ -138,7 +140,7 @@
#define UART_READ(base, r) *(volatile char *)(base + (r))
#define UART_WRITE(base, r, v) *(volatile char *)(base + (r)) = (v)
-void brdsetup(void);
+void brdsetup(void); /* called by entry.S */
void
brdsetup(void)
@@ -155,8 +157,14 @@
20, 25, 20, 30, 35, 40, 40, 20,
30, 25, 40, 30, 30, 25, 35, 00
};
+ char *consname;
+ int consport;
uint32_t extclk;
unsigned pchb, pcib, val;
+ extern struct btinfo_memory bi_mem;
+ extern struct btinfo_console bi_cons;
+ extern struct btinfo_clock bi_clk;
+ extern struct btinfo_prodfamily bi_fam;
/*
* CHRP specification "Map-B" BAT012 layout
@@ -217,11 +225,9 @@
ticks_per_sec = busclock >> 2;
ns_per_tick = 1000000000 / ticks_per_sec;
+ /* now prepare serial console */
consname = brdprop->consname;
consport = brdprop->consport;
- consspeed = brdprop->consspeed;
-
- /* now prepare serial console */
if (strcmp(consname, "eumb") == 0) {
uart1base = 0xfc000000 + consport; /* 0x4500, 0x4600 */
UART_WRITE(uart1base, DCR, 0x01); /* enable DUART mode */
@@ -231,6 +237,13 @@
/* more brd adjustments */
brdfixup();
+
+ bi_mem.memsize = mpc107memsize();
+ snprintf(bi_cons.devname, sizeof(bi_cons.devname), consname);
+ bi_cons.addr = consport;
+ bi_cons.speed = brdprop->consspeed;
+ bi_clk.ticks_per_sec = ticks_per_sec;
+ snprintf(bi_fam.name, sizeof(bi_fam.name), brdprop->family);
}
struct brdprop *
Index: src/sys/arch/sandpoint/stand/netboot/dev_net.c
diff -u src/sys/arch/sandpoint/stand/netboot/dev_net.c:1.8 src/sys/arch/sandpoint/stand/netboot/dev_net.c:1.9
--- src/sys/arch/sandpoint/stand/netboot/dev_net.c:1.8 Thu May 13 10:40:02 2010
+++ src/sys/arch/sandpoint/stand/netboot/dev_net.c Sat Jun 26 21:45:49 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: dev_net.c,v 1.8 2010/05/13 10:40:02 phx Exp $ */
+/* $NetBSD: dev_net.c,v 1.9 2010/06/26 21:45:49 phx Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -38,9 +38,11 @@
#include <lib/libsa/net.h>
#include <lib/libsa/bootp.h>
#include <lib/libsa/nfs.h>
-
#include <lib/libkern/libkern.h>
+#include <machine/bootinfo.h>
+#include <machine/stdarg.h>
+
#include "globals.h"
static int netdev_sock = -1;
@@ -48,51 +50,66 @@
int
net_open(struct open_file *f, ...)
+
{
- int error = 0;
+ va_list ap;
+ char *file, *proto;
+ int error;
+ extern struct btinfo_bootpath bi_path;
- if (netdev_opens == 0) {
- if ((netdev_sock = netif_open(NULL)) < 0) {
- error = errno;
- goto bad;
- }
-
- /* send DHCP request */
- bootp(netdev_sock);
-
- /* IP address was not found */
- if (myip.s_addr == 0) {
- error = ENOENT;
- goto bad;
- }
-
- if (bootfile[0] == '\0')
- strcpy(bootfile, "netbsd");
-
- if (nfs_mount(netdev_sock, rootip, rootpath) != 0) {
- error = errno;
- goto bad;
- }
+ va_start(ap, f);
+ file = va_arg(ap, char *);
+ proto = va_arg(ap, char *);
+ va_end(ap);
+
+ if (netdev_opens > 0)
+ return 0;
+
+ if ((netdev_sock = netif_open(NULL)) < 0)
+ return ENXIO; /* never fails indeed */
+
+ error = 0;
+ bootp(netdev_sock); /* send DHCP request */
+ if (myip.s_addr == 0) {
+ error = ENOENT; /* IP address was not found */
+ goto bad;
}
+
+ if (file[0] != '\0')
+ snprintf(bootfile, sizeof(bootfile), file);
+ else if (bootfile[0] == '\0')
+ snprintf(bootfile, sizeof(bootfile), "netbsd");
+
+ if (strcmp(proto, "nfs") == 0
+ && (error = nfs_mount(netdev_sock, rootip, rootpath)) != 0)
+ goto bad;
+
+ snprintf(bi_path.bootpath, sizeof(bi_path.bootpath), bootfile);
+ f->f_devdata = &netdev_sock;
netdev_opens++;
-bad:
- return (error);
+ return 0;
+ bad:
+ netif_close(netdev_sock);
+ netdev_sock = -1;
+ return error;
}
int
net_close(struct open_file *f)
{
+ f->f_devdata = NULL;
if (--netdev_opens > 0)
- return (0);
+ return 0;
netif_close(netdev_sock);
netdev_sock = -1;
- return (0);
+ return 0;
}
int
-net_strategy(void *d, int f, daddr_t b, size_t s, void *buf, size_t *r)
+net_strategy(void *devdata, int rw, daddr_t dblk, size_t size,
+ void *p, size_t *rsize)
{
- return (EIO);
+ return EIO;
}
Index: src/sys/arch/sandpoint/stand/netboot/siisata.c
diff -u src/sys/arch/sandpoint/stand/netboot/siisata.c:1.8 src/sys/arch/sandpoint/stand/netboot/siisata.c:1.9
--- src/sys/arch/sandpoint/stand/netboot/siisata.c:1.8 Wed May 14 23:14:11 2008
+++ src/sys/arch/sandpoint/stand/netboot/siisata.c Sat Jun 26 21:45:49 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.8 2008/05/14 23:14:11 nisimura Exp $ */
+/* $NetBSD: siisata.c,v 1.9 2010/06/26 21:45:49 phx Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -30,25 +30,16 @@
*/
#include <sys/param.h>
-#include <sys/disklabel.h>
-
-#include <dev/ic/wdcreg.h>
-#include <dev/ata/atareg.h>
#include <lib/libsa/stand.h>
+
#include "globals.h"
-/*
- * - no vtophys() translation, vaddr_t == paddr_t.
- */
-#define DEVTOV(pa) (uint32_t)(pa)
+static uint32_t pciiobase = PCI_XIOBASE;
int siisata_match(unsigned, void *);
void *siisata_init(unsigned, void *);
-static void map3112chan(unsigned, int, struct atac_channel *);
-static void map3114chan(unsigned, int, struct atac_channel *);
-
int
siisata_match(unsigned tag, void *data)
{
@@ -67,77 +58,50 @@
void *
siisata_init(unsigned tag, void *data)
{
- unsigned val, chvalid;
- struct atac_softc *l;
-
- val = pcicfgread(tag, PCI_ID_REG);
- if ((PCI_PRODUCT(val) & 0xf) == 4)
- chvalid = 0xf; /* 4 channel model */
- else
- chvalid = 0x3; /* 2 channel model */
+ unsigned val;
+ int nchan, n;
+ struct dkdev_ata *l;
+
+ l = alloc(sizeof(struct dkdev_ata));
+ memset(l, 0, sizeof(struct dkdev_ata));
+ l->iobuf = allocaligned(512, 16);
+ l->tag = tag;
- l = alloc(sizeof(struct atac_softc));
- memset(l, 0, sizeof(struct atac_softc));
+ l->bar[0] = pciiobase + (pcicfgread(tag, 0x10) &~ 01);
+ l->bar[1] = pciiobase + (pcicfgread(tag, 0x14) &~ 01);
+ l->bar[2] = pciiobase + (pcicfgread(tag, 0x18) &~ 01);
+ l->bar[3] = pciiobase + (pcicfgread(tag, 0x1c) &~ 01);
+ l->bar[4] = pciiobase + (pcicfgread(tag, 0x20) &~ 01);
+ l->bar[5] = pcicfgread(tag, 0x24) &~ 0x3ff;
+ val = pcicfgread(tag, PCI_ID_REG);
if ((PCI_PRODUCT(val) & 0xf) == 0x2) {
- map3112chan(tag, 0, &l->channel[0]);
- map3112chan(tag, 1, &l->channel[1]);
+ /* 3112/3512 */
+ l->chan[0].cmd = l->bar[0];
+ l->chan[0].ctl = l->chan[0].alt = l->bar[1] | 02;
+ l->chan[0].dma = l->bar[4] + 0x0;
+ l->chan[1].cmd = l->bar[2];
+ l->chan[1].ctl = l->chan[1].alt = l->bar[3] | 02;
+ l->chan[1].dma = l->bar[4] + 0x8;
+ /* assume BA5 access is possible */
+ nchan = 2;
}
else {
- map3114chan(tag, 0, &l->channel[0]);
- map3114chan(tag, 1, &l->channel[1]);
- map3114chan(tag, 2, &l->channel[2]);
- map3114chan(tag, 3, &l->channel[3]);
+ /* 3114 */
+ l->chan[0].cmd = l->bar[5] + 0x080;
+ l->chan[0].ctl = l->chan[0].alt = (l->bar[5] + 0x088) | 02;
+ l->chan[1].cmd = l->bar[5] + 0x0c0;
+ l->chan[1].ctl = l->chan[1].alt = (l->bar[5] + 0x0c8) | 02;
+ l->chan[2].cmd = l->bar[5] + 0x280;
+ l->chan[2].ctl = l->chan[2].alt = (l->bar[5] + 0x288) | 02;
+ l->chan[3].cmd = l->bar[5] + 0x2c0;
+ l->chan[3].ctl = l->chan[3].alt = (l->bar[5] + 0x2c8) | 02;
+ nchan = 4;
+ }
+ for (n = 0; n < nchan; n++) {
+ l->presense[n] = satapresense(l, n);
+ if (l->presense[n])
+ printf("port %d device present\n", n);
}
- l->chvalid = chvalid & (unsigned)data;
- l->tag = tag;
return l;
}
-
-/* BAR0-3 */
-static const struct {
- int cmd, ctl;
-} regstd[2] = {
- { 0x10, 0x14 },
- { 0x18, 0x1c },
-};
-
-static void
-map3112chan(unsigned tag, int ch, struct atac_channel *cp)
-{
- int i;
-
- cp->c_cmdbase = (void *)DEVTOV(~07 & pcicfgread(tag, regstd[ch].cmd));
- cp->c_ctlbase = (void *)DEVTOV(~03 & pcicfgread(tag, regstd[ch].ctl));
- cp->c_data = (u_int16_t *)(cp->c_cmdbase + wd_data);
- for (i = 0; i < 8; i++)
- cp->c_cmdreg[i] = cp->c_cmdbase + i;
- cp->c_cmdreg[wd_status] = cp->c_cmdreg[wd_command];
- cp->c_cmdreg[wd_features] = cp->c_cmdreg[wd_precomp];
-}
-
-/* offset to BAR5 */
-static const struct {
- int IDE_TF0, IDE_TF8;
-} reg3114[4] = {
- { 0x080, 0x091 },
- { 0x0c0, 0x0d1 },
- { 0x280, 0x291 },
- { 0x2c0, 0x2d1 },
-};
-
-static void
-map3114chan(unsigned tag, int ch, struct atac_channel *cp)
-{
- int i;
- uint8_t *ba5;
-
- ba5 = (uint8_t *)DEVTOV(pcicfgread(tag, 0x24)); /* PCI_BAR5 */
- cp->c_cmdbase = ba5 + reg3114[ch].IDE_TF0;
- cp->c_ctlbase = ba5 + reg3114[ch].IDE_TF8;
- cp->c_data = (u_int16_t *)(cp->c_cmdbase + wd_data);
- for (i = 0; i < 8; i++)
- cp->c_cmdreg[i] = cp->c_cmdbase + i;
- cp->c_cmdreg[wd_status] = cp->c_cmdreg[wd_command];
- cp->c_cmdreg[wd_features] = cp->c_cmdreg[wd_precomp];
-}
Index: src/sys/arch/sandpoint/stand/netboot/devopen.c
diff -u src/sys/arch/sandpoint/stand/netboot/devopen.c:1.10 src/sys/arch/sandpoint/stand/netboot/devopen.c:1.11
--- src/sys/arch/sandpoint/stand/netboot/devopen.c:1.10 Mon Jul 20 11:43:09 2009
+++ src/sys/arch/sandpoint/stand/netboot/devopen.c Sat Jun 26 21:45:49 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: devopen.c,v 1.10 2009/07/20 11:43:09 nisimura Exp $ */
+/* $NetBSD: devopen.c,v 1.11 2010/06/26 21:45:49 phx Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -35,68 +35,62 @@
#include <lib/libsa/stand.h>
#include <lib/libsa/nfs.h>
+#include <lib/libsa/ufs.h>
+#include <lib/libsa/tftp.h>
#include <lib/libkern/libkern.h>
#include "globals.h"
-struct devsw devsw[] = {
- { "net", net_strategy, net_open, net_close, noioctl },
-};
-int ndevs = sizeof(devsw) / sizeof(devsw[0]);
-
-struct fs_ops fssw[] = {
- FS_OPS(nfs),
-};
-struct fs_ops file_system[1];
+struct devsw devnet = { "net", net_strategy, net_open, net_close, noioctl };
+struct devsw devdsk = { "dsk", dsk_strategy, dsk_open, dsk_close, noioctl };
+
+struct fs_ops file_system[1] = { FS_OPS(null) };
int nfsys = 1;
+struct fs_ops fs_nfs = FS_OPS(nfs);
+struct fs_ops fs_tftp = FS_OPS(tftp);
+struct fs_ops fs_ffsv2 = FS_OPS(ffsv2);
+struct fs_ops fs_ffsv1 = FS_OPS(ffsv1);
+extern char *fsmod;
+
+static void parseunit(const char *, int *, int *, char **);
int
devopen(struct open_file *of, const char *name, char **file)
{
int error;
+ int unit, part;
extern char bootfile[]; /* handed by DHCP */
if (of->f_flags != F_READ)
return EPERM;
- if (strcmp("net:", name) == 0) {
- of->f_dev = &devsw[0];
- if ((error = net_open(of, name)) != 0)
+ if (strncmp("net:", name, 4) == 0 || strncmp("nfs:", name, 4) == 0) {
+ of->f_dev = &devnet;
+ if ((error = net_open(of, &name[4], "nfs")) != 0)
return error;
- file_system[0] = fssw[0];
+ file_system[0] = fs_nfs;
*file = bootfile; /* resolved fname */
return 0; /* NFS */
}
-#if 0 /* later */
+ if (strncmp("tftp:", name, 5) == 0) {
+ of->f_dev = &devnet;
+ if ((error = net_open(of, &name[5], "tftp")) != 0)
+ return error;
+ file_system[0] = fs_tftp;
+ *file = bootfile; /* resolved fname */
+ return 0; /* TFTP */
+ }
if (name[0] == 'w' && name[1] == 'd') {
parseunit(&name[2], &unit, &part, file);
- of->f_dev = &devsw[1];
- if ((error = wdopen(of, unit, part)) != 0)
+ of->f_dev = &devdsk;
+ if ((error = dsk_open(of, unit, part, *file)) != 0)
return error;
- switch (parsefstype(of->f_devdata)) {
- default:
- case FS_BSDFFS:
- file_system[0] = fssw[1]; break;
- case FS_EX2FS:
- file_system[0] = fssw[2]; break;
- case FS_MSDOS:
- file_system[0] = fssw[3]; break;
- }
- return 0;
+ file_system[0] = *dsk_fsops(of);
+ return 0; /* FFS */
}
-#endif
return ENOENT;
}
-/* ARGSUSED */
-int
-noioctl(struct open_file *f, u_long cmd, void *data)
-{
-
- return EINVAL;
-}
-
-#if 0
static void
parseunit(const char *name, int *unitp, int *partp, char **pathp)
{
@@ -115,4 +109,11 @@
*partp = (part == -1) ? 0 : part;
*pathp = (*p == ':') ? (char *)p + 1 : NULL;
}
-#endif
+
+/* ARGSUSED */
+int
+noioctl(struct open_file *f, u_long cmd, void *data)
+{
+
+ return EINVAL;
+}
Index: src/sys/arch/sandpoint/stand/netboot/globals.h
diff -u src/sys/arch/sandpoint/stand/netboot/globals.h:1.17 src/sys/arch/sandpoint/stand/netboot/globals.h:1.18
--- src/sys/arch/sandpoint/stand/netboot/globals.h:1.17 Thu May 20 20:18:51 2010
+++ src/sys/arch/sandpoint/stand/netboot/globals.h Sat Jun 26 21:45:49 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: globals.h,v 1.17 2010/05/20 20:18:51 phx Exp $ */
+/* $NetBSD: globals.h,v 1.18 2010/06/26 21:45:49 phx Exp $ */
/* clock feed */
#ifndef EXT_CLK_FREQ
@@ -30,10 +30,6 @@
void (*reset)(void);
};
-extern char *consname;
-extern int consport;
-extern int consspeed;
-extern int ticks_per_sec;
extern uint32_t cpuclock, busclock;
/* board specific support code */
@@ -87,6 +83,20 @@
#define PCI_HDRTYPE_TYPE(r) (((r) >> 16) & 0x7f)
#define PCI_HDRTYPE_MULTIFN(r) ((r) & (0x80 << 16))
+/*
+ * "Map B" layout
+ *
+ * practice direct mode configuration scheme with CONFIG_ADDR
+ * (0xfec0'0000) and CONFIG_DATA (0xfee0'0000).
+ */
+#define PCI_MEMBASE 0x80000000 /* PCI memory space */
+#define PCI_MEMLIMIT 0xfbffffff /* EUMB is next to this */
+#define PCI_IOBASE 0x00001000 /* reserves room for southbridge */
+#define PCI_IOLIMIT 0x000fffff
+#define PCI_XIOBASE 0xfe000000 /* ISA/PCI io space */
+#define CONFIG_ADDR 0xfec00000
+#define CONFIG_DATA 0xfee00000
+
/* cache ops */
void _wb(uint32_t, uint32_t);
void _wbinv(uint32_t, uint32_t);
@@ -95,7 +105,7 @@
/* heap */
void *allocaligned(size_t, size_t);
-/* NIF */
+/* NIF support */
int net_open(struct open_file *, ...);
int net_close(struct open_file *);
int net_strategy(void *, int, daddr_t, size_t, void *, size_t *);
@@ -114,3 +124,71 @@
NIF_DECL(tlp);
NIF_DECL(rge);
NIF_DECL(skg);
+
+/* DSK support */
+int dskdv_init(unsigned, void **);
+int disk_scan(void *);
+
+int dsk_open(struct open_file *, ...);
+int dsk_close(struct open_file *);
+int dsk_strategy(void *, int, daddr_t, size_t, void *, size_t *);
+struct fs_ops *dsk_fsops(struct open_file *);
+
+/* status */
+#define ATA_STS_BUSY 0x80
+#define ATA_STS_DRDY 0x40
+#define ATA_STS_ERR 0x01
+/* command */
+#define ATA_CMD_IDENT 0xec
+#define ATA_CMD_READ 0xc8
+#define ATA_CMD_READ_EXT 0x24
+#define ATA_CMD_SETF 0xef
+/* device */
+#define ATA_DEV_LBA 0xe0
+#define ATA_DEV_OBS 0x90
+/* control */
+#define ATA_DREQ 0x08
+#define ATA_SRST 0x04
+
+#define ATA_XFER 0x03
+#define XFER_PIO4 0x0c
+#define XFER_PIO0 0x08
+
+struct dvata_chan {
+ uint32_t cmd, ctl, alt, dma;
+};
+#define _DAT 0 /* RW */
+#define _ERR 1 /* R */
+#define _FEA 1 /* W */
+#define _NSECT 2 /* RW */
+#define _LBAL 3 /* RW */
+#define _LBAM 4 /* RW */
+#define _LBAH 5 /* RW */
+#define _DEV 6 /* W */
+#define _STS 7 /* R */
+#define _CMD 7 /* W */
+
+struct dkdev_ata {
+ unsigned tag;
+ uint32_t bar[6];
+ struct dvata_chan chan[4];
+ int presense[4];
+ char *iobuf;
+};
+
+struct disk {
+ char xname[8];
+ void *dvops;
+ unsigned unittag;
+ uint16_t ident[128];
+ uint64_t nsect;
+ uint64_t first;
+ void *dlabel;
+ int part;
+ void *fsops;
+ int (*lba_read)(struct disk *, uint64_t, uint32_t, void *);
+};
+
+int spinwait_unbusy(struct dkdev_ata *, int, int, const char **);
+int perform_atareset(struct dkdev_ata *, int);
+int satapresense(struct dkdev_ata *, int);
Index: src/sys/arch/sandpoint/stand/netboot/main.c
diff -u src/sys/arch/sandpoint/stand/netboot/main.c:1.33 src/sys/arch/sandpoint/stand/netboot/main.c:1.34
--- src/sys/arch/sandpoint/stand/netboot/main.c:1.33 Thu May 20 20:18:51 2010
+++ src/sys/arch/sandpoint/stand/netboot/main.c Sat Jun 26 21:45:49 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.33 2010/05/20 20:18:51 phx Exp $ */
+/* $NetBSD: main.c,v 1.34 2010/06/26 21:45:49 phx Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -61,41 +61,36 @@
int bi_size; /* BOOTINFO_MAXSIZE */
char *bi_next;
-extern char bootfile[]; /* filled by DHCP */
-char rootdev[4]; /* NIF nickname, filled by netif_init() */
-uint8_t en[6]; /* NIC macaddr, fill by netif_init() */
-
-void main(int, char **);
void bi_init(void *);
void bi_add(void *, int, int);
+struct btinfo_memory bi_mem;
+struct btinfo_console bi_cons;
+struct btinfo_clock bi_clk;
+struct btinfo_prodfamily bi_fam;
+struct btinfo_bootpath bi_path;
+struct btinfo_rootdevice bi_rdev;
+struct btinfo_net bi_net;
+
+void main(int, char **);
extern char bootprog_rev[], bootprog_maker[], bootprog_date[];
int brdtype;
-char *consname;
-int consport;
-int consspeed;
-int ticks_per_sec;
uint32_t busclock, cpuclock;
+static int check_bootname(char *);
+#define BNAME_DEFAULT "nfs:"
+
void
main(int argc, char *argv[])
{
- struct btinfo_memory bi_mem;
- struct btinfo_console bi_cons;
- struct btinfo_clock bi_clk;
- struct btinfo_bootpath bi_path;
- struct btinfo_rootdevice bi_rdev;
- struct btinfo_net bi_net;
- struct btinfo_prodfamily bi_fam;
struct brdprop *brdprop;
unsigned long marks[MARK_MAX];
unsigned lata[1][2], lnif[1][2];
- unsigned memsize, tag;
+ unsigned tag, dsk;
int b, d, f, fd, howto, i, n;
-
- /* determine SDRAM size */
- memsize = mpc107memsize();
+ char *bname;
+ void *dev;
printf("\n");
printf(">> NetBSD/sandpoint Boot, Revision %s\n", bootprog_rev);
@@ -103,17 +98,19 @@
brdprop = brd_lookup(brdtype);
printf("%s, cpu %u MHz, bus %u MHz, %dMB SDRAM\n", brdprop->verbose,
- cpuclock / 1000000, busclock / 1000000, memsize >> 20);
+ cpuclock / 1000000, busclock / 1000000, bi_mem.memsize >> 20);
n = pcilookup(PCI_CLASS_IDE, lata, sizeof(lata)/sizeof(lata[0]));
if (n == 0)
n = pcilookup(PCI_CLASS_MISCSTORAGE, lata,
sizeof(lata)/sizeof(lata[0]));
- if (n == 0)
+ if (n == 0) {
+ dsk = ~0;
printf("no IDE found\n");
+ }
else {
- tag = lata[0][1];
- pcidecomposetag(tag, &b, &d, &f);
+ dsk = lata[0][1];
+ pcidecomposetag(dsk, &b, &d, &f);
printf("%04x.%04x IDE %02d:%02d:%02d\n",
PCI_VENDOR(lata[0][0]), PCI_PRODUCT(lata[0][0]),
b, d, f);
@@ -135,20 +132,13 @@
pcisetup();
pcifixup();
+ if (dskdv_init(dsk, &dev) == 0 || disk_scan(dev) == 0)
+ printf("no IDE/SATA device driver is found\n");
+
if (netif_init(tag) == 0)
printf("no NIC device driver is found\n");
- if ((fd = open("net:", 0)) < 0) {
- if (errno == ENOENT)
- printf("\"%s\" not found\n", bootfile);
- goto loadfail;
- }
- printf("loading \"%s\" ", bootfile);
- marks[MARK_START] = 0;
- if (fdloadfile(fd, marks, LOAD_KERNEL) < 0)
- goto loadfail;
-
- /* get boot mode and boot options */
+ /* get boot options and determine bootname */
howto = RB_AUTOBOOT;
for (n = 1; n < argc; n++) {
for (i = 0; i < sizeof(bootargs) / sizeof(bootargs[0]); i++) {
@@ -159,22 +149,31 @@
}
}
if (i >= sizeof(bootargs) / sizeof(bootargs[0]))
- break; /* break on first garbage argument */
+ break; /* break on first unknown string */
+ }
+ if (n == argc)
+ bname = BNAME_DEFAULT;
+ else {
+ bname = argv[n];
+ if (check_bootname(bname) == 0) {
+ printf("%s not a valid bootname\n", bname);
+ goto loadfail;
+ }
+ }
+
+ if ((fd = open(bname, 0)) < 0) {
+ if (errno == ENOENT)
+ printf("\"%s\" not found\n", bi_path.bootpath);
+ goto loadfail;
}
+ printf("loading \"%s\" ", bi_path.bootpath);
+ marks[MARK_START] = 0;
+ if (fdloadfile(fd, marks, LOAD_KERNEL) < 0)
+ goto loadfail;
bootinfo = (void *)0x4000;
bi_init(bootinfo);
- bi_mem.memsize = memsize;
- snprintf(bi_cons.devname, sizeof(bi_cons.devname), consname);
- bi_cons.addr = consport;
- bi_cons.speed = consspeed;
- bi_clk.ticks_per_sec = ticks_per_sec;
- snprintf(bi_path.bootpath, sizeof(bi_path.bootpath), bootfile);
- snprintf(bi_rdev.devname, sizeof(bi_rdev.devname), rootdev);
- bi_rdev.cookie = tag; /* PCI tag for fxp netboot case */
- snprintf(bi_fam.name, sizeof(bi_fam.name), brdprop->family);
-
bi_add(&bi_cons, BTINFO_CONSOLE, sizeof(bi_cons));
bi_add(&bi_mem, BTINFO_MEMORY, sizeof(bi_mem));
bi_add(&bi_clk, BTINFO_CLOCK, sizeof(bi_clk));
@@ -183,9 +182,6 @@
bi_add(&bi_fam, BTINFO_PRODFAMILY, sizeof(bi_fam));
if (brdtype == BRD_SYNOLOGY) {
/* need to set MAC address for Marvell-SKnet */
- strcpy(bi_net.devname, "sk");
- memcpy(bi_net.mac_address, en, sizeof(en));
- bi_net.cookie = tag;
bi_add(&bi_net, BTINFO_NET, sizeof(bi_net));
}
@@ -294,3 +290,26 @@
p = (uint32_t)alloc(size + align);
return (void *)((p + align) & ~align);
}
+
+static int
+check_bootname(char *s)
+{
+ /*
+ * nfs:
+ * nfs:<bootfile>
+ * tftp:
+ * tftp:<bootfile>
+ * wdN:<bootfile>
+ *
+ * net is a synonym of nfs.
+ */
+ if (strncmp(s, "nfs:", 4) == 0 || strncmp(s, "net:", 4) == 0)
+ return 1;
+ if (strncmp(s, "tftp:", 5) == 0)
+ return 1;
+ if (s[0] == 'w' && s[1] == 'd'
+ && s[2] >= '0' && s[2] <= '3' && s[3] == ':') {
+ return s[4] != '\0';
+ }
+ return 0;
+}
Index: src/sys/arch/sandpoint/stand/netboot/nif.c
diff -u src/sys/arch/sandpoint/stand/netboot/nif.c:1.12 src/sys/arch/sandpoint/stand/netboot/nif.c:1.13
--- src/sys/arch/sandpoint/stand/netboot/nif.c:1.12 Sun May 2 13:31:14 2010
+++ src/sys/arch/sandpoint/stand/netboot/nif.c Sat Jun 26 21:45:49 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: nif.c,v 1.12 2010/05/02 13:31:14 phx Exp $ */
+/* $NetBSD: nif.c,v 1.13 2010/06/26 21:45:49 phx Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -37,6 +37,8 @@
#include <lib/libsa/stand.h>
#include <lib/libsa/net.h>
+#include <machine/bootinfo.h>
+
#include "globals.h"
struct nifdv {
@@ -51,13 +53,13 @@
static struct iodesc netdesc;
-static struct nifdv vnifdv[] = {
+static struct nifdv lnifdv[] = {
{ "fxp", fxp_match, fxp_init, fxp_send, fxp_recv },
{ "tlp", tlp_match, tlp_init, tlp_send, tlp_recv },
{ "re", rge_match, rge_init, rge_send, rge_recv },
{ "sk", skg_match, skg_init, skg_send, skg_recv },
};
-static int nnifdv = sizeof(vnifdv)/sizeof(vnifdv[0]);
+static int nnifdv = sizeof(lnifdv)/sizeof(lnifdv[0]);
int
netif_init(unsigned tag)
@@ -66,11 +68,11 @@
struct nifdv *dv;
int n;
uint8_t enaddr[6];
- extern uint8_t en[6];
- extern char rootdev[4];
+ extern struct btinfo_net bi_net;
+ extern struct btinfo_rootdevice bi_rdev;
for (n = 0; n < nnifdv; n++) {
- dv = &vnifdv[n];
+ dv = &lnifdv[n];
if ((*dv->match)(tag, NULL) > 0)
goto found;
}
@@ -80,8 +82,13 @@
s = &netdesc;
s->io_netif = dv;
memcpy(s->myea, enaddr, sizeof(s->myea));
- memcpy(en, enaddr, sizeof(en));
- snprintf(rootdev, sizeof(rootdev), "%s", dv->name);
+
+ /* build btinfo to identify NIF device */
+ snprintf(bi_net.devname, sizeof(bi_net.devname), dv->name);
+ memcpy(bi_net.mac_address, enaddr, sizeof(bi_net.mac_address));
+ bi_net.cookie = tag;
+ snprintf(bi_rdev.devname, sizeof(bi_rdev.devname), dv->name);
+ bi_rdev.cookie = tag;
return 1;
}
Index: src/sys/arch/sandpoint/stand/netboot/pci.c
diff -u src/sys/arch/sandpoint/stand/netboot/pci.c:1.13 src/sys/arch/sandpoint/stand/netboot/pci.c:1.14
--- src/sys/arch/sandpoint/stand/netboot/pci.c:1.13 Thu May 13 10:40:02 2010
+++ src/sys/arch/sandpoint/stand/netboot/pci.c Sat Jun 26 21:45:49 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: pci.c,v 1.13 2010/05/13 10:40:02 phx Exp $ */
+/* $NetBSD: pci.c,v 1.14 2010/06/26 21:45:49 phx Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -33,18 +33,6 @@
#include <lib/libsa/stand.h>
-/*
- * "Map B" layout
- *
- * practice direct mode configuration scheme with CONFIG_ADDR
- * (0xfec0'0000) and CONFIG_DATA (0xfee0'0000).
- */
-#define PCI_MEMBASE 0x80000000
-#define PCI_MEMLIMIT 0xfbffffff /* EUMB is next to this */
-#define PCI_IOBASE 0x00001000 /* reserves room for via 686B */
-#define PCI_IOLIMIT 0x000fffff
-#define CONFIG_ADDR 0xfec00000
-#define CONFIG_DATA 0xfee00000
#define MAXNDEVS 32
Index: src/sys/arch/sandpoint/stand/netboot/pciide.c
diff -u src/sys/arch/sandpoint/stand/netboot/pciide.c:1.7 src/sys/arch/sandpoint/stand/netboot/pciide.c:1.8
--- src/sys/arch/sandpoint/stand/netboot/pciide.c:1.7 Wed May 14 23:14:11 2008
+++ src/sys/arch/sandpoint/stand/netboot/pciide.c Sat Jun 26 21:45:49 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: pciide.c,v 1.7 2008/05/14 23:14:11 nisimura Exp $ */
+/* $NetBSD: pciide.c,v 1.8 2010/06/26 21:45:49 phx Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -30,46 +30,23 @@
*/
#include <sys/param.h>
-#include <sys/disklabel.h>
-
-#include <dev/ic/wdcreg.h>
-#include <dev/ata/atareg.h>
#include <lib/libsa/stand.h>
+
#include "globals.h"
-/*
- * - no vtophys() translation, vaddr_t == paddr_t.
- */
-#define DEVTOV(pa) (uint32_t)(pa)
+static uint32_t pciiobase = PCI_XIOBASE;
-/*
- * cmdide
- * iteide
- * viaide
- * slide
- */
+struct myops {
+ int (*chipfix)(struct dkdev_ata *);
+ int (*presense)(struct dkdev_ata *, int);
+};
+static struct myops cmdideops = { NULL, NULL };
+static struct myops *myops = &cmdideops;
int pciide_match(unsigned, void *);
void *pciide_init(unsigned, void *);
-#define PCIIDE_INTERFACE_PCI(chan) (0x01 << (2 * (chan)))
-
-/* native: PCI BAR0-3 */
-static const struct {
- int cmd, ctl;
-} pcibar[2] = {
- { 0x10, 0x14 },
- { 0x18, 0x1c },
-};
-/* legacy: ISA/PCI IO space */
-static const struct {
- int cmd, ctl;
-} compat[2] = {
- { 0x1f0, 0x3f6 },
- { 0x170, 0x376 },
-};
-
int
pciide_match(unsigned tag, void *data)
{
@@ -81,6 +58,7 @@
case PCI_DEVICE(0x1283, 0x8211): /* ITE 8211 IDE */
case PCI_DEVICE(0x1106, 0x1571): /* VIA 82C586 IDE */
case PCI_DEVICE(0x10ad, 0x0105): /* Symphony Labs 82C105 IDE */
+ case PCI_DEVICE(0x10b8, 0x5229): /* ALi IDE */
return 1;
}
return 0;
@@ -89,42 +67,57 @@
void *
pciide_init(unsigned tag, void *data)
{
- int ch, i;
+ int native, n;
unsigned val;
- struct atac_softc *l;
- struct atac_channel *cp;
+ struct dkdev_ata *l;
+
+ l = alloc(sizeof(struct dkdev_ata));
+ memset(l, 0, sizeof(struct dkdev_ata));
+ l->iobuf = allocaligned(512, 16);
+ l->tag = tag;
+
+ if (myops->chipfix)
+ (*myops->chipfix)(l);
- l = alloc(sizeof(struct atac_softc));
- memset(l, 0, sizeof(struct atac_softc));
val = pcicfgread(tag, PCI_CLASS_REG);
- for (ch = 0; ch < 2; ch += 1) {
- cp = &l->channel[ch];
- if (PCIIDE_INTERFACE_PCI(ch) & val) {
- cp->c_cmdbase =
- (void *)DEVTOV(~03 & pcicfgread(tag, pcibar[ch].cmd));
- cp->c_ctlbase =
- (void *)DEVTOV(~03 & pcicfgread(tag, pcibar[ch].ctl));
- cp->c_data = (u_int16_t *)(cp->c_cmdbase + wd_data);
- for (i = 0; i < 8; i++)
- cp->c_cmdreg[i] = cp->c_cmdbase + i;
- cp->c_cmdreg[wd_status] = cp->c_cmdreg[wd_command];
- cp->c_cmdreg[wd_features] = cp->c_cmdreg[wd_precomp];
- }
+ native = val & 03;
+ if (native) {
+ /* native, use BAR 01234 */
+ l->bar[0] = pciiobase + (pcicfgread(tag, 0x10) &~ 01);
+ l->bar[1] = pciiobase + (pcicfgread(tag, 0x14) &~ 01);
+ l->bar[2] = pciiobase + (pcicfgread(tag, 0x18) &~ 01);
+ l->bar[3] = pciiobase + (pcicfgread(tag, 0x1c) &~ 01);
+ l->bar[4] = pciiobase + (pcicfgread(tag, 0x20) &~ 01);
+ l->chan[0].cmd = l->bar[0];
+ l->chan[0].ctl = l->chan[0].alt = l->bar[1] | 02;
+ l->chan[0].dma = l->bar[4] + 0x0;
+ l->chan[1].cmd = l->bar[2];
+ l->chan[1].ctl = l->chan[1].alt = l->bar[3] | 02;
+ l->chan[1].dma = l->bar[4] + 0x8;
+ }
+ else {
+ /* legacy */
+ l->bar[0]= pciiobase + 0x1f0;
+ l->bar[1]= pciiobase + 0x3f4;
+ l->bar[2]= pciiobase + 0x170;
+ l->bar[3]= pciiobase + 0x374;
+ l->chan[0].cmd = l->bar[0];
+ l->chan[0].ctl = l->chan[0].alt = l->bar[1] | 02;
+ l->chan[0].dma = 0;
+ l->chan[1].cmd = l->bar[2];
+ l->chan[1].ctl = l->chan[1].alt = l->bar[3] | 02;
+ l->chan[1].dma = 0;
+ }
+
+ for (n = 0; n < 2; n++) {
+ if (myops->presense && (*myops->presense)(l, n) == 0)
+ l->presense[n] = 0; /* found not exist */
else {
- uint32_t pciiobase = 0xfe000000; /* !!! */
- cp->c_cmdbase =
- (void *)DEVTOV(pciiobase + compat[ch].cmd);
- cp->c_ctlbase =
- (void *)DEVTOV(pciiobase + compat[ch].ctl);
- cp->c_data = (u_int16_t *)(cp->c_cmdbase + wd_data);
- for (i = 0; i < 8; i++)
- cp->c_cmdreg[i] = cp->c_cmdbase + i;
- cp->c_cmdreg[wd_status] = cp->c_cmdreg[wd_command];
- cp->c_cmdreg[wd_features] = cp->c_cmdreg[wd_precomp];
+ /* check to see whether soft reset works */
+ l->presense[n] = perform_atareset(l, n);
}
- cp->compatchan = ch;
+ if (l->presense[n])
+ printf("channel %d present\n", n);
}
- l->chvalid = 03 & (unsigned)data;
- l->tag = tag;
return l;
}