[BACK]Return to consinit.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / arch / x86 / x86

Annotation of src/sys/arch/x86/x86/consinit.c, Revision 1.35

1.35    ! riastrad    1: /*     $NetBSD: consinit.c,v 1.34 2021/10/07 12:52:27 msaitoh Exp $    */
1.1       fvdl        2:
                      3: /*
                      4:  * Copyright (c) 1998
                      5:  *     Matthias Drochner.  All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  *
                     16:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     17:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     18:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     19:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     20:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     21:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     22:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     23:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     24:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     25:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     26:  *
                     27:  */
                     28:
                     29: #include <sys/cdefs.h>
1.35    ! riastrad   30: __KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.34 2021/10/07 12:52:27 msaitoh Exp $");
1.1       fvdl       31:
                     32: #include "opt_kgdb.h"
1.25      msaitoh    33: #include "opt_puc.h"
1.33      bouyer     34: #include "opt_xen.h"
1.1       fvdl       35:
                     36: #include <sys/param.h>
                     37: #include <sys/systm.h>
                     38: #include <sys/device.h>
1.22      dyoung     39: #include <sys/bus.h>
1.29      nonaka     40: #include <sys/cpu.h>
1.1       fvdl       41: #include <machine/bootinfo.h>
1.17      jmcneill   42: #include <arch/x86/include/genfb_machdep.h>
1.1       fvdl       43:
1.28      is         44: #include <dev/cons.h>
                     45:
                     46: #include "nullcons.h"
1.16      jmcneill   47: #include "genfb.h"
1.1       fvdl       48: #include "vga.h"
                     49: #include "ega.h"
                     50: #include "pcdisplay.h"
1.25      msaitoh    51: #include "com_puc.h"
1.1       fvdl       52: #if (NVGA > 0) || (NEGA > 0) || (NPCDISPLAY > 0)
                     53: #include <dev/ic/mc6845reg.h>
                     54: #include <dev/ic/pcdisplayvar.h>
                     55: #if (NVGA > 0)
                     56: #include <dev/ic/vgareg.h>
                     57: #include <dev/ic/vgavar.h>
                     58: #endif
                     59: #if (NEGA > 0)
                     60: #include <dev/isa/egavar.h>
                     61: #endif
                     62: #if (NPCDISPLAY > 0)
                     63: #include <dev/isa/pcdisplayvar.h>
                     64: #endif
                     65: #endif
                     66:
                     67: #include "pckbc.h"
                     68: #if (NPCKBC > 0)
                     69: #include <dev/isa/isareg.h>
                     70: #include <dev/ic/i8042reg.h>
                     71: #include <dev/ic/pckbcvar.h>
1.4       bjh21      72: #include <dev/pckbport/pckbportvar.h>
1.1       fvdl       73: #endif
                     74: #include "pckbd.h" /* for pckbc_machdep_cnattach */
                     75:
1.16      jmcneill   76: #if (NGENFB > 0)
                     77: #include <dev/wsfb/genfbvar.h>
                     78: #endif
                     79:
1.1       fvdl       80: #include "com.h"
                     81: #if (NCOM > 0)
                     82: #include <sys/termios.h>
                     83: #include <dev/ic/comreg.h>
                     84: #include <dev/ic/comvar.h>
                     85: #endif
1.25      msaitoh    86: #if (NCOM_PUC > 0)
                     87: #include <dev/pci/puccn.h>
                     88: #endif
1.1       fvdl       89:
                     90: #include "ukbd.h"
                     91: #if (NUKBD > 0)
                     92: #include <dev/usb/ukbdvar.h>
                     93: #endif
                     94:
1.32      bouyer     95: #ifndef XENPV
1.31      nonaka     96: #include "hvkbd.h"
1.30      christos   97: #if NHVKBD > 0
1.29      nonaka     98: #include <dev/hyperv/hvkbdvar.h>
                     99: #endif
                    100: #endif
                    101:
1.33      bouyer    102: #ifdef XENPVHVM
                    103: #include <xen/xen.h>
                    104: #endif
                    105:
1.1       fvdl      106: #ifndef CONSDEVNAME
                    107: #define CONSDEVNAME "pc"
                    108: #endif
                    109:
                    110: #if (NCOM > 0)
                    111: #ifndef CONADDR
                    112: #define CONADDR 0x3f8
                    113: #endif
                    114: #ifndef CONSPEED
                    115: #define CONSPEED TTYDEF_SPEED
                    116: #endif
                    117: #ifndef CONMODE
                    118: #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
                    119: #endif
                    120: int comcnmode = CONMODE;
                    121: #endif /* NCOM */
                    122:
                    123: const struct btinfo_console default_consinfo = {
                    124:        {0, 0},
                    125:        CONSDEVNAME,
                    126: #if (NCOM > 0)
                    127:        CONADDR, CONSPEED
                    128: #else
                    129:        0, 0
                    130: #endif
                    131: };
                    132:
                    133: #ifdef KGDB
                    134: #ifndef KGDB_DEVNAME
                    135: #define KGDB_DEVNAME "com"
                    136: #endif
                    137: const char kgdb_devname[] = KGDB_DEVNAME;
                    138:
                    139: #if (NCOM > 0)
                    140: #ifndef KGDB_DEVADDR
                    141: #define KGDB_DEVADDR 0x3f8
                    142: #endif
                    143: int comkgdbaddr = KGDB_DEVADDR;
                    144: #ifndef KGDB_DEVRATE
                    145: #define KGDB_DEVRATE TTYDEF_SPEED
                    146: #endif
                    147: int comkgdbrate = KGDB_DEVRATE;
                    148: #ifndef KGDB_DEVMODE
                    149: #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
                    150: #endif
                    151: int comkgdbmode = KGDB_DEVMODE;
                    152: #endif /* NCOM */
                    153:
                    154: #endif /* KGDB */
                    155:
                    156: /*
                    157:  * consinit:
                    158:  * initialize the system console.
                    159:  * XXX - shouldn't deal with this initted thing, but then,
                    160:  * it shouldn't be called from init386 either.
                    161:  */
                    162: void
1.19      cegger    163: consinit(void)
1.1       fvdl      164: {
                    165:        const struct btinfo_console *consinfo;
1.27      martin    166: #if (NGENFB > 0)
1.16      jmcneill  167:        const struct btinfo_framebuffer *fbinfo;
1.27      martin    168: #endif
1.1       fvdl      169:        static int initted;
1.26      taca      170: #if (NCOM > 0)
1.25      msaitoh   171:        int rv;
1.26      taca      172: #endif
1.1       fvdl      173:
1.33      bouyer    174: #ifdef XENPVHVM
                    175:        if (vm_guest == VM_GUEST_XENPVH) {
                    176:                xen_pvh_consinit();
                    177:                return;
                    178:        }
                    179: #endif
1.1       fvdl      180:        if (initted)
                    181:                return;
                    182:        initted = 1;
                    183:
                    184: #ifndef CONS_OVERRIDE
                    185:        consinfo = lookup_bootinfo(BTINFO_CONSOLE);
                    186:        if (!consinfo)
                    187: #endif
                    188:                consinfo = &default_consinfo;
                    189:
1.27      martin    190: #if (NGENFB > 0)
1.16      jmcneill  191:        fbinfo = lookup_bootinfo(BTINFO_FRAMEBUFFER);
1.27      martin    192: #endif
1.16      jmcneill  193:
1.1       fvdl      194:        if (!strcmp(consinfo->devname, "pc")) {
1.6       augustss  195:                int error;
1.16      jmcneill  196: #if (NGENFB > 0)
                    197:                if (fbinfo && fbinfo->physaddr > 0) {
1.35    ! riastrad  198:                        /*
        !           199:                         * If we have a framebuffer address, and
        !           200:                         * x86_genfb_cnattach can map it, then
        !           201:                         * genfb_cnattach causes genfb_is_console to
        !           202:                         * later return true.  device_pci_register will
        !           203:                         * use this to set up the device properties for
        !           204:                         * a PCI display-class device to notify it that
        !           205:                         * it has been selected as the console.
        !           206:                         */
1.17      jmcneill  207:                        if (x86_genfb_cnattach() == -1) {
                    208:                                initted = 0;    /* defer */
                    209:                                return;
                    210:                        }
1.16      jmcneill  211:                        genfb_cnattach();
                    212:                        goto dokbd;
1.17      jmcneill  213:                }
                    214:                genfb_disable();
1.16      jmcneill  215: #endif
1.1       fvdl      216: #if (NVGA > 0)
1.21      dyoung    217:                if (!vga_cnattach(x86_bus_space_io, x86_bus_space_mem,
1.1       fvdl      218:                                  -1, 1))
                    219:                        goto dokbd;
                    220: #endif
                    221: #if (NEGA > 0)
1.21      dyoung    222:                if (!ega_cnattach(x86_bus_space_io, x86_bus_space_mem))
1.1       fvdl      223:                        goto dokbd;
                    224: #endif
                    225: #if (NPCDISPLAY > 0)
1.21      dyoung    226:                if (!pcdisplay_cnattach(x86_bus_space_io, x86_bus_space_mem))
1.1       fvdl      227:                        goto dokbd;
                    228: #endif
                    229:                if (0) goto dokbd; /* XXX stupid gcc */
                    230: dokbd:
1.7       augustss  231:                error = ENODEV;
1.1       fvdl      232: #if (NPCKBC > 0)
1.21      dyoung    233:                error = pckbc_cnattach(x86_bus_space_io, IO_KBD, KBCMDP,
1.24      jdc       234:                    PCKBC_KBD_SLOT, 0);
1.1       fvdl      235: #endif
1.29      nonaka    236: #if (NHVKBD > 0)
                    237:                if (error && vm_guest == VM_GUEST_HV)
                    238:                        error = hvkbd_cnattach();
                    239: #endif
1.5       augustss  240: #if (NUKBD > 0)
                    241:                if (error)
1.7       augustss  242:                        error = ukbd_cnattach();
1.1       fvdl      243: #endif
1.7       augustss  244:                if (error)
                    245:                        printf("WARNING: no console keyboard, error=%d\n",
                    246:                               error);
1.1       fvdl      247:                return;
                    248:        }
                    249: #if (NCOM > 0)
                    250:        if (!strcmp(consinfo->devname, "com")) {
1.9       jmmv      251:                int addr = consinfo->addr;
                    252:                int speed = consinfo->speed;
1.1       fvdl      253:
1.25      msaitoh   254: #if (NCOM_PUC > 0) && defined(PUC_CNAUTO)
                    255:                puc_cnprobe(NULL);
                    256:                rv = puc_cninit(NULL);
                    257:                if (rv == 0)
                    258:                        return;
                    259: #endif
                    260:
1.9       jmmv      261:                if (addr == 0)
                    262:                        addr = CONADDR;
                    263:                if (speed == 0)
                    264:                        speed = CONSPEED;
                    265:
1.25      msaitoh   266:                rv = comcnattach(x86_bus_space_io, addr, speed,
                    267:                                 COM_FREQ, COM_TYPE_NORMAL, comcnmode);
                    268:                if (rv != 0)
1.1       fvdl      269:                        panic("can't init serial console @%x", consinfo->addr);
                    270:                return;
                    271:        }
                    272: #endif
1.28      is        273: #if (NNULLCONS > 0)
                    274:        if (!strcmp(consinfo->devname, "nullcons")) {
                    275:                void nullcninit(struct consdev *cn);
                    276:
                    277:                nullcninit(0);
                    278:                return;
                    279:        }
                    280: #endif
1.1       fvdl      281:        panic("invalid console device %s", consinfo->devname);
                    282: }
                    283:
                    284: #ifdef KGDB
                    285: void
1.20      cegger    286: kgdb_port_init(void)
1.1       fvdl      287: {
                    288: #if (NCOM > 0)
1.34      msaitoh   289:        if (!strcmp(kgdb_devname, "com")) {
1.21      dyoung    290:                com_kgdb_attach(x86_bus_space_io, comkgdbaddr, comkgdbrate,
                    291:                    COM_FREQ, COM_TYPE_NORMAL, comkgdbmode);
1.1       fvdl      292:        }
                    293: #endif
                    294: }
                    295: #endif

CVSweb <webmaster@jp.NetBSD.org>