⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scsiconf.c

📁 MIPS处理器的bootloader,龙芯就是用的修改过的PMON2
💻 C
📖 第 1 页 / 共 2 页
字号:
/*	$OpenBSD: scsiconf.c,v 1.56 2001/05/24 04:13:16 angelos Exp $	*//*	$NetBSD: scsiconf.c,v 1.57 1996/05/02 01:09:01 neil Exp $	*//* * Copyright (c) 1994 Charles Hannum.  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. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by Charles Hannum. * 4. The name of the author may not be used to endorse or promote products *    derived from this software without specific prior written permission. * * 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. *//* * Originally written by Julian Elischer (julian@tfs.com) * for TRW Financial Systems for use under the MACH(2.5) operating system. * * TRW Financial Systems, in accordance with their agreement with Carnegie * Mellon University, makes this software available to CMU to distribute * or use in any manner that they see fit as long as this message is kept with * the software. For this reason TFS also grants any other persons or * organisations permission to use or modify this software. * * TFS supplies this software to be publicly redistributed * on the understanding that TFS is not responsible for the correct * functioning of this software in any circumstances. * * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 */#include <sys/types.h>#include <sys/param.h>#include <sys/systm.h>#include <sys/malloc.h>#include <sys/device.h>#include <scsi/scsi_all.h>#include <scsi/scsiconf.h>#if 0#if NCALS > 0	{ T_PROCESSOR, T_FIXED, 1,	  0, 0, 0 },#endif	/* NCALS */#if NBLL > 0	{ T_PROCESSOR, T_FIXED, 1,	  "AEG     ", "READER          ", "V1.0" },#endif	/* NBLL */#if NKIL > 0	{ T_SCANNER, T_FIXED, 0,	  "KODAK   ", "IL Scanner 900  ", 0 },#endif	/* NKIL */#endif/* * Declarations */void scsi_probedev __P((struct scsibus_softc *, int, int));int scsi_probe_bus __P((int bus, int target, int lun));struct scsi_device probe_switch = {	NULL,	NULL,	NULL,	NULL,};int scsibusmatch __P((struct device *, void *, void *));void scsibusattach __P((struct device *, struct device *, void *));int  scsibusactivate __P((struct device *, enum devact));int  scsibusdetach __P((struct device *, int));void scsibuszeroref __P((struct device *));int scsibussubmatch __P((struct device *, void *, void *));struct cfattach scsibus_ca = {	sizeof(struct scsibus_softc), scsibusmatch, scsibusattach,	scsibusdetach, scsibusactivate, scsibuszeroref};struct cfdriver scsibus_cd = {	NULL, "scsibus", DV_DULL};int scsidebug_targets = SCSIDEBUG_TARGETS;int scsidebug_luns = SCSIDEBUG_LUNS;int scsidebug_level = SCSIDEBUG_LEVEL;int scsi_autoconf = SCSI_AUTOCONF;int scsibusprint __P((void *, const char *));intscsiprint(aux, pnp)	void *aux;	const char *pnp;{#ifndef __OpenBSD__	struct scsi_link *l = aux;#endif	/* only "scsibus"es can attach to "scsi"s; easy. */	if (pnp)		printf("scsibus at %s", pnp);#ifndef __OpenBSD__	/* don't print channel if the controller says there can be only one. */	if (l->channel != SCSI_CHANNEL_ONLY_ONE)		printf(" channel %d", l->channel);#endif	return (UNCONF);}intscsibusmatch(parent, match, aux)        struct device *parent;        void *match, *aux;{	return 1;}/* * The routine called by the adapter boards to get all their * devices configured in. */voidscsibusattach(parent, self, aux)        struct device *parent, *self;        void *aux;{	struct scsibus_softc *sb = (struct scsibus_softc *)self;	struct scsi_link *sc_link_proto = aux;	int nbytes, i;	extern int cold;	if (!cold)		scsi_autoconf = 0;	sc_link_proto->scsibus = sb->sc_dev.dv_unit;	sb->adapter_link = sc_link_proto;	if (sb->adapter_link->adapter_buswidth == 0)		sb->adapter_link->adapter_buswidth = 8;	sb->sc_buswidth = sb->adapter_link->adapter_buswidth;	if (sb->adapter_link->luns == 0)		sb->adapter_link->luns = 8;	printf(": %d targets\n", sb->sc_buswidth);	nbytes = sb->sc_buswidth * sizeof(struct scsi_link **);	sb->sc_link = (struct scsi_link ***)malloc(nbytes, M_DEVBUF, M_NOWAIT);	if (sb->sc_link == NULL)		panic("scsibusattach: can't allocate target links");	nbytes = 8 * sizeof(struct scsi_link *);	for (i = 0; i < sb->sc_buswidth; i++) {		sb->sc_link[i] = (struct scsi_link **)malloc(nbytes,		    M_DEVBUF, M_NOWAIT);		if (sb->sc_link[i] == NULL)			panic("scsibusattach: can't allocate lun links");		bzero(sb->sc_link[i], nbytes);	}#if defined(SCSI_DELAY) && SCSI_DELAY > 2	printf("%s: waiting for scsi devices to settle\n",		sb->sc_dev.dv_xname);#else	/* SCSI_DELAY > 2 */#undef	SCSI_DELAY#define SCSI_DELAY 2#endif	/* SCSI_DELAY */	delay(1000000 * SCSI_DELAY);	scsi_probe_bus(sb->sc_dev.dv_unit, -1, -1);}intscsibusactivate(dev, act)	struct device *dev;	enum devact act;{	return (config_activate_children(dev, act));}int  scsibusdetach (dev, type)	struct device *dev;	int type;{	return (config_detach_children(dev, type));}voidscsibuszeroref(dev)	struct device *dev;{	struct scsibus_softc *sb = (struct scsibus_softc *)dev;	int i;	for (i = 0; i < sb->sc_buswidth; i++) {		if (sb->sc_link[i] != NULL)			free(sb->sc_link[i], M_DEVBUF);	}		free(sb->sc_link, M_DEVBUF);}intscsibussubmatch(parent, match, aux)	struct device *parent;	void *match, *aux;{	struct cfdata *cf = match;	struct scsibus_attach_args *sa = aux;	struct scsi_link *sc_link = sa->sa_sc_link;	if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != sc_link->target)		return 0;	if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != sc_link->lun)		return 0;	return ((*cf->cf_attach->ca_match)(parent, match, aux));}/* * Probe the requested scsi bus. It must be already set up. * -1 requests all set up scsi busses. * target and lun optionally narrow the search if not -1 */intscsi_probe_busses(bus, target, lun)	int bus, target, lun;{	if (bus == -1) {		for (bus = 0; bus < scsibus_cd.cd_ndevs; bus++)			if (scsibus_cd.cd_devs[bus])				scsi_probe_bus(bus, target, lun);		return 0;	} else {		return scsi_probe_bus(bus, target, lun);	}}/* * Probe the requested scsi bus. It must be already set up. * target and lun optionally narrow the search if not -1 */intscsi_probe_bus(bus, target, lun)	int bus, target, lun;{	struct scsibus_softc *scsi;	int maxtarget, mintarget, maxlun, minlun;	u_int16_t scsi_addr;	if (bus < 0 || bus >= scsibus_cd.cd_ndevs)		return ENXIO;	scsi = scsibus_cd.cd_devs[bus];	if (!scsi)		return ENXIO;	scsi_addr = scsi->adapter_link->adapter_target;	if (target == -1) {		maxtarget = scsi->adapter_link->adapter_buswidth - 1;		mintarget = 0;	} else {		if (target < 0 ||		    target >= scsi->adapter_link->adapter_buswidth)			return EINVAL;		maxtarget = mintarget = target;	}	if (lun == -1) {		maxlun = scsi->adapter_link->luns - 1;		minlun = 0;	} else {		if (lun < 0 || lun > 7)			return EINVAL;		maxlun = minlun = lun;	}	for (target = mintarget; target <= maxtarget; target++) {		if (target == scsi_addr)			continue;		for (lun = minlun; lun <= maxlun; lun++) {			/*			 * See if there's a device present, and configure it.			 */			scsi_probedev(scsi, target, lun);			if ((scsi->moreluns & (1 << target)) == 0)				break;			/* otherwise something says we should look further */		}	}	return 0;}voidscsi_strvis(dst, src, len)	u_char *dst, *src;	int len;{	/* Trim leading and trailing blanks and NULs. */	while (len > 0 && (src[0] == ' ' || src[0] == '\0' || src[0] == 0xff))		++src, --len;	while (len > 0 && (src[len-1] == ' ' || src[len-1] == '\0' ||	    src[len-1] == 0xff))		--len;	while (len > 0) {		if (*src < 0x20 || *src >= 0x80) {			/* non-printable characters */			*dst++ = '\\';			*dst++ = ((*src & 0300) >> 6) + '0';			*dst++ = ((*src & 0070) >> 3) + '0';			*dst++ = ((*src & 0007) >> 0) + '0';		} else if (*src == '\\') {			/* quote characters */			*dst++ = '\\';			*dst++ = '\\';		} else {			/* normal characters */			*dst++ = *src;		}		++src, --len;	}	*dst++ = 0;}struct scsi_quirk_inquiry_pattern {	struct scsi_inquiry_pattern pattern;	u_int16_t quirks;};struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {#ifndef PMON	{{T_CDROM, T_REMOV,	 "CHINON  ", "CD-ROM CDS-431  ", ""},     SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "Chinon  ", "CD-ROM CDS-525  ", ""},     SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "CHINON  ", "CD-ROM CDS-535  ", ""},     SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "DEC     ", "RRD42   (C) DEC ", ""},     SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "DENON   ", "DRD-25X         ", "V"},    SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "HP      ", "C4324/C4325     ", ""},     SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "IMS     ", "CDD521/10       ", "2.06"}, SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "MATSHITA", "CD-ROM CR-5XX   ", "1.0b"}, SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "MEDAVIS ", "RENO CD-ROMX2A  ", ""},	  SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "MEDIAVIS", "CDR-H93MV       ", "1.3"}, SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "NEC     ", "CD-ROM DRIVE:55 ", ""},     SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "NEC     ", "CD-ROM DRIVE:83 ", ""},     SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "NEC     ", "CD-ROM DRIVE:84 ", ""},     SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "NEC     ", "CD-ROM DRIVE:210", "1.0"},  SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "NEC     ", "CD-ROM DRIVE:501", ""},     SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "NEC     ", "CD-ROM DRIVE:841", ""},     SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "PIONEER ", "CD-ROM DR-124X  ", "1.01"}, SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "SONY    ", "CD-ROM CDU-541  ", ""},     SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "SONY    ", "CD-ROM CDU-55S  ", ""},     SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "SONY    ", "CD-ROM CDU-561  ", ""},     SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "SONY    ", "CD-ROM CDU-8003A", ""},     SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "SONY    ", "CD-ROM CDU-8012 ", ""},     SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "TEAC    ", "CD-ROM          ", "1.06"}, SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "TEAC    ", "CD-ROM CD-56S   ", "1.0B"}, SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "TEXEL   ", "CD-ROM          ", "1.06"}, SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "TEXEL   ", "CD-ROM DM-XX24 K", "1.10"}, SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "TOSHIBA ", "XM-4101TASUNSLCD", "1755"}, SDEV_NOLUNS},	{{T_CDROM, T_REMOV,  	 "ShinaKen", "CD-ROM DM-3x1S", "1.04"},   SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "JVC     ", "R2626           ", "1.55"}, SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "CyberDrv", "", ""}, SDEV_NOLUNS},	{{T_CDROM, T_REMOV,	 "PLEXTOR", "CD-ROM PX-40TS", "1.01"}, SDEV_NOSYNC}, 	{{T_OPTICAL, T_REMOV, 	 "EPSON   ", "OMD-5010        ", "3.08"}, SDEV_NOLUNS},	{{T_OPTICAL, T_REMOV,	 "FUJITSU", "M2513A",            "0800"}, SDEV_NOMODESENSE},	{{T_OPTICAL, T_REMOV,	 "DELTIS  ", "MOS321          ", "3.30"}, SDEV_NOMODESENSE}, 	{{T_OPTICAL, T_REMOV,	 "EPSON   ", "OMD-5010        ", "3.08"}, SDEV_NOLUNS},	{{T_OPTICAL, T_REMOV,	 "FUJITSU", "M2513A",            "0800"}, SDEV_NOMODESENSE},	{{T_OPTICAL, T_REMOV,	 "DELTIS  ", "MOS321          ", "3.30"}, SDEV_NOMODESENSE},	{{T_DIRECT, T_FIXED,	 "MICROP  ", "1588-15MBSUN0669", ""},     SDEV_AUTOSAVE},	{{T_DIRECT, T_FIXED,	 "DEC     ", "RZ55     (C) DEC", ""},     SDEV_AUTOSAVE},	{{T_DIRECT, T_FIXED,	 "EMULEX  ", "MD21/S2     ESDI", "A00"},  SDEV_FORCELUNS|SDEV_AUTOSAVE},	/* Gives non-media hardware failure in response to start-unit command */	{{T_DIRECT, T_FIXED,	 "HITACHI", "DK515C",            "CP15"}, SDEV_NOSTARTUNIT},	{{T_DIRECT, T_FIXED,	 "HITACHI", "DK515C",            "CP16"}, SDEV_NOSTARTUNIT},	{{T_DIRECT, T_FIXED,	 "IBMRAID ", "0662S",            ""},     SDEV_AUTOSAVE},	{{T_DIRECT, T_FIXED,	 "IBM     ", "0663H",            ""},     SDEV_AUTOSAVE},	{{T_DIRECT, T_FIXED,	 "IBM",	  "0664",		 ""},	  SDEV_AUTOSAVE},	{{T_DIRECT, T_FIXED,	 "IBM     ", "H3171-S2",         ""},	  SDEV_NOLUNS|SDEV_AUTOSAVE},	{{T_DIRECT, T_FIXED,	 "IBM     ", "KZ-C",		 ""},	  SDEV_AUTOSAVE},	/* Broken IBM disk */	{{T_DIRECT, T_FIXED,	 ""	   , "DFRSS2F",		 ""},	  SDEV_AUTOSAVE},	{{T_DIRECT, T_FIXED,	 "IBM"	   , "DDY",		 ""},	  SDEV_NOLUNS},	{{T_DIRECT, T_FIXED,	 "IBM"	   , "DPS",		 ""},	  SDEV_NOLUNS},	{{T_DIRECT, T_FIXED,	 "MAXTOR  ", "XT-3280         ", ""},     SDEV_NOLUNS},	{{T_DIRECT, T_FIXED,	 "MAXTOR  ", "XT-4380S        ", ""},     SDEV_NOLUNS},	{{T_DIRECT, T_FIXED,	 "MAXTOR  ", "MXT-1240S       ", ""},     SDEV_NOLUNS},	{{T_DIRECT, T_FIXED,	 "MAXTOR  ", "XT-4170S        ", ""},     SDEV_NOLUNS},	{{T_DIRECT, T_FIXED,	 "MAXTOR  ", "XT-8760S",	 ""},     SDEV_NOLUNS},	{{T_DIRECT, T_FIXED,	 "MAXTOR  ", "LXT-213S        ", ""},     SDEV_NOLUNS},

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -