xref: /netbsd/sys/arch/vax/boot/boot/rom.c (revision c4a72b64)
1 /*	$NetBSD: rom.c,v 1.5 2002/09/19 17:41:21 ragge Exp $ */
2 /*
3  * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to Ludd by
7  * Bertram Barth.
8  *
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.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed at Ludd, University of
20  *      Lule}, Sweden and its contributors.
21  * 4. The name of the author may not be used to endorse or promote products
22  *    derived from this software without specific prior written permission
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #include "sys/param.h"
37 #include "sys/reboot.h"
38 #include "sys/disklabel.h"
39 
40 #define RF_PROTECTED_SECTORS	64	/* XXX <dev/raidframe/raidframevar.h> */
41 
42 #include "lib/libsa/stand.h"
43 #include "lib/libsa/ufs.h"
44 
45 #include "lib/libkern/libkern.h"
46 
47 #include "../include/pte.h"
48 #include "../include/sid.h"
49 #include "../include/mtpr.h"
50 #include "../include/reg.h"
51 #include "../include/rpb.h"
52 
53 #include "data.h"
54 #include "vaxstand.h"
55 
56 static struct disklabel romlabel;
57 static char io_buf[DEV_BSIZE];
58 static struct bqo *bqo;
59 static int dpart, dunit;
60 
61 int
62 romopen(struct open_file *f, int adapt, int ctlr, int unit, int part)
63 {
64 	char *msg;
65 	struct disklabel *lp = &romlabel;
66 	size_t i;
67 	int err;
68 
69 	bqo = (void *)bootrpb.iovec;
70 
71 	bzero(lp, sizeof(struct disklabel));
72 	dunit = unit;
73 	dpart = part;
74 
75 	err = romstrategy(0, F_READ, LABELSECTOR, DEV_BSIZE, io_buf, &i);
76 	if (err) {
77 		printf("reading disklabel: %s\n",strerror(err));
78 		return 0;
79 	}
80 	msg = getdisklabel(io_buf+LABELOFFSET, lp);
81 	if (msg)
82 		printf("getdisklabel: %s\n",msg);
83 	return(0);
84 }
85 
86 int	romwrite_uvax(int, int, void *, struct rpb *);
87 int	romread_uvax(int, int, void *, struct rpb *);
88 
89 int
90 romstrategy (f, func, dblk, size, buf, rsize)
91 	void *f;
92 	int func;
93 	daddr_t dblk;
94 	size_t size;
95 	void *buf;
96 	size_t *rsize;
97 {
98 	struct	disklabel *lp;
99 	int	block;
100 
101 	lp = &romlabel;
102 	block = dblk + lp->d_partitions[dpart].p_offset;
103 	if (dunit >= 0 && dunit < 10)
104 		bootrpb.unit = dunit;
105 	if (lp->d_partitions[dpart].p_fstype == FS_RAID)
106 		block += RF_PROTECTED_SECTORS;
107 
108 	if (func == F_WRITE)
109 		romwrite_uvax(block, size, buf, &bootrpb);
110 	else
111 		romread_uvax(block, size, buf, &bootrpb);
112 
113 	*rsize = size;
114 	return 0;
115 }
116 
117