1 /* $NetBSD: devopen.c,v 1.20 2018/03/21 18:27:27 ragge Exp $ */
2 /*
3 * Copyright (c) 1997 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 #include <lib/libsa/stand.h>
28 #include <lib/libkern/libkern.h>
29
30 #include <machine/param.h>
31 #include <machine/rpb.h>
32 #include <machine/sid.h>
33 #include <machine/pte.h>
34 #define VAX780 1
35 #include <machine/ka750.h>
36
37 #include <dev/bi/bireg.h>
38
39 #include "vaxstand.h"
40
41 int nexaddr, csrbase;
42 static int *mapaddr;
43
44 /*
45 * Boot device syntax:
46 * device(adapter, controller, unit, partition)file
47 */
48 int
devopen(struct open_file * f,const char * fname,char ** file)49 devopen(struct open_file *f, const char *fname, char **file)
50 {
51 int dev, unit, ctlr, part, adapt, i, a[4], x;
52 struct devsw *dp;
53 extern int cnvtab[];
54 char *s, *c;
55
56 part = 0;
57
58 /*
59 * Adaptor and controller are normally zero (or uninteresting),
60 * but we need to do some conversion here anyway (if it's a
61 * manual boot, but that's checked by the device driver).
62 * Set them to -1 to tell if it's a set number or default.
63 */
64 dev = bootrpb.devtyp;
65 unit = bootrpb.unit;
66 adapt = ctlr = -1;
67
68 if (dev == BDEV_KDB)
69 dev = BDEV_UDA; /* use the same driver */
70
71 for (i = 0, dp = 0; i < ndevs; i++)
72 if (cnvtab[i] == dev)
73 dp = devsw + i;
74
75 x = 0;
76 if ((s = strchr((char *)fname, '('))) {
77 *s++ = 0;
78
79 for (i = 0, dp = devsw; i < ndevs; i++, dp++)
80 if (dp->dv_name && strcmp(dp->dv_name, fname) == 0)
81 break;
82
83 if (i == ndevs) {
84 printf("No such device - Configured devices are:\n");
85 for (dp = devsw, i = 0; i < ndevs; i++, dp++)
86 if (dp->dv_name)
87 printf(" %s", dp->dv_name);
88 printf("\n");
89 return -1;
90 }
91 dev = cnvtab[i];
92 if ((c = strchr(s, ')')) == 0)
93 goto usage;
94
95 *c++ = 0;
96
97 if (*s) do {
98 a[x++] = atoi(s);
99 while (*s >= '0' && *s <= '9')
100 s++;
101
102 if (*s != ',' && *s != 0)
103 goto usage;
104 } while (*s++);
105
106 if (x)
107 part = a[x - 1];
108 if (x > 1)
109 unit = a[x - 2];
110 if (x > 2)
111 ctlr = a[x - 3];
112 if (x > 3)
113 adapt = a[0];
114 *file = c;
115 } else {
116 *file = (char *)fname;
117 c = (char *)fname;
118 }
119
120 if (!dp->dv_open) {
121 printf("Can't open device type %d\n", dev);
122 return(ENODEV);
123 }
124 f->f_dev = dp;
125 bootrpb.unit = unit;
126 bootrpb.devtyp = dev;
127
128 nexaddr = bootrpb.adpphy;
129 switch (vax_boardtype) {
130 case VAX_BTYP_750:
131 csrbase = (nexaddr == 0xf30000 ? 0xffe000 : 0xfbe000);
132 mapaddr = (int *)nexaddr + VAX_NBPG;
133 if (adapt < 0)
134 break;
135 nexaddr = (NEX750 + NEXSIZE * adapt);
136 csrbase = (adapt == 8 ? 0xffe000 : 0xfbe000);
137 break;
138 case VAX_BTYP_780:
139 case VAX_BTYP_790:
140 csrbase = 0x2007e000 + 0x40000 * ((nexaddr & 0x1e000) >> 13);
141 mapaddr = (int *)nexaddr + VAX_NBPG;
142 if (adapt < 0)
143 break;
144 nexaddr = ((int)NEX780 + NEXSIZE * adapt);
145 csrbase = 0x2007e000 + 0x40000 * adapt;
146 break;
147 case VAX_BTYP_9CC: /* 6000/200 */
148 case VAX_BTYP_9RR: /* 6000/400 */
149 case VAX_BTYP_1202: /* 6000/500 */
150 csrbase = 0;
151 if (ctlr < 0)
152 ctlr = bootrpb.adpphy & 15;
153 if (adapt < 0)
154 adapt = (bootrpb.adpphy >> 4) & 15;
155 nexaddr = BI_BASE(adapt, ctlr);
156 break;
157
158 case VAX_BTYP_8000:
159 case VAX_BTYP_8800:
160 case VAX_BTYP_8PS:
161 csrbase = 0; /* _may_ be a KDB */
162 nexaddr = bootrpb.csrphy;
163 if (ctlr < 0)
164 break;
165 if (adapt < 0)
166 nexaddr = (nexaddr & 0xff000000) + BI_NODE(ctlr);
167 else
168 nexaddr = BI_BASE(adapt, ctlr);
169 break;
170 case VAX_BTYP_610:
171 nexaddr = 0; /* No map regs */
172 csrbase = 0x20000000;
173 break;
174
175 case VAX_BTYP_VXT:
176 nexaddr = 0;
177 csrbase = bootrpb.csrphy;
178 break;
179 default:
180 nexaddr = 0; /* No map regs */
181 csrbase = 0x20000000;
182 if (bootrpb.adpphy == 0x20087800) {
183 nexaddr = bootrpb.adpphy;
184 mapaddr = (int *)nexaddr + VAX_NBPG;
185 }
186 break;
187 }
188
189 #ifdef DEV_DEBUG
190 printf("rpb.type %d rpb.unit %d rpb.csr %lx rpb.adp %lx\n",
191 bootrpb.devtyp, bootrpb.unit, bootrpb.csrphy, bootrpb.adpphy);
192 printf("adapter %d ctlr %d unit %d part %d\n", adapt, ctlr, unit, part);
193 printf("nexaddr %x csrbase %x\n", nexaddr, csrbase);
194 #endif
195
196 return (*dp->dv_open)(f, adapt, ctlr, unit, part);
197
198 usage:
199 printf("usage: dev(adapter,controller,unit,partition)file -asd\n");
200 return -1;
201 }
202
203 /*
204 * Map in virtual address vaddr of size vsize starting with map mapno.
205 * Returns the unibus address of the mapped area.
206 */
207 int
ubmap(int mapno,int vaddr,int size)208 ubmap(int mapno, int vaddr, int size)
209 {
210 int voff = (vaddr & VAX_PGOFSET);
211 int rv = (mapno << VAX_PGSHIFT) + voff;
212 int vpag, npag;
213
214 if (mapaddr == 0)
215 return vaddr; /* no map, phys == virt */
216
217 npag = (voff + size) / VAX_NBPG;
218 vpag = vaddr >> VAX_PGSHIFT;
219 while (npag-- >= 0)
220 mapaddr[mapno++] = vpag++ | PG_V;
221 return rv;
222 }
223