[BACK]Return to autoconf.c CVS log [TXT][DIR] Up to [local] / sys / arch / macppc / macppc

Annotation of sys/arch/macppc/macppc/autoconf.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: autoconf.c,v 1.33 2007/06/01 23:14:06 deraadt Exp $   */
        !             2: /*
        !             3:  * Copyright (c) 1996, 1997 Per Fogelstrom
        !             4:  * Copyright (c) 1995 Theo de Raadt
        !             5:  * Copyright (c) 1988 University of Utah.
        !             6:  * Copyright (c) 1992, 1993
        !             7:  *     The Regents of the University of California.  All rights reserved.
        !             8:  *
        !             9:  * This code is derived from software contributed to Berkeley by
        !            10:  * the Systems Programming Group of the University of Utah Computer
        !            11:  * Science Department and Ralph Campbell.
        !            12:  *
        !            13:  * Redistribution and use in source and binary forms, with or without
        !            14:  * modification, are permitted provided that the following conditions
        !            15:  * are met:
        !            16:  * 1. Redistributions of source code must retain the above copyright
        !            17:  *    notice, this list of conditions and the following disclaimer.
        !            18:  * 2. Redistributions in binary form must reproduce the above copyright
        !            19:  *    notice, this list of conditions and the following disclaimer in the
        !            20:  *    documentation and/or other materials provided with the distribution.
        !            21:  * 3. Neither the name of the University nor the names of its contributors
        !            22:  *    may be used to endorse or promote products derived from this software
        !            23:  *    without specific prior written permission.
        !            24:  *
        !            25:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            26:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            27:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            28:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            29:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            30:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            31:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            32:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            33:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            34:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            35:  * SUCH DAMAGE.
        !            36:  *
        !            37:  * from: Utah Hdr: autoconf.c 1.31 91/01/21
        !            38:  *
        !            39:  *     from: @(#)autoconf.c    8.1 (Berkeley) 6/10/93
        !            40:  *      $Id: autoconf.c,v 1.33 2007/06/01 23:14:06 deraadt Exp $
        !            41:  */
        !            42:
        !            43: /*
        !            44:  * Setup the system to run on the current machine.
        !            45:  *
        !            46:  * cpu_configure() is called at boot time.  Available
        !            47:  * devices are determined (from possibilities mentioned in ioconf.c),
        !            48:  * and the drivers are initialized.
        !            49:  */
        !            50:
        !            51: #include <sys/param.h>
        !            52: #include <sys/systm.h>
        !            53: #include <sys/buf.h>
        !            54: #include <sys/disklabel.h>
        !            55: #include <sys/conf.h>
        !            56: #include <sys/reboot.h>
        !            57: #include <sys/device.h>
        !            58: #include <dev/cons.h>
        !            59: #include <uvm/uvm_extern.h>
        !            60: #include <machine/autoconf.h>
        !            61: #include <machine/powerpc.h>
        !            62:
        !            63: #include <sys/disk.h>
        !            64: #include <scsi/scsi_all.h>
        !            65: #include <scsi/scsi_disk.h>
        !            66: #include <scsi/scsiconf.h>
        !            67: #include <scsi/sdvar.h>
        !            68:
        !            69: void   dumpconf(void);
        !            70: struct device *getdevunit(char *, int);
        !            71: static struct devmap *findtype(char **);
        !            72: void   makebootdev(char *cp);
        !            73: int    getpno(char **);
        !            74:
        !            75: /*
        !            76:  * The following several variables are related to
        !            77:  * the configuration process, and are used in initializing
        !            78:  * the machine.
        !            79:  */
        !            80: int    cold = 1;       /* if 1, still working on cold-start */
        !            81: char   bootdev[16];    /* to hold boot dev name */
        !            82: struct device *bootdv = NULL;
        !            83:
        !            84: struct dumpmem dumpmem[VM_PHYSSEG_MAX];
        !            85: u_int ndumpmem;
        !            86:
        !            87: /*
        !            88:  *  Configure all devices found that we know about.
        !            89:  *  This is done at boot time.
        !            90:  */
        !            91: void
        !            92: cpu_configure()
        !            93: {
        !            94:        (void)splhigh();        /* To be really sure.. */
        !            95:        calc_delayconst();
        !            96:
        !            97:        if (config_rootfound("mainbus", "mainbus") == 0)
        !            98:                panic("no mainbus found");
        !            99:        (void)spl0();
        !           100:        cold = 0;
        !           101: }
        !           102:
        !           103: struct devmap {
        !           104:        char *att;
        !           105:        char *dev;
        !           106:        int   type;
        !           107: };
        !           108: #define        T_IFACE 0x10
        !           109:
        !           110: #define        T_BUS   0x00
        !           111: #define        T_SCSI  0x11
        !           112: #define        T_IDE   0x12
        !           113: #define        T_DISK  0x21
        !           114:
        !           115: static struct devmap *
        !           116: findtype(char **s)
        !           117: {
        !           118:        static struct devmap devmap[] = {
        !           119:                { "/ht",                NULL, T_BUS },
        !           120:                { "/ht@",               NULL, T_BUS },
        !           121:                { "/pci@",              NULL, T_BUS },
        !           122:                { "/pci",               NULL, T_BUS },
        !           123:                { "/AppleKiwi@",        NULL, T_BUS },
        !           124:                { "/AppleKiwi",         NULL, T_BUS },
        !           125:                { "/mac-io@",           NULL, T_BUS },
        !           126:                { "/mac-io",            NULL, T_BUS },
        !           127:                { "/@",                 NULL, T_BUS },
        !           128:                { "/LSILogic,sas@",     "sd", T_SCSI },
        !           129:                { "/scsi@",             "sd", T_SCSI },
        !           130:                { "/ide",               "wd", T_IDE },
        !           131:                { "/ata",               "wd", T_IDE },
        !           132:                { "/k2-sata-root",      NULL, T_BUS },
        !           133:                { "/k2-sata",           "wd", T_IDE },
        !           134:                { "/disk@",             "sd", T_DISK },
        !           135:                { "/disk",              "wd", T_DISK },
        !           136:                { "/usb@",              "sd", T_SCSI },
        !           137:                { "/ADPT,2940U2B@",     "sd", T_SCSI },
        !           138:                { "/bcom5704@4",        "bge0", T_IFACE },
        !           139:                { "/bcom5704@4,1",      "bge1", T_IFACE },
        !           140:                { "/ethernet",          "gem0", T_IFACE },
        !           141:                { NULL, NULL }
        !           142:        };
        !           143:        struct devmap *dp = &devmap[0];
        !           144:
        !           145:        while (dp->att) {
        !           146:                if (strncmp(*s, dp->att, strlen(dp->att)) == 0) {
        !           147:                        *s += strlen(dp->att);
        !           148:                        break;
        !           149:                }
        !           150:                dp++;
        !           151:        }
        !           152:        if (dp->att == NULL)
        !           153:                printf("string [%s] not found\n", *s);
        !           154:
        !           155:        return(dp);
        !           156: }
        !           157:
        !           158: /*
        !           159:  * Look at the string 'bp' and decode the boot device.
        !           160:  * Boot names look like: '/pci/scsi@c/disk@0,0/bsd'
        !           161:  *                       '/pci/mac-io/ide@20000/disk@0,0/bsd
        !           162:  *                       '/pci/mac-io/ide/disk/bsd
        !           163:  *                      '/ht@0,f2000000/pci@2/bcom5704@4/bsd'
        !           164:  */
        !           165: void
        !           166: makebootdev(char *bp)
        !           167: {
        !           168:        int     unit, ptype;
        !           169:        char   *dev, *cp;
        !           170:        struct devmap *dp;
        !           171:
        !           172:        cp = bp;
        !           173:        do {
        !           174:                while(*cp && *cp != '/')
        !           175:                        cp++;
        !           176:
        !           177:                dp = findtype(&cp);
        !           178:                if (!dp->att) {
        !           179:                        printf("Warning: bootpath unrecognized: %s\n", bp);
        !           180:                        return;
        !           181:                }
        !           182:        } while((dp->type & T_IFACE) == 0);
        !           183:
        !           184:        if (dp->att && dp->type == T_IFACE) {
        !           185:                snprintf(bootdev, sizeof bootdev, "%s", dp->dev);
        !           186:                return;
        !           187:        }
        !           188:        dev = dp->dev;
        !           189:        while(*cp && *cp != '/')
        !           190:                cp++;
        !           191:        ptype = dp->type;
        !           192:        dp = findtype(&cp);
        !           193:        if (dp->att && dp->type == T_DISK) {
        !           194:                unit = getpno(&cp);
        !           195:                if (ptype == T_SCSI) {
        !           196:                        struct device *dv;
        !           197:                        struct sd_softc *sd;
        !           198:
        !           199:                        TAILQ_FOREACH(dv, &alldevs, dv_list) {
        !           200:                                if (dv->dv_class != DV_DISK ||
        !           201:                                    strcmp(dv->dv_cfdata->cf_driver->cd_name, "sd"))
        !           202:                                        continue;
        !           203:                                sd = (struct sd_softc *)dv;
        !           204:                                if (sd->sc_link->target != unit)
        !           205:                                        continue;
        !           206:                                snprintf(bootdev, sizeof bootdev,
        !           207:                                    "%s%c", dv->dv_xname, 'a');
        !           208:                                return;
        !           209:                        }
        !           210:                }
        !           211:                snprintf(bootdev, sizeof bootdev, "%s%d%c", dev, unit, 'a');
        !           212:                return;
        !           213:        }
        !           214:        printf("Warning: boot device unrecognized: %s\n", bp);
        !           215: }
        !           216:
        !           217: int
        !           218: getpno(char **cp)
        !           219: {
        !           220:        int val = 0, digit;
        !           221:        char *cx = *cp;
        !           222:
        !           223:        while (*cx) {
        !           224:                if (*cx >= '0' && *cx <= '9')
        !           225:                        digit = *cx - '0';
        !           226:                else if (*cx >= 'a' && *cx <= 'f')
        !           227:                        digit = *cx - 'a' + 0x0a;
        !           228:                else
        !           229:                        break;
        !           230:                val = val * 16 + digit;
        !           231:                cx++;
        !           232:        }
        !           233:        *cp = cx;
        !           234:        return (val);
        !           235: }
        !           236:
        !           237: void
        !           238: device_register(struct device *dev, void *aux)
        !           239: {
        !           240: }
        !           241:
        !           242: /*
        !           243:  * find a device matching "name" and unit number
        !           244:  */
        !           245: struct device *
        !           246: getdevunit(char *name, int unit)
        !           247: {
        !           248:        struct device *dev = TAILQ_FIRST(&alldevs);
        !           249:        char num[10], fullname[16];
        !           250:        int lunit;
        !           251:
        !           252:        /* compute length of name and decimal expansion of unit number */
        !           253:        snprintf(num, sizeof num, "%d", unit);
        !           254:        lunit = strlen(num);
        !           255:        if (strlen(name) + lunit >= sizeof(fullname) - 1)
        !           256:                panic("config_attach: device name too long");
        !           257:
        !           258:        strlcpy(fullname, name, sizeof fullname);
        !           259:        strlcat(fullname, num, sizeof fullname);
        !           260:
        !           261:        while (strcmp(dev->dv_xname, fullname) != 0)
        !           262:                if ((dev = TAILQ_NEXT(dev, dv_list)) == NULL)
        !           263:                        return NULL;
        !           264:
        !           265:        return dev;
        !           266: }
        !           267:
        !           268: /*
        !           269:  * Now that we are fully operational, we can checksum the
        !           270:  * disks, and using some heuristics, hopefully are able to
        !           271:  * always determine the correct root disk.
        !           272:  */
        !           273: void
        !           274: diskconf(void)
        !           275: {
        !           276:        dev_t temp;
        !           277:        int part = 0;
        !           278:
        !           279:        printf("bootpath: %s\n", bootpath);
        !           280:        makebootdev(bootpath);
        !           281:
        !           282:        /* Lookup boot device from boot if not set by configuration */
        !           283:        bootdv = parsedisk(bootdev, strlen(bootdev), 0, &temp);
        !           284:        setroot(bootdv, part, RB_USERREQ);
        !           285:        dumpconf();
        !           286: }
        !           287:
        !           288: struct nam2blk nam2blk[] = {
        !           289:        { "wd",         0 },
        !           290:        { "sd",         2 },
        !           291:        { "raid",       19 },
        !           292:        { NULL,         -1 }
        !           293: };

CVSweb