root/arch/sparc/prom/console.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. prom_nbgetchar
  2. prom_nbputchar
  3. prom_getchar
  4. prom_putchar
  5. prom_query_input_device
  6. prom_query_output_device

   1 /* $Id: console.c,v 1.6 1996/01/01 02:46:27 davem Exp $
   2  * console.c: Routines that deal with sending and receiving IO
   3  *            to/from the current console device using the PROM.
   4  *
   5  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
   6  */
   7 
   8 #include <asm/openprom.h>
   9 #include <asm/oplib.h>
  10 #include <linux/string.h>
  11 
  12 /* Non blocking get character from console input device, returns -1
  13  * if no input was taken.  This can be used for polling.
  14  */
  15 int
  16 prom_nbgetchar(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  17 {
  18         static char inc;
  19 
  20         switch(prom_vers) {
  21         case PROM_V0:
  22                 return (*(romvec->pv_nbgetchar))();
  23                 break;
  24         case PROM_V2:
  25         case PROM_V3:
  26         case PROM_P1275:
  27                 if( (*(romvec->pv_v2devops).v2_dev_read)(*romvec->pv_v2bootargs.fd_stdin , &inc, 0x1) == 1)
  28                         return inc;
  29                 return -1;
  30                 break;
  31         };
  32         return 0; /* Ugh, we could spin forever on unsupported proms ;( */
  33 }
  34 
  35 /* Non blocking put character to console device, returns -1 if
  36  * unsuccessful.
  37  */
  38 int
  39 prom_nbputchar(char c)
     /* [previous][next][first][last][top][bottom][index][help] */
  40 {
  41         static char outc;
  42 
  43         switch(prom_vers) {
  44         case PROM_V0:
  45                 return (*(romvec->pv_nbputchar))(c);
  46                 break;
  47         case PROM_V2:
  48         case PROM_V3:
  49         case PROM_P1275:
  50                 outc = c;
  51                 if( (*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout, &outc, 0x1) == 1)
  52                         return 0;
  53                 return -1;
  54                 break;
  55         };
  56         return 0; /* Ugh, we could spin forever on unsupported proms ;( */
  57 }
  58 
  59 /* Blocking version of get character routine above. */
  60 char
  61 prom_getchar(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  62 {
  63         int character;
  64         while((character = prom_nbgetchar()) == -1) ;
  65         return (char) character;
  66 }
  67 
  68 /* Blocking version of put character routine above. */
  69 void
  70 prom_putchar(char c)
     /* [previous][next][first][last][top][bottom][index][help] */
  71 {
  72         while(prom_nbputchar(c) == -1) ;
  73         return;
  74 }
  75 
  76 /* Query for input device type */
  77 enum prom_input_device
  78 prom_query_input_device()
     /* [previous][next][first][last][top][bottom][index][help] */
  79 {
  80         int st_p;
  81         char propb[64];
  82         char *p;
  83 
  84         switch(prom_vers) {
  85         case PROM_V0:
  86         case PROM_V2:
  87         default:
  88                 switch(*romvec->pv_stdin) {
  89                 case PROMDEV_KBD:       return PROMDEV_IKBD;
  90                 case PROMDEV_TTYA:      return PROMDEV_ITTYA;
  91                 case PROMDEV_TTYB:      return PROMDEV_ITTYB;
  92                 default:
  93                         return PROMDEV_I_UNK;
  94                 };
  95         case PROM_V3:
  96         case PROM_P1275:
  97                 st_p = (*romvec->pv_v2devops.v2_inst2pkg)(*romvec->pv_v2bootargs.fd_stdin);
  98                 if(prom_node_has_property(st_p, "keyboard"))
  99                         return PROMDEV_IKBD;
 100                 prom_getproperty(st_p, "device_type", propb, sizeof(propb));
 101                 if(strncmp(propb, "serial", sizeof("serial")))
 102                         return PROMDEV_I_UNK;
 103                 prom_getproperty(prom_root_node, "stdin-path", propb, sizeof(propb));
 104                 p = propb;
 105                 while(*p) p++; p -= 2;
 106                 if(p[0] == ':') {
 107                         if(p[1] == 'a')
 108                                 return PROMDEV_ITTYA;
 109                         else if(p[1] == 'b')
 110                                 return PROMDEV_ITTYB;
 111                 }
 112                 return PROMDEV_I_UNK;
 113         };
 114 }
 115 
 116 /* Query for output device type */
 117 
 118 enum prom_output_device
 119 prom_query_output_device()
     /* [previous][next][first][last][top][bottom][index][help] */
 120 {
 121         int st_p;
 122         char propb[64];
 123         char *p;
 124         int propl;
 125 
 126         switch(prom_vers) {
 127         case PROM_V0:
 128                 switch(*romvec->pv_stdin) {
 129                 case PROMDEV_SCREEN:    return PROMDEV_OSCREEN;
 130                 case PROMDEV_TTYA:      return PROMDEV_OTTYA;
 131                 case PROMDEV_TTYB:      return PROMDEV_OTTYB;
 132                 };
 133                 break;
 134         case PROM_V2:
 135         case PROM_V3:
 136         case PROM_P1275:
 137                 st_p = (*romvec->pv_v2devops.v2_inst2pkg)(*romvec->pv_v2bootargs.fd_stdout);
 138                 propl = prom_getproperty(st_p, "device_type", propb, sizeof(propb));
 139                 if (propl >= 0 && propl == sizeof("display") &&
 140                         strncmp("display", propb, sizeof("display")) == 0)
 141                 {
 142                         return PROMDEV_OSCREEN;
 143                 }
 144                 if(prom_vers == PROM_V3) {
 145                         if(strncmp("serial", propb, sizeof("serial")))
 146                                 return PROMDEV_O_UNK;
 147                         prom_getproperty(prom_root_node, "stdout-path", propb, sizeof(propb));
 148                         p = propb;
 149                         while(*p) p++; p -= 2;
 150                         if(p[0]==':') {
 151                                 if(p[1] == 'a')
 152                                         return PROMDEV_OTTYA;
 153                                 else if(p[1] == 'b')
 154                                         return PROMDEV_OTTYB;
 155                         }
 156                         return PROMDEV_O_UNK;
 157                 } else {
 158                         /* This works on SS-2 (an early OpenFirmware) still. */
 159                         switch(*romvec->pv_stdin) {
 160                         case PROMDEV_TTYA:      return PROMDEV_OTTYA;
 161                         case PROMDEV_TTYB:      return PROMDEV_OTTYB;
 162                         };
 163                 }
 164                 break;
 165         };
 166         return PROMDEV_O_UNK;
 167 }

/* [previous][next][first][last][top][bottom][index][help] */