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 $ */
6 * Copyright (c) 1998-2004 Michael Shalayeff
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
33 #include <sys/param.h>
34 #include <sys/disklabel.h>
35 #include <sys/reboot.h>
38 #include <machine/iomod.h>
44 const char cdevs
[][4] = {
45 "ite", "", "", "", "", "", "", "",
48 const int ncdevs
= NENTS(cdevs
);
50 const struct pdc_devs
{
63 /* pass dev_t to the open routines */
65 devopen(struct open_file
*f
, const char *fname
, char **file
)
68 const struct pdc_devs
*dp
= pdc_devs
;
69 int bdev
, badapt
, bctlr
, bunit
, bpart
;
74 if (!(*file
= strchr(fname
, ':')))
84 for (dp
= pdc_devs
; dp
< &pdc_devs
[NENTS(pdc_devs
)]; dp
++)
85 if (!strncmp(fname
, dp
->name
, sizeof(dp
->name
)-1))
88 if (dp
>= &pdc_devs
[NENTS(pdc_devs
)] || dp
->dev_type
< 0)
91 n
= strtoul(fname
+ sizeof(dp
->name
)-1, &p
, 10);
95 bctlr
= (n
>> 4) & 0xf;
96 badapt
= (n
>> 8) & 0xf;
97 if (*p
>= 'a' && *p
< 'a' + MAXPARTITIONS
) {
102 bootdev
= MAKEBOOTDEV(bdev
, badapt
, bctlr
, bunit
, bpart
);
106 printf("%s\n", dp
->name
);
109 if (!(hpd
= alloc(sizeof *hpd
))) {
111 printf ("devopen: no mem\n");
114 memset(hpd
, 0, sizeof *hpd
);
115 hpd
->bootdev
= bootdev
;
116 hpd
->buf
= (char *)(((u_int
)hpd
->ua_buf
+ IODC_MINIOSIZ
-1) &
119 if ((rc
= (*devsw
[dp
->dev_type
].dv_open
)(f
, file
)) == 0) {
120 f
->f_dev
= &devsw
[dp
->dev_type
];
127 if (!(f
->f_flags
& F_NODEV
))
128 f
->f_dev
= &devsw
[dp
->dev_type
];
137 devboot(btdev_t dev
, char *p
)
143 switch (PAGE0
->mem_boot
.pz_class
) {
146 unit
= PAGE0
->mem_boot
.pz_layers
[0];
150 unit
= PAGE0
->mem_boot
.pz_layers
[0];
152 case PCL_NET_MASK
|PCL_SEQU
:
161 dev
= bootdev
= MAKEBOOTDEV(type
, 0, 0, unit
, 0);
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
);
184 case '\177': /* DEL erases */
195 while(++pch_pos
% 8);
199 * XXX fredette - probably only necessary
200 * when using a serial console?
224 if ((c
< ' ' && c
!= '\n') || c
== '\177')
228 * XXX fredette - probably only unnecessary
229 * when using a serial console?
243 if ((c
= tcngetc()) == 0)
253 sprintf(ttyname_buf
, "%s%d", cdevs
[major(cn_tab
->cn_dev
)],
254 minor(cn_tab
->cn_dev
));
255 return (ttyname_buf
);
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)
268 for (i
= 0; i
< ncdevs
; i
++)
269 if (strncmp(name
, cdevs
[i
], no
- name
+ 1) == 0)
270 return (makedev(i
, unit
));