1 /* $NetBSD: rom.c,v 1.11 2022/04/25 15:06:34 mlelstv 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 * 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 BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #include <sys/param.h> 31 #include <sys/reboot.h> 32 #include <sys/disklabel.h> 33 34 #define RF_PROTECTED_SECTORS 64 /* XXX <dev/raidframe/raidframevar.h> */ 35 36 #include <lib/libsa/stand.h> 37 #include <lib/libsa/ufs.h> 38 39 #include <lib/libkern/libkern.h> 40 41 #include "../include/pte.h" 42 #include "../include/sid.h" 43 #include "../include/mtpr.h" 44 #include "../include/reg.h" 45 #include "../include/rpb.h" 46 47 #include "data.h" 48 #include "vaxstand.h" 49 50 static struct disklabel romlabel; 51 static char io_buf[DEV_BSIZE]; 52 static struct bqo *bqo; 53 static int dpart, dunit; 54 55 int 56 romopen(struct open_file *f, int adapt, int ctlr, int unit, int part) 57 { 58 char *msg; 59 struct disklabel *lp = &romlabel; 60 size_t i; 61 int err; 62 63 bqo = (void *)bootrpb.iovec; 64 65 memset(lp, 0, sizeof(struct disklabel)); 66 dunit = unit; 67 dpart = part; 68 69 err = romstrategy(0, F_READ, LABELSECTOR, DEV_BSIZE, io_buf, &i); 70 if (err) { 71 printf("reading disklabel: %s\n",strerror(err)); 72 return 0; 73 } 74 msg = getdisklabel(io_buf+LABELOFFSET, lp); 75 if (msg) 76 printf("getdisklabel: %s\n",msg); 77 return(0); 78 } 79 80 int romwrite_uvax(int, int, void *, struct rpb *); 81 int romread_uvax(int, int, void *, struct rpb *); 82 83 int 84 romstrategy (void *f, int func, daddr_t dblk, size_t size, void *buf, size_t *rsize) 85 { 86 struct disklabel *lp; 87 int block; 88 89 lp = &romlabel; 90 block = dblk + lp->d_partitions[dpart].p_offset; 91 if (dunit >= 0 && dunit < 10) 92 bootrpb.unit = dunit; 93 if (lp->d_partitions[dpart].p_fstype == FS_RAID) 94 block += RF_PROTECTED_SECTORS; 95 96 if (func == F_WRITE) 97 romwrite_uvax(block, size, buf, &bootrpb); 98 else 99 romread_uvax(block, size, buf, &bootrpb); 100 101 *rsize = size; 102 return 0; 103 } 104 105 int 106 romioctl(struct open_file *f, u_long cmd, void *data) 107 { 108 return ENOTTY; 109 } 110