Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / hp700 / stand / common / dev_hppa.c
blob600df65fa8aa941417cc6ce5a07eb3616d9287db
1 /* $NetBSD: dev_hppa.c,v 1.11 2009/05/08 09:33:59 skrll Exp $ */
3 /* $OpenBSD: dev_hppa.c,v 1.5 1999/04/20 20:01:01 mickey Exp $ */
5 /*
6 * Copyright (c) 1998-2004 Michael Shalayeff
7 * All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
32 #include "libsa.h"
33 #include <sys/param.h>
34 #include <sys/disklabel.h>
35 #include <sys/reboot.h>
36 #include <dev/cons.h>
38 #include <machine/iomod.h>
40 #include "dev_hppa.h"
42 extern int debug;
44 const char cdevs[][4] = {
45 "ite", "", "", "", "", "", "", "",
46 "", "", "", "", ""
48 const int ncdevs = NENTS(cdevs);
50 const struct pdc_devs {
51 char name[3];
52 int dev_type;
53 } pdc_devs[] = {
54 { "dk", 0 },
55 { "ct", 1 },
56 { "lf", 2 },
57 { "", -1 },
58 { "rd", -1 },
59 { "sw", -1 },
60 { "fl", -1 },
63 /* pass dev_t to the open routines */
64 int
65 devopen(struct open_file *f, const char *fname, char **file)
67 struct hppa_dev *hpd;
68 const struct pdc_devs *dp = pdc_devs;
69 int bdev, badapt, bctlr, bunit, bpart;
70 unsigned long n;
71 char *p;
72 int rc = 1;
74 if (!(*file = strchr(fname, ':')))
75 return ENODEV;
76 else
77 (*file)++;
79 #ifdef DEBUGBUG
80 if (debug)
81 printf("devopen: ");
82 #endif
84 for (dp = pdc_devs; dp < &pdc_devs[NENTS(pdc_devs)]; dp++)
85 if (!strncmp(fname, dp->name, sizeof(dp->name)-1))
86 break;
88 if (dp >= &pdc_devs[NENTS(pdc_devs)] || dp->dev_type < 0)
89 return ENODEV;
90 bdev = dp->dev_type;
91 n = strtoul(fname + sizeof(dp->name)-1, &p, 10);
92 if (n == ULONG_MAX)
93 return ENODEV;
94 bunit = n & 0xf;
95 bctlr = (n >> 4) & 0xf;
96 badapt = (n >> 8) & 0xf;
97 if (*p >= 'a' && *p < 'a' + MAXPARTITIONS) {
98 bpart = *p - 'a';
99 } else {
100 bpart = 0;
102 bootdev = MAKEBOOTDEV(bdev, badapt, bctlr, bunit, bpart);
104 #ifdef DEBUGBUG
105 if (debug)
106 printf("%s\n", dp->name);
107 #endif
109 if (!(hpd = alloc(sizeof *hpd))) {
110 #ifdef DEBUG
111 printf ("devopen: no mem\n");
112 #endif
113 } else {
114 memset(hpd, 0, sizeof *hpd);
115 hpd->bootdev = bootdev;
116 hpd->buf = (char *)(((u_int)hpd->ua_buf + IODC_MINIOSIZ-1) &
117 ~(IODC_MINIOSIZ-1));
118 f->f_devdata = hpd;
119 if ((rc = (*devsw[dp->dev_type].dv_open)(f, file)) == 0) {
120 f->f_dev = &devsw[dp->dev_type];
121 return 0;
123 dealloc (hpd, 0);
124 f->f_devdata = NULL;
127 if (!(f->f_flags & F_NODEV))
128 f->f_dev = &devsw[dp->dev_type];
130 if (!f->f_devdata)
131 *file = NULL;
133 return rc;
136 void
137 devboot(btdev_t dev, char *p)
139 const char *q;
140 if (!dev) {
141 int type, unit;
143 switch (PAGE0->mem_boot.pz_class) {
144 case PCL_RANDOM:
145 type = 0;
146 unit = PAGE0->mem_boot.pz_layers[0];
147 break;
148 case PCL_SEQU:
149 type = 1;
150 unit = PAGE0->mem_boot.pz_layers[0];
151 break;
152 case PCL_NET_MASK|PCL_SEQU:
153 type = 2;
154 unit = 0;
155 break;
156 default:
157 type = 0;
158 unit = 0;
159 break;
161 dev = bootdev = MAKEBOOTDEV(type, 0, 0, unit, 0);
163 #ifdef _TEST
164 *p++ = '/';
165 *p++ = 'd';
166 *p++ = 'e';
167 *p++ = 'v';
168 *p++ = '/';
169 *p++ = 'r';
170 #endif
171 /* quick copy device name */
172 for (q = pdc_devs[B_TYPE(dev)].name; (*p++ = *q++););
173 p[-1] = '0' + B_UNIT(dev);
174 *p++ = 'a' + B_PARTITION(dev);
175 *p = '\0';
178 int pch_pos;
180 void
181 putchar(int c)
183 switch(c) {
184 case '\177': /* DEL erases */
185 cnputc('\b');
186 cnputc(' ');
187 case '\b':
188 cnputc('\b');
189 if (pch_pos)
190 pch_pos--;
191 break;
192 case '\t':
194 cnputc(' ');
195 while(++pch_pos % 8);
196 break;
197 case '\n':
199 * XXX fredette - probably only necessary
200 * when using a serial console?
202 cnputc(c);
203 c = '\r';
204 /* FALLTHROUGH */
205 case '\r':
206 cnputc(c);
207 pch_pos=0;
208 break;
209 default:
210 cnputc(c);
211 pch_pos++;
212 break;
217 getchar(void)
219 int c = cngetc();
221 if (c == '\r')
222 c = '\n';
224 if ((c < ' ' && c != '\n') || c == '\177')
225 return(c);
228 * XXX fredette - probably only unnecessary
229 * when using a serial console?
231 #if 0
232 putchar(c);
233 #endif
235 return(c);
239 tgetchar(void)
241 int c;
243 if ((c = tcngetc()) == 0)
244 return(0);
245 return(getchar());
248 #if 0
249 char ttyname_buf[8];
250 char *
251 ttyname(int fd)
253 sprintf(ttyname_buf, "%s%d", cdevs[major(cn_tab->cn_dev)],
254 minor(cn_tab->cn_dev));
255 return (ttyname_buf);
258 dev_t
259 ttydev(char *name)
261 int i, unit = -1;
262 char *no = name + strlen(name) - 1;
264 while (no >= name && *no >= '0' && *no <= '9')
265 unit = (unit < 0 ? 0 : (unit * 10)) + *no-- - '0';
266 if (no < name || unit < 0)
267 return (NODEV);
268 for (i = 0; i < ncdevs; i++)
269 if (strncmp(name, cdevs[i], no - name + 1) == 0)
270 return (makedev(i, unit));
271 return (NODEV);
273 #endif