1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * "PROM" interface
  29  */
  30 
  31 #include <sys/types.h>
  32 #include <sys/promif.h>
  33 
  34 #include <kmdb/kmdb_promif_impl.h>
  35 #include <kmdb/kmdb_kdi.h>
  36 #include <kmdb/kmdb_dpi.h>
  37 #include <mdb/mdb_err.h>
  38 #include <mdb/mdb_debug.h>
  39 #include <mdb/mdb_string.h>
  40 #include <mdb/mdb.h>
  41 
  42 struct boot_syscalls *kmdb_sysp;
  43 
  44 ssize_t
  45 kmdb_prom_obp_writer(caddr_t buf, size_t len)
  46 {
  47         int i;
  48 
  49         for (i = 0; i < len; i++)
  50                 prom_putchar(*buf++);
  51 
  52         return (len);
  53 }
  54 
  55 /*ARGSUSED*/
  56 ihandle_t
  57 kmdb_prom_get_handle(char *name)
  58 {
  59         /* no handles here */
  60         return (0);
  61 }
  62 
  63 char *
  64 kmdb_prom_get_ddi_prop(kmdb_auxv_t *kav, char *propname)
  65 {
  66         int i;
  67 
  68         if (kav->kav_pcache != NULL) {
  69                 for (i = 0; i < kav->kav_nprops; i++) {
  70                         kmdb_auxv_nv_t *nv = &kav->kav_pcache[i];
  71                         if (strcmp(nv->kanv_name, propname) == 0)
  72                                 return (nv->kanv_val);
  73                 }
  74         }
  75 
  76         return (NULL);
  77 }
  78 
  79 /*ARGSUSED*/
  80 void
  81 kmdb_prom_free_ddi_prop(char *val)
  82 {
  83 }
  84 
  85 /*
  86  * This function is actually about checking if we are using
  87  * local console versus serial console. Serial console can be named
  88  * "ttyX" where X is [a-d], or "usb-serial".
  89  */
  90 int
  91 kmdb_prom_stdout_is_framebuffer(kmdb_auxv_t *kav)
  92 {
  93         char *dev;
  94 
  95         /*
  96          * The property "output-device" value is set in property cache, and
  97          * is based on either "output-device" or "console" properties from
  98          * the actual system. We can't use the official promif version, as we
  99          * need to ensure that property lookups come from our property cache.
 100          */
 101 
 102         if ((dev = kmdb_prom_get_ddi_prop(kav, "output-device")) == NULL)
 103                 return (0);
 104 
 105         if (strncmp(dev, "tty", 3) == 0)
 106                 return (0);
 107         if (strcmp(dev, "usb-serial") == 0)
 108                 return (0);
 109 
 110         /* Anything else is classified as local console. */
 111         return (1);
 112 }