Home | History | Annotate | Line # | Download | only in boot
      1 /*	$NetBSD: hp.c,v 1.11 2018/03/19 15:43:45 ragge Exp $ */
      2 /*
      3  * Copyright (c) 1994 Ludd, University of Lule}, Sweden.
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  */
     26 
     27  /* All bugs are subject to removal without further notice */
     28 
     29 #include <sys/param.h>
     30 #include <sys/disklabel.h>
     31 
     32 #include <lib/libsa/stand.h>
     33 
     34 #include <lib/libkern/libkern.h>
     35 
     36 #include "../include/pte.h"
     37 #include "../include/rpb.h"
     38 #include "../include/sid.h"
     39 #define VAX780 1
     40 struct proc;
     41 #include "../include/ka750.h"
     42 
     43 #include "../mba/mbareg.h"
     44 #include "../mba/hpreg.h"
     45 
     46 #include "vaxstand.h"
     47 
     48 /*
     49  * These routines for HP disk standalone boot is wery simple,
     50  * assuming a lots of thing like that we only working at one hp disk
     51  * a time, no separate routines for mba driver etc..
     52  * But it works :)
     53  */
     54 
     55 static struct disklabel hplabel;
     56 static char io_buf[DEV_BSIZE];
     57 static int dpart;
     58 static int adpadr, unitadr;
     59 
     60 #define	MBA_WCSR(reg, val) \
     61 	((void)(*(volatile u_int32_t *)((adpadr) + (reg)) = (val)));
     62 #define MBA_RCSR(reg) \
     63 	(*(volatile u_int32_t *)((adpadr) + (reg)))
     64 #define	HP_WCSR(reg, val) \
     65 	((void)(*(volatile u_int32_t *)((unitadr) + (reg)) = (val)));
     66 #define HP_RCSR(reg) \
     67 	(*(volatile u_int32_t *)((unitadr) + (reg)))
     68 
     69 int
     70 hpopen(struct open_file *f, int adapt, int ctlr, int unit, int part)
     71 {
     72 	char *msg;
     73 	int err;
     74 	size_t i;
     75 
     76 	if (askname == 0) { /* Take info from RPB */
     77 		adpadr = bootrpb.adpphy;
     78 		unitadr = adpadr + MUREG(bootrpb.unit, 0);
     79 	} else {
     80 		adpadr = nexaddr;
     81 		unitadr = adpadr + MUREG(unit, 0);
     82 		bootrpb.adpphy = adpadr;
     83 		bootrpb.unit = unit;
     84 	}
     85 	memset(&hplabel, 0, sizeof(struct disklabel));
     86 
     87 	hplabel.d_secpercyl = 32;
     88 	hplabel.d_nsectors = 32;
     89 
     90 	/* Set volume valid and 16 bit format; only done once */
     91 	MBA_WCSR(MBA_CR, MBACR_INIT);
     92 	HP_WCSR(HP_CS1, HPCS_PA);
     93 	HP_WCSR(HP_OF, HPOF_FMT);
     94 
     95 	err = hpstrategy(0, F_READ, LABELSECTOR, DEV_BSIZE, io_buf, &i);
     96 	if (err) {
     97 		printf("reading disklabel: %s\n", strerror(err));
     98 		return 0;
     99 	}
    100 
    101 	msg = getdisklabel(io_buf + LABELOFFSET, &hplabel);
    102 	if (msg)
    103 		printf("getdisklabel: %s\n", msg);
    104 	return 0;
    105 }
    106 
    107 int
    108 hpstrategy(void *f, int func, daddr_t dblk,
    109     size_t size, void *buf, size_t *rsize)
    110 {
    111 	unsigned int bn, cn, sn, tn;
    112 
    113 	(void)ubmap(0, (int)buf, size);
    114 
    115 	MBA_WCSR(MBA_VAR, ((u_int)buf & VAX_PGOFSET));
    116 	MBA_WCSR(MBA_BC, (~size) + 1);
    117 	bn = dblk + hplabel.d_partitions[dpart].p_offset;
    118 
    119 	if (bn) {
    120 		cn = bn / hplabel.d_secpercyl;
    121 		sn = bn % hplabel.d_secpercyl;
    122 		tn = sn / hplabel.d_nsectors;
    123 		sn = sn % hplabel.d_nsectors;
    124 	} else
    125 		cn = sn = tn = 0;
    126 
    127 	HP_WCSR(HP_DC, cn);
    128 	HP_WCSR(HP_DA, (tn << 8) | sn);
    129 #ifdef notdef
    130 	if (func == F_WRITE)
    131 		HP_WCSR(HP_CS1, HPCS_WRITE);
    132 	else
    133 #endif
    134 		HP_WCSR(HP_CS1, HPCS_READ);
    135 
    136 	while (MBA_RCSR(MBA_SR) & MBASR_DTBUSY)
    137 		;
    138 
    139 	if (MBA_RCSR(MBA_SR) & MBACR_ABORT)
    140 		return 1;
    141 
    142 	*rsize = size;
    143 	return 0;
    144 }
    145