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