Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/bebox/stand/boot Support kernel load from SCSI HDD ...



details:   https://anonhg.NetBSD.org/src/rev/fb274eb5d789
branches:  trunk
changeset: 758027:fb274eb5d789
user:      kiyohara <kiyohara%NetBSD.org@localhost>
date:      Thu Oct 14 06:58:22 2010 +0000

description:
Support kernel load from SCSI HDD with onboard siop.  It is very EXPERIMENTAL!!

diffstat:

 sys/arch/bebox/stand/boot/Makefile |     4 +-
 sys/arch/bebox/stand/boot/boot.c   |     8 +-
 sys/arch/bebox/stand/boot/conf.c   |     7 +-
 sys/arch/bebox/stand/boot/sd.c     |   741 +++++++++++++++++++++
 sys/arch/bebox/stand/boot/sdvar.h  |   164 ++++
 sys/arch/bebox/stand/boot/siop.c   |  1233 ++++++++++++++++++++++++++++++++++++
 sys/arch/bebox/stand/boot/version  |     4 +-
 7 files changed, 2156 insertions(+), 5 deletions(-)

diffs (truncated from 2244 to 300 lines):

diff -r 2bc1d06c14f7 -r fb274eb5d789 sys/arch/bebox/stand/boot/Makefile
--- a/sys/arch/bebox/stand/boot/Makefile        Thu Oct 14 06:50:43 2010 +0000
+++ b/sys/arch/bebox/stand/boot/Makefile        Thu Oct 14 06:58:22 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.28 2010/10/14 06:50:43 kiyohara Exp $
+#      $NetBSD: Makefile,v 1.29 2010/10/14 06:58:22 kiyohara Exp $
 
 NOMAN= # defined
 
@@ -23,7 +23,7 @@
 SRCS= srt0.s
 SRCS+= boot.c clock.c com.c conf.c cons.c cpu.c devopen.c
 SRCS+= fd.c filesystem.c inkernel.c io.c kbd.c monitor.c ns16550.c
-SRCS+= pci.c prf.c tgets.c vers.c vga.c video.c vreset.c wdc.c wd.c
+SRCS+= pci.c prf.c sd.c siop.c tgets.c vers.c vga.c video.c vreset.c wdc.c wd.c
 SRCS+= setjmp.S
 
 CFLAGS= -Wno-main -ffreestanding
diff -r 2bc1d06c14f7 -r fb274eb5d789 sys/arch/bebox/stand/boot/boot.c
--- a/sys/arch/bebox/stand/boot/boot.c  Thu Oct 14 06:50:43 2010 +0000
+++ b/sys/arch/bebox/stand/boot/boot.c  Thu Oct 14 06:58:22 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: boot.c,v 1.22 2010/10/14 06:50:44 kiyohara Exp $       */
+/*     $NetBSD: boot.c,v 1.23 2010/10/14 06:58:22 kiyohara Exp $       */
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -40,11 +40,14 @@
 #include <machine/cpu.h>
 
 #include "boot.h"
+#include "sdvar.h"
 #include "wdvar.h"
 
 char *names[] = {
+       "/dev/disk/scsi/0/0/0_0:/netbsd",
        "/dev/disk/ide/0/master/0_0:/netbsd",
        "/dev/disk/floppy:netbsd",      "/dev/disk/floppy:netbsd.gz",
+       "/dev/disk/scsi/0/0/0_0:/onetbsd",
        "/dev/disk/ide/0/master/0_0:/onetbsd",
        "/dev/disk/floppy:onetbsd",     "/dev/disk/floppy:onetbsd.gz"
        "in",
@@ -132,6 +135,9 @@
 
        printf("\n");
 
+       /* Initialize siop@pci0 dev 12 func 0 */
+       siop_init(0, 12, 0);
+
        /* Initialize wdc@isa port 0x1f0 */
        wdc_init(0x1f0);
 
diff -r 2bc1d06c14f7 -r fb274eb5d789 sys/arch/bebox/stand/boot/conf.c
--- a/sys/arch/bebox/stand/boot/conf.c  Thu Oct 14 06:50:43 2010 +0000
+++ b/sys/arch/bebox/stand/boot/conf.c  Thu Oct 14 06:58:22 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: conf.c,v 1.8 2010/10/14 06:50:44 kiyohara Exp $        */
+/*     $NetBSD: conf.c,v 1.9 2010/10/14 06:58:22 kiyohara Exp $        */
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -42,12 +42,17 @@
 extern int inopen(struct open_file *, ...);
 extern int inclose(struct open_file *);
 
+extern int sdstrategy(void *, int, daddr_t, size_t, void *, size_t *);
+extern int sdopen(struct open_file *, ...);
+extern int sdclose(struct open_file *);
+
 extern int wdstrategy(void *, int, daddr_t, size_t, void *, size_t *);
 extern int wdopen(struct open_file *, ...);
 extern int wdclose(struct open_file *);
 
 struct devsw devsw[] = {
        { "fd", fdstrategy, fdopen, fdclose, noioctl },
+       { "sd", sdstrategy, sdopen, sdclose, noioctl },
        { "wd", wdstrategy, wdopen, wdclose, noioctl },
 
        { NULL, NULL,       NULL,   NULL,    NULL },
diff -r 2bc1d06c14f7 -r fb274eb5d789 sys/arch/bebox/stand/boot/sd.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/bebox/stand/boot/sd.c    Thu Oct 14 06:58:22 2010 +0000
@@ -0,0 +1,741 @@
+/*     $NetBSD: sd.c,v 1.1 2010/10/14 06:58:22 kiyohara Exp $  */
+/*
+ * Copyright (c) 2010 KIYOHARA Takashi
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/stdint.h>
+
+#include <lib/libsa/stand.h>
+#include <lib/libkern/libkern.h>
+
+#include <machine/param.h>
+#include <machine/stdarg.h>
+
+#include "boot.h"
+#include "sdvar.h"
+
+#ifdef DEBUG
+#define DPRINTF(x)     printf x
+#else
+#define DPRINTF(x)
+#endif
+
+#define SD_DEFAULT_BLKSIZE     512
+
+
+struct sd_mode_sense_data {
+       struct scsi_mode_parameter_header_6 header;
+       struct scsi_general_block_descriptor blk_desc;
+       union scsi_disk_pages pages;
+};
+
+static int sd_validate_blksize(int);
+static uint64_t sd_read_capacity(struct sd_softc *, int *);
+static int sd_get_simplifiedparms(struct sd_softc *);
+static int sd_get_capacity(struct sd_softc *);
+static int sd_get_parms_page4(struct sd_softc *, struct disk_parms *);
+static int sd_get_parms_page5(struct sd_softc *, struct disk_parms *);
+static int sd_get_parms(struct sd_softc *);
+static void sdgetdefaultlabel(struct sd_softc *, struct disklabel *);
+static int sdgetdisklabel(struct sd_softc *);
+
+int sdopen(struct open_file *, ...);
+int sdclose(struct open_file *);
+int sdstrategy(void *, int, daddr_t, size_t, void *, size_t *);
+
+
+static int
+sd_validate_blksize(int len)
+{
+
+       switch (len) {
+       case 256:
+       case 512:
+       case 1024:
+       case 2048:
+       case 4096:
+               return 1;
+       }
+       return 0;
+}
+
+/*
+ * sd_read_capacity:
+ *
+ *     Find out from the device what its capacity is.
+ */
+static uint64_t
+sd_read_capacity(struct sd_softc *sd, int *blksize)
+{
+       union {
+               struct scsipi_read_capacity_10 cmd;
+               struct scsipi_read_capacity_16 cmd16;
+       } cmd;
+       union {
+               struct scsipi_read_capacity_10_data data;
+               struct scsipi_read_capacity_16_data data16;
+       } data;
+       uint64_t rv;
+
+       memset(&cmd, 0, sizeof(cmd));
+       cmd.cmd.opcode = READ_CAPACITY_10;
+
+       /*
+        * If the command works, interpret the result as a 4 byte
+        * number of blocks
+        */
+       rv = 0;
+       memset(&data, 0, sizeof(data.data));
+       if (scsi_command(sd, (void *)&cmd.cmd, sizeof(cmd.cmd),
+           (void *)&data, sizeof(data.data)) != 0)
+               goto out;
+
+       if (_4btol(data.data.addr) != 0xffffffff) {
+               *blksize = _4btol(data.data.length);
+               rv = _4btol(data.data.addr) + 1;
+               goto out;
+       }
+
+       /*
+        * Device is larger than can be reflected by READ CAPACITY (10).
+        * Try READ CAPACITY (16).
+        */
+
+       memset(&cmd, 0, sizeof(cmd));
+       cmd.cmd16.opcode = READ_CAPACITY_16;
+       cmd.cmd16.byte2 = SRC16_SERVICE_ACTION;
+       _lto4b(sizeof(data.data16), cmd.cmd16.len);
+
+       memset(&data, 0, sizeof(data.data16));
+       if (scsi_command(sd, (void *)&cmd.cmd16, sizeof(cmd.cmd16),
+           (void *)&data, sizeof(data.data16)) != 0)
+               goto out;
+
+       *blksize = _4btol(data.data16.length);
+       rv = _8btol(data.data16.addr) + 1;
+
+ out:
+       return rv;
+}
+
+static int
+sd_get_simplifiedparms(struct sd_softc *sd)
+{
+       struct {
+               struct scsi_mode_parameter_header_6 header;
+               /* no block descriptor */
+               uint8_t pg_code; /* page code (should be 6) */
+               uint8_t pg_length; /* page length (should be 11) */
+               uint8_t wcd; /* bit0: cache disable */
+               uint8_t lbs[2]; /* logical block size */
+               uint8_t size[5]; /* number of log. blocks */
+               uint8_t pp; /* power/performance */
+               uint8_t flags;
+               uint8_t resvd;
+       } scsipi_sense;
+       struct disk_parms *dp = &sd->sc_params;
+       uint64_t blocks;
+       int error, blksize;
+
+       /*
+        * sd_read_capacity (ie "read capacity") and mode sense page 6
+        * give the same information. Do both for now, and check
+        * for consistency.
+        * XXX probably differs for removable media
+        */
+       dp->blksize = SD_DEFAULT_BLKSIZE;
+       if ((blocks = sd_read_capacity(sd, &blksize)) == 0)
+               return SDGP_RESULT_OFFLINE;             /* XXX? */
+
+       error = scsi_mode_sense(sd, SMS_DBD, 6,
+           &scsipi_sense.header, sizeof(scsipi_sense));
+
+       if (error != 0)
+               return SDGP_RESULT_OFFLINE;             /* XXX? */
+
+       dp->blksize = blksize;
+       if (!sd_validate_blksize(dp->blksize))
+               dp->blksize = _2btol(scsipi_sense.lbs);
+       if (!sd_validate_blksize(dp->blksize))
+               dp->blksize = SD_DEFAULT_BLKSIZE;
+
+       /*
+        * Create a pseudo-geometry.
+        */
+       dp->heads = 64;
+       dp->sectors = 32;
+       dp->cyls = blocks / (dp->heads * dp->sectors);
+       dp->disksize = _5btol(scsipi_sense.size);
+       if (dp->disksize <= UINT32_MAX && dp->disksize != blocks) {
+               printf("RBC size: mode sense=%llu, get cap=%llu\n",
+                      (unsigned long long)dp->disksize,
+                      (unsigned long long)blocks);
+               dp->disksize = blocks;
+       }
+       dp->disksize512 = (dp->disksize * dp->blksize) / DEV_BSIZE;
+
+       return SDGP_RESULT_OK;
+}
+
+/*
+ * Get the scsi driver to send a full inquiry to the * device and use the
+ * results to fill out the disk parameter structure.
+ */
+static int
+sd_get_capacity(struct sd_softc *sd)
+{
+       struct disk_parms *dp = &sd->sc_params;
+       uint64_t blocks;
+       int error, blksize;
+
+       dp->disksize = blocks = sd_read_capacity(sd, &blksize);
+       if (blocks == 0) {
+               struct scsipi_read_format_capacities cmd;



Home | Main Index | Thread Index | Old Index