bugdev.c revision 1.1 1 1.1 chuck /* $NetBSD: bugdev.c,v 1.1 1996/05/17 20:59:53 chuck Exp $ */
2 1.1 chuck
3 1.1 chuck /*
4 1.1 chuck * Copyright (c) 1993 Paul Kranenburg
5 1.1 chuck * All rights reserved.
6 1.1 chuck *
7 1.1 chuck * Redistribution and use in source and binary forms, with or without
8 1.1 chuck * modification, are permitted provided that the following conditions
9 1.1 chuck * are met:
10 1.1 chuck * 1. Redistributions of source code must retain the above copyright
11 1.1 chuck * notice, this list of conditions and the following disclaimer.
12 1.1 chuck * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 chuck * notice, this list of conditions and the following disclaimer in the
14 1.1 chuck * documentation and/or other materials provided with the distribution.
15 1.1 chuck * 3. All advertising materials mentioning features or use of this software
16 1.1 chuck * must display the following acknowledgement:
17 1.1 chuck * This product includes software developed by Paul Kranenburg.
18 1.1 chuck * 4. The name of the author may not be used to endorse or promote products
19 1.1 chuck * derived from this software without specific prior written permission
20 1.1 chuck *
21 1.1 chuck * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 chuck * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 chuck * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 chuck * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 chuck * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 chuck * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 chuck * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 chuck * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 chuck * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 chuck * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 chuck */
32 1.1 chuck
33 1.1 chuck #include <sys/param.h>
34 1.1 chuck #include <sys/disklabel.h>
35 1.1 chuck #include <machine/prom.h>
36 1.1 chuck
37 1.1 chuck #include "stand.h"
38 1.1 chuck #include "libsa.h"
39 1.1 chuck
40 1.1 chuck void cputobsdlabel __P((struct disklabel *lp, struct cpu_disklabel *clp));
41 1.1 chuck
42 1.1 chuck int errno;
43 1.1 chuck
44 1.1 chuck struct bugsc_softc {
45 1.1 chuck int fd; /* Prom file descriptor */
46 1.1 chuck int poff; /* Partition offset */
47 1.1 chuck int psize; /* Partition size */
48 1.1 chuck short ctrl;
49 1.1 chuck short dev;
50 1.1 chuck } bugsc_softc[1];
51 1.1 chuck
52 1.1 chuck int
53 1.1 chuck devopen(f, fname, file)
54 1.1 chuck struct open_file *f;
55 1.1 chuck const char *fname;
56 1.1 chuck char **file;
57 1.1 chuck {
58 1.1 chuck register struct bugsc_softc *pp = &bugsc_softc[0];
59 1.1 chuck int error, i, dn = 0, pn = 0;
60 1.1 chuck char *dev, *cp;
61 1.1 chuck static char iobuf[MAXBSIZE];
62 1.1 chuck struct disklabel sdlabel;
63 1.1 chuck
64 1.1 chuck dev = bugargs.arg_start;
65 1.1 chuck
66 1.1 chuck /*
67 1.1 chuck * Extract partition # from boot device string.
68 1.1 chuck */
69 1.1 chuck for (cp = dev; *cp; cp++) /* void */;
70 1.1 chuck while (*cp != '/' && cp > dev) {
71 1.1 chuck if (*cp == ':')
72 1.1 chuck pn = *(cp+1) - 'a';
73 1.1 chuck --cp;
74 1.1 chuck }
75 1.1 chuck
76 1.1 chuck pp->fd = bugscopen(f);
77 1.1 chuck
78 1.1 chuck if (pp->fd < 0) {
79 1.1 chuck printf("Can't open device `%s'\n", dev);
80 1.1 chuck return (ENXIO);
81 1.1 chuck }
82 1.1 chuck error = bugscstrategy(pp, F_READ, LABELSECTOR, DEV_BSIZE, iobuf, &i);
83 1.1 chuck if (error)
84 1.1 chuck return (error);
85 1.1 chuck if (i != DEV_BSIZE)
86 1.1 chuck return (EINVAL);
87 1.1 chuck
88 1.1 chuck cputobsdlabel(&sdlabel, (struct cpu_disklabel *)iobuf);
89 1.1 chuck pp->poff = sdlabel.d_partitions[pn].p_offset;
90 1.1 chuck pp->psize = sdlabel.d_partitions[pn].p_size;
91 1.1 chuck
92 1.1 chuck f->f_dev = devsw;
93 1.1 chuck f->f_devdata = (void *)pp;
94 1.1 chuck *file = (char *)fname;
95 1.1 chuck return (0);
96 1.1 chuck }
97 1.1 chuck
98 1.1 chuck /* silly block scale factor */
99 1.1 chuck #define BUG_BLOCK_SIZE 256
100 1.1 chuck #define BUG_SCALE (512/BUG_BLOCK_SIZE)
101 1.1 chuck int
102 1.1 chuck bugscstrategy(devdata, func, dblk, size, buf, rsize)
103 1.1 chuck void *devdata;
104 1.1 chuck int func;
105 1.1 chuck daddr_t dblk;
106 1.1 chuck size_t size;
107 1.1 chuck void *buf;
108 1.1 chuck size_t *rsize;
109 1.1 chuck {
110 1.1 chuck struct mvmeprom_dskio dio;
111 1.1 chuck register struct bugsc_softc *pp = (struct bugsc_softc *)devdata;
112 1.1 chuck daddr_t blk = dblk + pp->poff;
113 1.1 chuck
114 1.1 chuck twiddle();
115 1.1 chuck
116 1.1 chuck dio.ctrl_lun = pp->ctrl;
117 1.1 chuck dio.dev_lun = pp->dev;
118 1.1 chuck dio.status = 0;
119 1.1 chuck dio.pbuffer = buf;
120 1.1 chuck dio.blk_num = blk * BUG_SCALE;
121 1.1 chuck dio.blk_cnt = size / BUG_BLOCK_SIZE; /* assumed size in bytes */
122 1.1 chuck dio.flag = 0;
123 1.1 chuck dio.addr_mod = 0;
124 1.1 chuck #ifdef DEBUG
125 1.1 chuck printf("bugscstrategy: size=%d blk=%d buf=%x\n", size, blk, buf);
126 1.1 chuck printf("ctrl %d dev %d\n", dio.ctrl_lun, dio.dev_lun);
127 1.1 chuck #endif
128 1.1 chuck mvmeprom_diskrd(&dio);
129 1.1 chuck
130 1.1 chuck *rsize = dio.blk_cnt * BUG_BLOCK_SIZE;
131 1.1 chuck #ifdef DEBUG
132 1.1 chuck printf("rsize %d status %x\n", *rsize, dio.status);
133 1.1 chuck #endif
134 1.1 chuck
135 1.1 chuck if (dio.status)
136 1.1 chuck return (EIO);
137 1.1 chuck return (0);
138 1.1 chuck }
139 1.1 chuck
140 1.1 chuck int
141 1.1 chuck bugscopen(f)
142 1.1 chuck struct open_file *f;
143 1.1 chuck {
144 1.1 chuck #ifdef DEBUG
145 1.1 chuck printf("bugscopen:\n");
146 1.1 chuck #endif
147 1.1 chuck
148 1.1 chuck f->f_devdata = (void *)bugsc_softc;
149 1.1 chuck bugsc_softc[0].ctrl = (short)bugargs.ctrl_lun;
150 1.1 chuck bugsc_softc[0].dev = (short)bugargs.dev_lun;
151 1.1 chuck #ifdef DEBUG
152 1.1 chuck printf("using mvmebug ctrl %d dev %d\n",
153 1.1 chuck bugsc_softc[0].ctrl, bugsc_softc[0].dev);
154 1.1 chuck #endif
155 1.1 chuck return (0);
156 1.1 chuck }
157 1.1 chuck
158 1.1 chuck int
159 1.1 chuck bugscclose(f)
160 1.1 chuck struct open_file *f;
161 1.1 chuck {
162 1.1 chuck return (EIO);
163 1.1 chuck }
164 1.1 chuck
165 1.1 chuck int
166 1.1 chuck bugscioctl(f, cmd, data)
167 1.1 chuck struct open_file *f;
168 1.1 chuck u_long cmd;
169 1.1 chuck void *data;
170 1.1 chuck {
171 1.1 chuck return (EIO);
172 1.1 chuck }
173 1.1 chuck
174 1.1 chuck void
175 1.1 chuck cputobsdlabel(lp, clp)
176 1.1 chuck struct disklabel *lp;
177 1.1 chuck struct cpu_disklabel *clp;
178 1.1 chuck {
179 1.1 chuck int i;
180 1.1 chuck
181 1.1 chuck lp->d_magic = clp->magic1;
182 1.1 chuck lp->d_type = clp->type;
183 1.1 chuck lp->d_subtype = clp->subtype;
184 1.1 chuck bcopy(clp->vid_vd, lp->d_typename, 16);
185 1.1 chuck bcopy(clp->packname, lp->d_packname, 16);
186 1.1 chuck lp->d_secsize = clp->cfg_psm;
187 1.1 chuck lp->d_nsectors = clp->cfg_spt;
188 1.1 chuck lp->d_ncylinders = clp->cfg_trk; /* trk is really num of cyl! */
189 1.1 chuck lp->d_ntracks = clp->cfg_hds;
190 1.1 chuck
191 1.1 chuck lp->d_secpercyl = clp->secpercyl;
192 1.1 chuck lp->d_secperunit = clp->secperunit;
193 1.1 chuck lp->d_secpercyl = clp->secpercyl;
194 1.1 chuck lp->d_secperunit = clp->secperunit;
195 1.1 chuck lp->d_sparespertrack = clp->sparespertrack;
196 1.1 chuck lp->d_sparespercyl = clp->sparespercyl;
197 1.1 chuck lp->d_acylinders = clp->acylinders;
198 1.1 chuck lp->d_rpm = clp->rpm;
199 1.1 chuck lp->d_interleave = clp->cfg_ilv;
200 1.1 chuck lp->d_trackskew = clp->cfg_sof;
201 1.1 chuck lp->d_cylskew = clp->cylskew;
202 1.1 chuck lp->d_headswitch = clp->headswitch;
203 1.1 chuck
204 1.1 chuck /* this silly table is for winchester drives */
205 1.1 chuck switch (clp->cfg_ssr) {
206 1.1 chuck case 0:
207 1.1 chuck lp->d_trkseek = 0;
208 1.1 chuck break;
209 1.1 chuck case 1:
210 1.1 chuck lp->d_trkseek = 6;
211 1.1 chuck break;
212 1.1 chuck case 2:
213 1.1 chuck lp->d_trkseek = 10;
214 1.1 chuck break;
215 1.1 chuck case 3:
216 1.1 chuck lp->d_trkseek = 15;
217 1.1 chuck break;
218 1.1 chuck case 4:
219 1.1 chuck lp->d_trkseek = 20;
220 1.1 chuck break;
221 1.1 chuck default:
222 1.1 chuck lp->d_trkseek = 0;
223 1.1 chuck break;
224 1.1 chuck }
225 1.1 chuck lp->d_flags = clp->flags;
226 1.1 chuck for (i = 0; i < NDDATA; i++)
227 1.1 chuck lp->d_drivedata[i] = clp->drivedata[i];
228 1.1 chuck for (i = 0; i < NSPARE; i++)
229 1.1 chuck lp->d_spare[i] = clp->spare[i];
230 1.1 chuck lp->d_magic2 = clp->magic2;
231 1.1 chuck lp->d_checksum = clp->checksum;
232 1.1 chuck lp->d_npartitions = clp->partitions;
233 1.1 chuck lp->d_bbsize = clp->bbsize;
234 1.1 chuck lp->d_sbsize = clp->sbsize;
235 1.1 chuck bcopy(clp->vid_4, &(lp->d_partitions[0]),sizeof (struct partition) * 4);
236 1.1 chuck bcopy(clp->cfg_4, &(lp->d_partitions[4]), sizeof (struct partition)
237 1.1 chuck * ((MAXPARTITIONS < 16) ? (MAXPARTITIONS - 4) : 12));
238 1.1 chuck }
239