xref: /netbsd-src/sys/arch/hppa/stand/common/dk.c (revision 6d3ceb1d619615401b17c9aa3e4bc674a1cb048b)
1*6d3ceb1dSskrll /*	$NetBSD: dk.c,v 1.1 2014/02/24 07:23:43 skrll Exp $	*/
2*6d3ceb1dSskrll 
3*6d3ceb1dSskrll /*	$OpenBSD: dk.c,v 1.5 1999/04/20 20:01:01 mickey Exp $	*/
4*6d3ceb1dSskrll 
5*6d3ceb1dSskrll /*
6*6d3ceb1dSskrll  * Copyright 1996 1995 by Open Software Foundation, Inc.
7*6d3ceb1dSskrll  *              All Rights Reserved
8*6d3ceb1dSskrll  *
9*6d3ceb1dSskrll  * Permission to use, copy, modify, and distribute this software and
10*6d3ceb1dSskrll  * its documentation for any purpose and without fee is hereby granted,
11*6d3ceb1dSskrll  * provided that the above copyright notice appears in all copies and
12*6d3ceb1dSskrll  * that both the copyright notice and this permission notice appear in
13*6d3ceb1dSskrll  * supporting documentation.
14*6d3ceb1dSskrll  *
15*6d3ceb1dSskrll  * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
16*6d3ceb1dSskrll  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
17*6d3ceb1dSskrll  * FOR A PARTICULAR PURPOSE.
18*6d3ceb1dSskrll  *
19*6d3ceb1dSskrll  * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
20*6d3ceb1dSskrll  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
21*6d3ceb1dSskrll  * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
22*6d3ceb1dSskrll  * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
23*6d3ceb1dSskrll  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24*6d3ceb1dSskrll  *
25*6d3ceb1dSskrll  */
26*6d3ceb1dSskrll 
27*6d3ceb1dSskrll #include "libsa.h"
28*6d3ceb1dSskrll 
29*6d3ceb1dSskrll #include <sys/param.h>
30*6d3ceb1dSskrll #include <sys/disklabel.h>
31*6d3ceb1dSskrll #include <sys/reboot.h>
32*6d3ceb1dSskrll #include <machine/pdc.h>
33*6d3ceb1dSskrll #include <machine/iomod.h>
34*6d3ceb1dSskrll 
35*6d3ceb1dSskrll #include "dev_hppa.h"
36*6d3ceb1dSskrll 
37*6d3ceb1dSskrll const char *dk_disklabel(struct hppa_dev *, struct disklabel *);
38*6d3ceb1dSskrll 
39*6d3ceb1dSskrll iodcio_t dkiodc;	/* boot IODC entry point */
40*6d3ceb1dSskrll 
41*6d3ceb1dSskrll const char *
dk_disklabel(struct hppa_dev * dp,struct disklabel * label)42*6d3ceb1dSskrll dk_disklabel(struct hppa_dev *dp, struct disklabel *label)
43*6d3ceb1dSskrll {
44*6d3ceb1dSskrll 	char buf[DEV_BSIZE];
45*6d3ceb1dSskrll 	size_t ret;
46*6d3ceb1dSskrll 
47*6d3ceb1dSskrll 	if (iodcstrategy(dp, F_READ, LABELSECTOR, DEV_BSIZE, buf, &ret) ||
48*6d3ceb1dSskrll 	    ret != DEV_BSIZE)
49*6d3ceb1dSskrll 		return "can't read disklabel";
50*6d3ceb1dSskrll 
51*6d3ceb1dSskrll 	return (getdisklabel(buf, label));
52*6d3ceb1dSskrll }
53*6d3ceb1dSskrll 
54*6d3ceb1dSskrll int
dkopen(struct open_file * f,...)55*6d3ceb1dSskrll dkopen(struct open_file *f, ...)
56*6d3ceb1dSskrll {
57*6d3ceb1dSskrll 	struct disklabel dkl;
58*6d3ceb1dSskrll 	struct hppa_dev *dp = f->f_devdata;
59*6d3ceb1dSskrll 	const char *st;
60*6d3ceb1dSskrll 	u_int i;
61*6d3ceb1dSskrll 
62*6d3ceb1dSskrll #ifdef	DEBUG
63*6d3ceb1dSskrll 	if (debug)
64*6d3ceb1dSskrll 		printf("dkopen(%p)\n", f);
65*6d3ceb1dSskrll #endif
66*6d3ceb1dSskrll 
67*6d3ceb1dSskrll 	if (!(dp->pz_dev = pdc_findev(-1, PCL_RANDOM)))
68*6d3ceb1dSskrll 		return ENXIO;
69*6d3ceb1dSskrll 
70*6d3ceb1dSskrll 	dp->part_off = 0;
71*6d3ceb1dSskrll 	st = NULL;
72*6d3ceb1dSskrll #ifdef DEBUG
73*6d3ceb1dSskrll 	if (debug)
74*6d3ceb1dSskrll 		printf ("disklabel\n");
75*6d3ceb1dSskrll #endif
76*6d3ceb1dSskrll 	if ((st = dk_disklabel(dp, &dkl)) != NULL) {
77*6d3ceb1dSskrll #ifdef DEBUG
78*6d3ceb1dSskrll 		if (debug)
79*6d3ceb1dSskrll 			printf ("dkopen: %s\n", st);
80*6d3ceb1dSskrll #endif
81*6d3ceb1dSskrll 	/*
82*6d3ceb1dSskrll 	 * Ignore disklabel errors for this two reasons:
83*6d3ceb1dSskrll 	 * 1. It is possible to dd(1) a LIF image containing the bootloader
84*6d3ceb1dSskrll 	 * and a kernel with attached RAM disk to disk and boot it. That way
85*6d3ceb1dSskrll 	 * the netboot installation LIF image is also usable as disk boot
86*6d3ceb1dSskrll 	 * image.
87*6d3ceb1dSskrll 	 * 2. Some old 700 machines report a wrong device class in
88*6d3ceb1dSskrll 	 * PAGE0->mem_boot.pz_class when net booting. (PCL_RANDOM instead
89*6d3ceb1dSskrll 	 * PCL_NET_MASK|PCL_SEQU) So the bootloader thinks it is booting
90*6d3ceb1dSskrll 	 * from disk when it is actually net booting. The net boot LIF image
91*6d3ceb1dSskrll 	 * contains no disklabel so the test for the disklabel will fail.
92*6d3ceb1dSskrll 	 * If the device open fails if there is no disklabel we are not able
93*6d3ceb1dSskrll 	 * to netboot those machines.
94*6d3ceb1dSskrll 	 * Therefore the error is ignored. The bootloader will fall back to
95*6d3ceb1dSskrll 	 * LIF later when there is no disklabel / FFS partition.
96*6d3ceb1dSskrll 	 * At the moment it doesn't matter that the wrong device type ("dk"
97*6d3ceb1dSskrll 	 * instead "lf") is used, as all I/O is abstracted by the firmware.
98*6d3ceb1dSskrll 	 * To get the correct device type it would be necessary to add a
99*6d3ceb1dSskrll 	 * quirk table to the switch() in dev_hppa.c:devboot().
100*6d3ceb1dSskrll 	 */
101*6d3ceb1dSskrll 	} else {
102*6d3ceb1dSskrll 		i = B_PARTITION(dp->bootdev);
103*6d3ceb1dSskrll #ifdef DEBUG
104*6d3ceb1dSskrll 		if (debug)
105*6d3ceb1dSskrll 			printf("bootdev 0x%x, partition %u\n", dp->bootdev, i);
106*6d3ceb1dSskrll #endif
107*6d3ceb1dSskrll 		if (i >= dkl.d_npartitions || !dkl.d_partitions[i].p_size) {
108*6d3ceb1dSskrll 			return (EPART);
109*6d3ceb1dSskrll 		}
110*6d3ceb1dSskrll 		dp->part_off = dkl.d_partitions[i].p_offset * dkl.d_secsize;
111*6d3ceb1dSskrll 	}
112*6d3ceb1dSskrll #ifdef DEBUGBUG
113*6d3ceb1dSskrll 	if (debug)
114*6d3ceb1dSskrll 		printf ("dkopen() ret\n");
115*6d3ceb1dSskrll #endif
116*6d3ceb1dSskrll 	return (0);
117*6d3ceb1dSskrll }
118*6d3ceb1dSskrll 
119*6d3ceb1dSskrll int
dkclose(struct open_file * f)120*6d3ceb1dSskrll dkclose(struct open_file *f)
121*6d3ceb1dSskrll {
122*6d3ceb1dSskrll 	dealloc(f->f_devdata, sizeof(struct hppa_dev));
123*6d3ceb1dSskrll 	f->f_devdata = NULL;
124*6d3ceb1dSskrll 	return 0;
125*6d3ceb1dSskrll }
126