1 /* $NetBSD: bugdev.c,v 1.11 2008/01/12 09:54:31 tsutsui Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/param.h>
33 #include <sys/disklabel.h>
34 #include <machine/prom.h>
36 #include <lib/libsa/stand.h>
39 void cputobsdlabel(struct disklabel
*lp
, struct cpu_disklabel
*clp
);
44 int fd
; /* Prom file descriptor */
45 int poff
; /* Partition offset */
46 int psize
; /* Partition size */
52 devopen(struct open_file
*f
, const char *fname
, char **file
)
54 struct bugsc_softc
*pp
= &bugsc_softc
[0];
58 static int iobuf
[DEV_BSIZE
/ sizeof(int)];
59 struct disklabel sdlabel
;
61 dev
= bugargs
.arg_start
;
64 * Extract partition # from boot device string.
65 * The Bug command line format of this is:
67 * 147-Bug> bo [drive],,[<d>:][kernel_name] [options]
70 * [drive] The bug LUN number, eg. 0
71 * [<d>:] <d> is partition # ('a' to 'h')
72 * [kernel_name] Eg. netbsd or /netbsd
75 * At this time, all we need do is scan for a ':', and assume the
76 * preceding letter is a partition id.
78 for (cp
= dev
+ 1; *cp
&& cp
<= bugargs
.arg_end
; cp
++) {
85 if ( pn
< 0 || pn
>= MAXPARTITIONS
) {
86 printf("Invalid partition number; defaulting to 'a'\n");
90 pp
->fd
= bugscopen(f
);
93 printf("Can't open device `%s'\n", dev
);
96 error
= bugscstrategy(pp
, F_READ
, LABELSECTOR
, DEV_BSIZE
, iobuf
, &nrd
);
103 cputobsdlabel(&sdlabel
, (struct cpu_disklabel
*)&(iobuf
[0]));
104 pp
->poff
= sdlabel
.d_partitions
[pn
].p_offset
;
105 pp
->psize
= sdlabel
.d_partitions
[pn
].p_size
;
108 f
->f_devdata
= (void *)pp
;
110 *file
= (char *)fname
;
114 /* silly block scale factor */
115 #define BUG_BLOCK_SIZE 256
116 #define BUG_SCALE (512/BUG_BLOCK_SIZE)
119 bugscstrategy(void *devdata
, int func
, daddr_t dblk
, size_t size
, void *buf
,
122 struct mvmeprom_dskio dio
;
123 struct bugsc_softc
*pp
= (struct bugsc_softc
*)devdata
;
124 daddr_t blk
= dblk
+ pp
->poff
;
128 dio
.ctrl_lun
= pp
->ctrl
;
129 dio
.dev_lun
= pp
->dev
;
132 dio
.blk_num
= blk
* BUG_SCALE
;
133 dio
.blk_cnt
= size
/ BUG_BLOCK_SIZE
; /* assumed size in bytes */
137 printf("bugscstrategy: size=%d blk=%d buf=%x\n", size
, blk
, buf
);
138 printf("ctrl %d dev %d\n", dio
.ctrl_lun
, dio
.dev_lun
);
140 mvmeprom_diskrd(&dio
);
142 *rsize
= dio
.blk_cnt
* BUG_BLOCK_SIZE
;
144 printf("rsize %d status %x\n", *rsize
, dio
.status
);
153 bugscopen(struct open_file
*f
, ...)
157 printf("bugscopen:\n");
160 f
->f_devdata
= (void *)bugsc_softc
;
161 bugsc_softc
[0].ctrl
= (short)bugargs
.ctrl_lun
;
162 bugsc_softc
[0].dev
= (short)bugargs
.dev_lun
;
164 printf("using mvmebug ctrl %d dev %d\n",
165 bugsc_softc
[0].ctrl
, bugsc_softc
[0].dev
);
172 bugscclose(struct open_file
*f
)
180 bugscioctl(struct open_file
*f
, u_long cmd
, void *data
)
187 cputobsdlabel(struct disklabel
*lp
, struct cpu_disklabel
*clp
)
191 lp
->d_magic
= (uint32_t)clp
->magic1
;
192 lp
->d_type
= (uint16_t)clp
->type
;
193 lp
->d_subtype
= (uint16_t)clp
->subtype
;
195 memcpy(lp
->d_typename
, clp
->vid_vd
, 16);
196 memcpy(lp
->d_packname
, clp
->packname
, 16);
198 lp
->d_secsize
= (uint32_t)clp
->cfg_psm
;
199 lp
->d_nsectors
= (uint32_t)clp
->cfg_spt
;
200 lp
->d_ncylinders
= (uint32_t)clp
->cfg_trk
; /* trk is num of cyl! */
201 lp
->d_ntracks
= (uint32_t)clp
->cfg_hds
;
202 lp
->d_secpercyl
= (uint32_t)clp
->secpercyl
;
203 lp
->d_secperunit
= (uint32_t)clp
->secperunit
;
204 lp
->d_sparespertrack
= (uint16_t)clp
->sparespertrack
;
205 lp
->d_sparespercyl
= (uint16_t)clp
->sparespercyl
;
206 lp
->d_acylinders
= (uint32_t)clp
->acylinders
;
207 lp
->d_rpm
= (uint16_t)clp
->rpm
;
208 lp
->d_interleave
= (uint16_t)clp
->cfg_ilv
;
209 lp
->d_trackskew
= (uint16_t)clp
->cfg_sof
;
210 lp
->d_cylskew
= (uint16_t)clp
->cylskew
;
211 lp
->d_headswitch
= (uint32_t)clp
->headswitch
;
213 /* this silly table is for winchester drives */
214 switch (clp
->cfg_ssr
) {
234 lp
->d_flags
= (uint32_t)clp
->flags
;
236 for (i
= 0; i
< NDDATA
; i
++)
237 lp
->d_drivedata
[i
] = (uint32_t)clp
->drivedata
[i
];
239 for (i
= 0; i
< NSPARE
; i
++)
240 lp
->d_spare
[i
] = (uint32_t)clp
->spare
[i
];
242 lp
->d_magic2
= (uint32_t)clp
->magic2
;
243 lp
->d_checksum
= (uint16_t)clp
->checksum
;
244 lp
->d_npartitions
= (uint16_t)clp
->partitions
;
245 lp
->d_bbsize
= (uint32_t)clp
->bbsize
;
246 lp
->d_sbsize
= (uint32_t)clp
->sbsize
;
248 memcpy(&(lp
->d_partitions
[0]), clp
->vid_4
,
249 sizeof(struct partition
) * 4);
252 memcpy(&(lp
->d_partitions
[4]), clp
->cfg_4
, sizeof(struct partition
)
253 * ((MAXPARTITIONS
< 16) ? (MAXPARTITIONS
- 4) : 12));