Sun Jan 23 01:32:08 2011 UTC ()
- add "ll" modifier to printf.
- be more conscious about int type propagation.
- add missing version and newvers.sh


(nisimura)
diff -r1.1 -r1.2 src/sys/arch/sandpoint/stand/altboot/dsk.c
diff -r1.1 -r1.2 src/sys/arch/sandpoint/stand/altboot/globals.h
diff -r1.1 -r1.2 src/sys/arch/sandpoint/stand/altboot/printf.c
diff -r0 -r1.1 src/sys/arch/sandpoint/stand/altboot/newvers.sh
diff -r0 -r1.1 src/sys/arch/sandpoint/stand/altboot/version

cvs diff -r1.1 -r1.2 src/sys/arch/sandpoint/stand/altboot/dsk.c (switch to unified diff)

--- src/sys/arch/sandpoint/stand/altboot/dsk.c 2011/01/23 01:05:30 1.1
+++ src/sys/arch/sandpoint/stand/altboot/dsk.c 2011/01/23 01:32:08 1.2
@@ -1,539 +1,538 @@ @@ -1,539 +1,538 @@
1/* $NetBSD: dsk.c,v 1.1 2011/01/23 01:05:30 nisimura Exp $ */ 1/* $NetBSD: dsk.c,v 1.2 2011/01/23 01:32:08 nisimura Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tohru Nishimura. 8 * by Tohru Nishimura.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 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 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 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * assumptions; 33 * assumptions;
34 * - up to 4 IDE/SATA drives. 34 * - up to 4 IDE/SATA drives.
35 * - a single (master) drive in each IDE channel. 35 * - a single (master) drive in each IDE channel.
36 * - all drives are up and spinning. 36 * - all drives are up and spinning.
37 */ 37 */
38 38
39#include <sys/types.h> 39#include <sys/types.h>
40 40
41#include <lib/libsa/stand.h> 41#include <lib/libsa/stand.h>
42#include <lib/libsa/ufs.h> 42#include <lib/libsa/ufs.h>
43 43
44#include <sys/disklabel.h> 44#include <sys/disklabel.h>
45#include <sys/bootblock.h> 45#include <sys/bootblock.h>
46 46
47#include <machine/bootinfo.h> 47#include <machine/bootinfo.h>
48#include <machine/stdarg.h> 48#include <machine/stdarg.h>
49 49
50#include "globals.h" 50#include "globals.h"
51 51
52/* 52/*
53 * - no vtophys() translation, vaddr_t == paddr_t. 53 * - no vtophys() translation, vaddr_t == paddr_t.
54 */ 54 */
55#define CSR_READ_4(r) in32rb(r) 55#define CSR_READ_4(r) in32rb(r)
56#define CSR_WRITE_4(r,v) out32rb(r,v) 56#define CSR_WRITE_4(r,v) out32rb(r,v)
57#define CSR_READ_1(r) *(volatile uint8_t *)(r) 57#define CSR_READ_1(r) *(volatile uint8_t *)(r)
58#define CSR_WRITE_1(r,v) *(volatile uint8_t *)(r)=(v) 58#define CSR_WRITE_1(r,v) *(volatile uint8_t *)(r)=(v)
59 59
60#define DSK_DECL(xxx) \ 60#define DSK_DECL(xxx) \
61 int xxx ## _match(unsigned, void *); \ 61 int xxx ## _match(unsigned, void *); \
62 void * xxx ## _init(unsigned, void *) 62 void * xxx ## _init(unsigned, void *)
63 63
64DSK_DECL(pciide); 64DSK_DECL(pciide);
65DSK_DECL(siisata); 65DSK_DECL(siisata);
66 66
67struct dskdv { 67struct dskdv {
68 char *name; 68 char *name;
69 int (*match)(unsigned, void *); 69 int (*match)(unsigned, void *);
70 void *(*init)(unsigned, void *); 70 void *(*init)(unsigned, void *);
71 void *priv; 71 void *priv;
72}; 72};
73 73
74static struct dskdv ldskdv[] = { 74static struct dskdv ldskdv[] = {
75 { "pciide", pciide_match, pciide_init, }, 75 { "pciide", pciide_match, pciide_init, },
76 { "siisata", siisata_match, siisata_init, }, 76 { "siisata", siisata_match, siisata_init, },
77}; 77};
78static int ndskdv = sizeof(ldskdv)/sizeof(ldskdv[0]); 78static int ndskdv = sizeof(ldskdv)/sizeof(ldskdv[0]);
79 79
80static int probe_drive(struct dkdev_ata *, int); 80static int probe_drive(struct dkdev_ata *, int);
81static void drive_ident(struct disk *, char *); 81static void drive_ident(struct disk *, char *);
82static char *mkident(char *, int); 82static char *mkident(char *, int);
83static void set_xfermode(struct dkdev_ata *, int); 83static void set_xfermode(struct dkdev_ata *, int);
84static void decode_dlabel(struct disk *, char *); 84static void decode_dlabel(struct disk *, char *);
85static int lba_read(struct disk *, uint64_t, uint32_t, void *); 85static int lba_read(struct disk *, int64_t, int, void *);
86static void issue48(struct dvata_chan *, uint64_t, uint32_t); 86static void issue48(struct dvata_chan *, int64_t, int);
87static void issue28(struct dvata_chan *, uint64_t, uint32_t); 87static void issue28(struct dvata_chan *, int64_t, int);
88static struct disk *lookup_disk(int); 88static struct disk *lookup_disk(int);
89 89
90static struct disk ldisk[4]; 90static struct disk ldisk[4];
91 91
92int 92int
93dskdv_init(unsigned tag, void **cookie) 93dskdv_init(unsigned tag, void **cookie)
94{ 94{
95 struct dskdv *dv; 95 struct dskdv *dv;
96 int n; 96 int n;
97 97
98 for (n = 0; n < ndskdv; n++) { 98 for (n = 0; n < ndskdv; n++) {
99 dv = &ldskdv[n]; 99 dv = &ldskdv[n];
100 if ((*dv->match)(tag, NULL) > 0) 100 if ((*dv->match)(tag, NULL) > 0)
101 goto found; 101 goto found;
102 } 102 }
103 return 0; 103 return 0;
104 found: 104 found:
105 dv->priv = (*dv->init)(tag, NULL); 105 dv->priv = (*dv->init)(tag, NULL);
106 *cookie = dv; 106 *cookie = dv;
107 return 1; 107 return 1;
108} 108}
109 109
110int 110int
111disk_scan(void *cookie) 111disk_scan(void *cookie)
112{ 112{
113 struct dskdv *dv = cookie; 113 struct dskdv *dv = cookie;
114 struct dkdev_ata *l = dv->priv; 114 struct dkdev_ata *l = dv->priv;
115 struct disk *d; 115 struct disk *d;
116 int n, ndrive; 116 int n, ndrive;
117 117
118 ndrive = 0; 118 ndrive = 0;
119 for (n = 0; n < 4; n++) { 119 for (n = 0; n < 4; n++) {
120 if (l->presense[n] == 0) 120 if (l->presense[n] == 0)
121 continue; 121 continue;
122 if (probe_drive(l, n) == 0) { 122 if (probe_drive(l, n) == 0) {
123 l->presense[n] = 0; 123 l->presense[n] = 0;
124 continue; 124 continue;
125 } 125 }
126 d = &ldisk[ndrive]; 126 d = &ldisk[ndrive];
127 d->dvops = l; 127 d->dvops = l;
128 d->unittag = ndrive; 128 d->unittag = ndrive;
129 snprintf(d->xname, sizeof(d->xname), "wd%d", d->unittag); 129 snprintf(d->xname, sizeof(d->xname), "wd%d", d->unittag);
130 set_xfermode(l, n); 130 set_xfermode(l, n);
131 drive_ident(d, l->iobuf); 131 drive_ident(d, l->iobuf);
132 decode_dlabel(d, l->iobuf); 132 decode_dlabel(d, l->iobuf);
133 ndrive += 1; 133 ndrive += 1;
134 } 134 }
135 return ndrive; 135 return ndrive;
136} 136}
137 137
138int 138int
139spinwait_unbusy(struct dkdev_ata *l, int n, int milli, const char **err) 139spinwait_unbusy(struct dkdev_ata *l, int n, int milli, const char **err)
140{ 140{
141 struct dvata_chan *chan = &l->chan[n]; 141 struct dvata_chan *chan = &l->chan[n];
142 int sts; 142 int sts;
143 const char *msg; 143 const char *msg;
144 144
145 /* 145 /*
146 * For best compatibility it is recommended to wait 400ns and 146 * For best compatibility it is recommended to wait 400ns and
147 * read the alternate status byte four times before the status 147 * read the alternate status byte four times before the status
148 * is valid. 148 * is valid.
149 */ 149 */
150 delay(1); 150 delay(1);
151 (void)CSR_READ_1(chan->alt); 151 (void)CSR_READ_1(chan->alt);
152 (void)CSR_READ_1(chan->alt); 152 (void)CSR_READ_1(chan->alt);
153 (void)CSR_READ_1(chan->alt); 153 (void)CSR_READ_1(chan->alt);
154 (void)CSR_READ_1(chan->alt); 154 (void)CSR_READ_1(chan->alt);
155 155
156 sts = CSR_READ_1(chan->cmd + _STS); 156 sts = CSR_READ_1(chan->cmd + _STS);
157 while (milli-- > 0 157 while (milli-- > 0
158 && sts != 0xff 158 && sts != 0xff
159 && (sts & (ATA_STS_BUSY|ATA_STS_DRDY)) != ATA_STS_DRDY) { 159 && (sts & (ATA_STS_BUSY|ATA_STS_DRDY)) != ATA_STS_DRDY) {
160 delay(1000); 160 delay(1000);
161 sts = CSR_READ_1(chan->cmd + _STS); 161 sts = CSR_READ_1(chan->cmd + _STS);
162 } 162 }
163 163
164 msg = NULL; 164 msg = NULL;
165 if (sts == 0xff) 165 if (sts == 0xff)
166 msg = "returned 0xff"; 166 msg = "returned 0xff";
167 else if (sts & ATA_STS_ERR) 167 else if (sts & ATA_STS_ERR)
168 msg = "returned ERR"; 168 msg = "returned ERR";
169 else if (sts & ATA_STS_BUSY) 169 else if (sts & ATA_STS_BUSY)
170 msg = "remains BUSY"; 170 msg = "remains BUSY";
171 else if ((sts & ATA_STS_DRDY) == 0) 171 else if ((sts & ATA_STS_DRDY) == 0)
172 msg = "no DRDY"; 172 msg = "no DRDY";
173 173
174 if (err != NULL) 174 if (err != NULL)
175 *err = msg; 175 *err = msg;
176 return msg == NULL; 176 return msg == NULL;
177} 177}
178 178
179int 179int
180perform_atareset(struct dkdev_ata *l, int n) 180perform_atareset(struct dkdev_ata *l, int n)
181{ 181{
182 struct dvata_chan *chan = &l->chan[n]; 182 struct dvata_chan *chan = &l->chan[n];
183 183
184 CSR_WRITE_1(chan->ctl, ATA_DREQ); 184 CSR_WRITE_1(chan->ctl, ATA_DREQ);
185 delay(10); 185 delay(10);
186 CSR_WRITE_1(chan->ctl, ATA_SRST|ATA_DREQ); 186 CSR_WRITE_1(chan->ctl, ATA_SRST|ATA_DREQ);
187 delay(10); 187 delay(10);
188 CSR_WRITE_1(chan->ctl, ATA_DREQ); 188 CSR_WRITE_1(chan->ctl, ATA_DREQ);
189 189
190 return spinwait_unbusy(l, n, 150, NULL); 190 return spinwait_unbusy(l, n, 150, NULL);
191} 191}
192 192
193int 193int
194satapresense(struct dkdev_ata *l, int n) 194satapresense(struct dkdev_ata *l, int n)
195{ 195{
196#define VND_CH(n) (((n&02)<<8)+((n&01)<<7)) 196#define VND_CH(n) (((n&02)<<8)+((n&01)<<7))
197#define VND_SC(n) (0x100+VND_CH(n)) 197#define VND_SC(n) (0x100+VND_CH(n))
198#define VND_SS(n) (0x104+VND_CH(n)) 198#define VND_SS(n) (0x104+VND_CH(n))
199 199
200 uint32_t sc = l->bar[5] + VND_SC(n); 200 uint32_t sc = l->bar[5] + VND_SC(n);
201 uint32_t ss = l->bar[5] + VND_SS(n); 201 uint32_t ss = l->bar[5] + VND_SS(n);
202 unsigned val; 202 unsigned val;
203 203
204 val = (00 << 4) | (03 << 8); /* any speed, no pwrmgt */ 204 val = (00 << 4) | (03 << 8); /* any speed, no pwrmgt */
205 CSR_WRITE_4(sc, val | 01); /* perform init */ 205 CSR_WRITE_4(sc, val | 01); /* perform init */
206 delay(50 * 1000); 206 delay(50 * 1000);
207 CSR_WRITE_4(sc, val); 207 CSR_WRITE_4(sc, val);
208 delay(50 * 1000);  208 delay(50 * 1000);
209 val = CSR_READ_4(ss); /* has completed */ 209 val = CSR_READ_4(ss); /* has completed */
210 return ((val & 03) == 03); /* active drive found */ 210 return ((val & 03) == 03); /* active drive found */
211} 211}
212 212
213static int 213static int
214probe_drive(struct dkdev_ata *l, int n) 214probe_drive(struct dkdev_ata *l, int n)
215{ 215{
216 struct dvata_chan *chan = &l->chan[n]; 216 struct dvata_chan *chan = &l->chan[n];
217 uint16_t *p; 217 uint16_t *p;
218 int i; 218 int i;
219  219
220 CSR_WRITE_1(chan->cmd + _CMD, ATA_CMD_IDENT); 220 CSR_WRITE_1(chan->cmd + _CMD, ATA_CMD_IDENT);
221 (void)CSR_READ_1(chan->alt); 221 (void)CSR_READ_1(chan->alt);
222 delay(10 * 1000); 222 delay(10 * 1000);
223 if (spinwait_unbusy(l, n, 1000, NULL) == 0) 223 if (spinwait_unbusy(l, n, 1000, NULL) == 0)
224 return 0; 224 return 0;
225 225
226 p = (uint16_t *)l->iobuf; 226 p = (uint16_t *)l->iobuf;
227 for (i = 0; i < 512; i += 2) { 227 for (i = 0; i < 512; i += 2) {
228 /* need to have bswap16 */ 228 /* need to have bswap16 */
229 *p++ = iole16toh(chan->cmd + _DAT); 229 *p++ = iole16toh(chan->cmd + _DAT);
230 } 230 }
231 (void)CSR_READ_1(chan->cmd + _STS); 231 (void)CSR_READ_1(chan->cmd + _STS);
232 return 1; 232 return 1;
233} 233}
234 234
235static void 235static void
236drive_ident(struct disk *d, char *ident) 236drive_ident(struct disk *d, char *ident)
237{ 237{
238 uint16_t *p; 238 uint16_t *p;
239 uint64_t huge; 239 uint64_t huge;
240 240
241 p = (uint16_t *)ident; 241 p = (uint16_t *)ident;
242#if 1 242#if 1
243 printf("[49]%04x [82]%04x [83]%04x [84]%04x " 243 printf("[49]%04x [82]%04x [83]%04x [84]%04x "
244 "[85]%04x [86]%04x [87]%04x [88]%04x\n", 244 "[85]%04x [86]%04x [87]%04x [88]%04x\n",
245 p[49], p[82], p[83], p[84], 245 p[49], p[82], p[83], p[84],
246 p[85], p[86], p[87], p[88]); 246 p[85], p[86], p[87], p[88]);
247#endif 247#endif
248 huge = 0; 248 huge = 0;
249 printf("%s: ", d->xname); 249 printf("%s: ", d->xname);
250 printf("<%s> ", mkident((char *)ident + 54, 40)); 250 printf("<%s> ", mkident((char *)ident + 54, 40));
251 if (p[49] & (1 << 8)) 251 if (p[49] & (1 << 8))
252 printf("DMA "); 252 printf("DMA ");
253 if (p[49] & (1 << 9)) { 253 if (p[49] & (1 << 9)) {
254 printf("LBA "); 254 printf("LBA ");
255 huge = p[60] | (p[61] << 16); 255 huge = p[60] | (p[61] << 16);
256 } 256 }
257 if ((p[83] & 0xc000) == 0x4000 && (p[83] & (1 << 10))) { 257 if ((p[83] & 0xc000) == 0x4000 && (p[83] & (1 << 10))) {
258 printf("LBA48 "); 258 printf("LBA48 ");
259 huge = p[100] | (p[101] << 16); 259 huge = p[100] | (p[101] << 16);
260 huge |= (uint64_t)p[102] << 32; 260 huge |= (uint64_t)p[102] << 32;
261 huge |= (uint64_t)p[103] << 48; 261 huge |= (uint64_t)p[103] << 48;
262 } 262 }
263 huge >>= (1 + 10); 263 huge >>= (1 + 10);
264 printf("%d MB\n", (int)huge); 264 printf("%d MB\n", (int)huge);
265 265
266 memcpy(d->ident, ident, sizeof(d->ident)); 266 memcpy(d->ident, ident, sizeof(d->ident));
267 d->nsect = huge; 267 d->nsect = huge;
268 d->lba_read = lba_read; 268 d->lba_read = lba_read;
269} 269}
270 270
271static char * 271static char *
272mkident(char *src, int len) 272mkident(char *src, int len)
273{ 273{
274 static char local[40]; 274 static char local[40];
275 char *dst, *end, *last; 275 char *dst, *end, *last;
276  276
277 if (len > sizeof(local)) 277 if (len > sizeof(local))
278 len = sizeof(local); 278 len = sizeof(local);
279 dst = last = local; 279 dst = last = local;
280 end = src + len - 1; 280 end = src + len - 1;
281 281
282 /* reserve space for '\0' */ 282 /* reserve space for '\0' */
283 if (len < 2) 283 if (len < 2)
284 goto out; 284 goto out;
285 /* skip leading white space */ 285 /* skip leading white space */
286 while (*src != '\0' && src < end && *src == ' ') 286 while (*src != '\0' && src < end && *src == ' ')
287 ++src; 287 ++src;
288 /* copy string, omitting trailing white space */ 288 /* copy string, omitting trailing white space */
289 while (*src != '\0' && src < end) { 289 while (*src != '\0' && src < end) {
290 *dst++ = *src; 290 *dst++ = *src;
291 if (*src++ != ' ') 291 if (*src++ != ' ')
292 last = dst; 292 last = dst;
293 } 293 }
294 out: 294 out:
295 *last = '\0'; 295 *last = '\0';
296 return local; 296 return local;
297} 297}
298 298
299static void 299static void
300decode_dlabel(struct disk *d, char *iobuf) 300decode_dlabel(struct disk *d, char *iobuf)
301{ 301{
302 struct mbr_partition *mp, *bsdp; 302 struct mbr_partition *mp, *bsdp;
303 struct disklabel *dlp; 303 struct disklabel *dlp;
304 struct partition *pp; 304 struct partition *pp;
305 char *dp; 305 char *dp;
306 int i, first; 306 int i, first;
307 307
308 bsdp = NULL; 308 bsdp = NULL;
309 (*d->lba_read)(d, 0, 1, iobuf); 309 (*d->lba_read)(d, 0, 1, iobuf);
310 if (bswap16(*(uint16_t *)(iobuf + MBR_MAGIC_OFFSET)) != MBR_MAGIC) 310 if (bswap16(*(uint16_t *)(iobuf + MBR_MAGIC_OFFSET)) != MBR_MAGIC)
311 goto skip; 311 goto skip;
312 mp = (struct mbr_partition *)(iobuf + MBR_PART_OFFSET); 312 mp = (struct mbr_partition *)(iobuf + MBR_PART_OFFSET);
313 for (i = 0; i < MBR_PART_COUNT; i++, mp++) { 313 for (i = 0; i < MBR_PART_COUNT; i++, mp++) {
314 if (mp->mbrp_type == MBR_PTYPE_NETBSD) { 314 if (mp->mbrp_type == MBR_PTYPE_NETBSD) {
315 bsdp = mp; 315 bsdp = mp;
316 break; 316 break;
317 } 317 }
318 } 318 }
319 skip: 319 skip:
320 first = (bsdp) ? bswap32(bsdp->mbrp_start) : 0; 320 first = (bsdp) ? bswap32(bsdp->mbrp_start) : 0;
321 (*d->lba_read)(d, first + LABELSECTOR, 1, iobuf); 321 (*d->lba_read)(d, first + LABELSECTOR, 1, iobuf);
322 dp = iobuf /* + LABELOFFSET */; 322 dp = iobuf /* + LABELOFFSET */;
323 for (i = 0; i < 512 - sizeof(struct disklabel); i++, dp += 4) { 323 for (i = 0; i < 512 - sizeof(struct disklabel); i++, dp += 4) {
324 dlp = (struct disklabel *)dp; 324 dlp = (struct disklabel *)dp;
325 if (dlp->d_magic == DISKMAGIC && dlp->d_magic2 == DISKMAGIC) { 325 if (dlp->d_magic == DISKMAGIC && dlp->d_magic2 == DISKMAGIC) {
326 goto found; 326 goto found;
327 } 327 }
328 } 328 }
329 d->dlabel = NULL; 329 d->dlabel = NULL;
330 printf("%s: no disklabel\n", d->xname); 330 printf("%s: no disklabel\n", d->xname);
331 return; 331 return;
332 found: 332 found:
333 d->dlabel = allocaligned(sizeof(struct disklabel), 4); 333 d->dlabel = allocaligned(sizeof(struct disklabel), 4);
334 memcpy(d->dlabel, dlp, sizeof(struct disklabel)); 334 memcpy(d->dlabel, dlp, sizeof(struct disklabel));
335#if 1 335#if 1
336 for (i = 0; i < dlp->d_npartitions; i += 1) { 336 for (i = 0; i < dlp->d_npartitions; i += 1) {
337 const char *type; 337 const char *type;
338 pp = &dlp->d_partitions[i]; 338 pp = &dlp->d_partitions[i];
339 type = NULL; 339 type = NULL;
340 switch (pp->p_fstype) { 340 switch (pp->p_fstype) {
341 case FS_SWAP: /* swap */ 341 case FS_SWAP: /* swap */
342 type = "swap"; 342 type = "swap";
343 break; 343 break;
344 case FS_BSDFFS: 344 case FS_BSDFFS:
345 type = "ffs"; 345 type = "ffs";
346 break; 346 break;
347 case FS_EX2FS: 347 case FS_EX2FS:
348 type = "ext2fs"; 348 type = "ext2fs";
349 break; 349 break;
350 } 350 }
351 if (type != NULL) 351 if (type != NULL)
352 printf("%s%c: %s\n", d->xname, i + 'a', type); 352 printf("%s%c: %s\n", d->xname, i + 'a', type);
353 } 353 }
354#endif 354#endif
355} 355}
356 356
357static void 357static void
358set_xfermode(struct dkdev_ata *l, int n) 358set_xfermode(struct dkdev_ata *l, int n)
359{ 359{
360 struct dvata_chan *chan = &l->chan[n]; 360 struct dvata_chan *chan = &l->chan[n];
361 361
362 CSR_WRITE_1(chan->cmd + _FEA, ATA_XFER); 362 CSR_WRITE_1(chan->cmd + _FEA, ATA_XFER);
363 CSR_WRITE_1(chan->cmd + _NSECT, XFER_PIO0); 363 CSR_WRITE_1(chan->cmd + _NSECT, XFER_PIO0);
364 CSR_WRITE_1(chan->cmd + _DEV, ATA_DEV_OBS); /* ??? */ 364 CSR_WRITE_1(chan->cmd + _DEV, ATA_DEV_OBS); /* ??? */
365 CSR_WRITE_1(chan->cmd + _CMD, ATA_CMD_SETF); 365 CSR_WRITE_1(chan->cmd + _CMD, ATA_CMD_SETF);
366 366
367 spinwait_unbusy(l, n, 1000, NULL); 367 spinwait_unbusy(l, n, 1000, NULL);
368} 368}
369 369
370static int 370static int
371lba_read(struct disk *d, uint64_t bno, uint32_t bcnt, void *buf) 371lba_read(struct disk *d, int64_t bno, int bcnt, void *buf)
372{ 372{
373 struct dkdev_ata *l; 373 struct dkdev_ata *l;
374 struct dvata_chan *chan; 374 struct dvata_chan *chan;
375 void (*issue)(struct dvata_chan *, uint64_t, uint32_t); 375 void (*issue)(struct dvata_chan *, int64_t, int);
376 int n, rdcnt, i, k; 376 int n, rdcnt, i, k;
377 uint16_t *p; 377 uint16_t *p;
378 const char *err; 378 const char *err;
379 int error; 379 int error;
380 380
381 l = d->dvops; 381 l = d->dvops;
382 n = d->unittag; 382 n = d->unittag;
383 p = (uint16_t *)buf; 383 p = (uint16_t *)buf;
384 chan = &l->chan[n]; 384 chan = &l->chan[n];
385 error = 0; 385 error = 0;
386 for ( ; bcnt > 0; bno += rdcnt, bcnt -= rdcnt) { 386 for ( ; bcnt > 0; bno += rdcnt, bcnt -= rdcnt) {
387 issue = (bno < (1ULL<<28)) ? issue28 : issue48; 387 issue = (bno < (1ULL<<28)) ? issue28 : issue48;
388 rdcnt = (bcnt > 255) ? 255 : bcnt; 388 rdcnt = (bcnt > 255) ? 255 : bcnt;
389 (*issue)(chan, bno, rdcnt); 389 (*issue)(chan, bno, rdcnt);
390 for (k = 0; k < rdcnt; k++) { 390 for (k = 0; k < rdcnt; k++) {
391 if (spinwait_unbusy(l, n, 1000, &err) == 0) { 391 if (spinwait_unbusy(l, n, 1000, &err) == 0) {
392 printf("%s blk %d %s\n", 392 printf("%s blk %lld %s\n", d->xname, bno, err);
393 d->xname, (int)bno, err); 
394 error = EIO; 393 error = EIO;
395 break; 394 break;
396 } 395 }
397 for (i = 0; i < 512; i += 2) { 396 for (i = 0; i < 512; i += 2) {
398 /* arrives in native order */ 397 /* arrives in native order */
399 *p++ = *(uint16_t *)(chan->cmd + _DAT); 398 *p++ = *(uint16_t *)(chan->cmd + _DAT);
400 } 399 }
401 /* clear irq if any */ 400 /* clear irq if any */
402 (void)CSR_READ_1(chan->cmd + _STS); 401 (void)CSR_READ_1(chan->cmd + _STS);
403 } 402 }
404 } 403 }
405 return error; 404 return error;
406} 405}
407 406
408static void 407static void
409issue48(struct dvata_chan *chan, uint64_t bno, uint32_t nblk) 408issue48(struct dvata_chan *chan, int64_t bno, int nblk)
410{ 409{
411 410
412 CSR_WRITE_1(chan->cmd + _NSECT, 0); /* always less than 256 */ 411 CSR_WRITE_1(chan->cmd + _NSECT, 0); /* always less than 256 */
413 CSR_WRITE_1(chan->cmd + _LBAL, (bno >> 24) & 0xff); 412 CSR_WRITE_1(chan->cmd + _LBAL, (bno >> 24) & 0xff);
414 CSR_WRITE_1(chan->cmd + _LBAM, (bno >> 32) & 0xff); 413 CSR_WRITE_1(chan->cmd + _LBAM, (bno >> 32) & 0xff);
415 CSR_WRITE_1(chan->cmd + _LBAH, (bno >> 40) & 0xff); 414 CSR_WRITE_1(chan->cmd + _LBAH, (bno >> 40) & 0xff);
416 CSR_WRITE_1(chan->cmd + _NSECT, nblk); 415 CSR_WRITE_1(chan->cmd + _NSECT, nblk);
417 CSR_WRITE_1(chan->cmd + _LBAL, (bno >> 0) & 0xff); 416 CSR_WRITE_1(chan->cmd + _LBAL, (bno >> 0) & 0xff);
418 CSR_WRITE_1(chan->cmd + _LBAM, (bno >> 8) & 0xff); 417 CSR_WRITE_1(chan->cmd + _LBAM, (bno >> 8) & 0xff);
419 CSR_WRITE_1(chan->cmd + _LBAH, (bno >> 16) & 0xff); 418 CSR_WRITE_1(chan->cmd + _LBAH, (bno >> 16) & 0xff);
420 CSR_WRITE_1(chan->cmd + _DEV, ATA_DEV_LBA); 419 CSR_WRITE_1(chan->cmd + _DEV, ATA_DEV_LBA);
421 CSR_WRITE_1(chan->cmd + _CMD, ATA_CMD_READ_EXT); 420 CSR_WRITE_1(chan->cmd + _CMD, ATA_CMD_READ_EXT);
422} 421}
423 422
424static void 423static void
425issue28(struct dvata_chan *chan, uint64_t bno, uint32_t nblk) 424issue28(struct dvata_chan *chan, int64_t bno, int nblk)
426{ 425{
427 426
428 CSR_WRITE_1(chan->cmd + _NSECT, nblk); 427 CSR_WRITE_1(chan->cmd + _NSECT, nblk);
429 CSR_WRITE_1(chan->cmd + _LBAL, (bno >> 0) & 0xff); 428 CSR_WRITE_1(chan->cmd + _LBAL, (bno >> 0) & 0xff);
430 CSR_WRITE_1(chan->cmd + _LBAM, (bno >> 8) & 0xff); 429 CSR_WRITE_1(chan->cmd + _LBAM, (bno >> 8) & 0xff);
431 CSR_WRITE_1(chan->cmd + _LBAH, (bno >> 16) & 0xff); 430 CSR_WRITE_1(chan->cmd + _LBAH, (bno >> 16) & 0xff);
432 CSR_WRITE_1(chan->cmd + _DEV, ((bno >> 24) & 0xf) | ATA_DEV_LBA); 431 CSR_WRITE_1(chan->cmd + _DEV, ((bno >> 24) & 0xf) | ATA_DEV_LBA);
433 CSR_WRITE_1(chan->cmd + _CMD, ATA_CMD_READ); 432 CSR_WRITE_1(chan->cmd + _CMD, ATA_CMD_READ);
434} 433}
435 434
436static struct disk * 435static struct disk *
437lookup_disk(int unit) 436lookup_disk(int unit)
438{ 437{
439 438
440 return &ldisk[unit]; 439 return &ldisk[unit];
441} 440}
442 441
443int 442int
444dsk_open(struct open_file *f, ...) 443dsk_open(struct open_file *f, ...)
445{ 444{
446 va_list ap; 445 va_list ap;
447 int unit, part; 446 int unit, part;
448 const char *name; 447 const char *name;
449 struct disk *d; 448 struct disk *d;
450 struct disklabel *dlp; 449 struct disklabel *dlp;
451 struct fs_ops *fs; 450 struct fs_ops *fs;
452 int error; 451 int error;
453 extern struct btinfo_bootpath bi_path; 452 extern struct btinfo_bootpath bi_path;
454 extern struct btinfo_rootdevice bi_rdev; 453 extern struct btinfo_rootdevice bi_rdev;
455 extern struct fs_ops fs_ffsv2, fs_ffsv1; 454 extern struct fs_ops fs_ffsv2, fs_ffsv1;
456 455
457 va_start(ap, f); 456 va_start(ap, f);
458 unit = va_arg(ap, int); 457 unit = va_arg(ap, int);
459 part = va_arg(ap, int); 458 part = va_arg(ap, int);
460 name = va_arg(ap, const char *); 459 name = va_arg(ap, const char *);
461 va_end(ap); 460 va_end(ap);
462 461
463 if ((d = lookup_disk(unit)) == NULL) 462 if ((d = lookup_disk(unit)) == NULL)
464 return ENXIO; 463 return ENXIO;
465 f->f_devdata = d; 464 f->f_devdata = d;
466 if ((dlp = d->dlabel) == NULL || part >= dlp->d_npartitions) 465 if ((dlp = d->dlabel) == NULL || part >= dlp->d_npartitions)
467 return ENXIO; 466 return ENXIO;
468 d->part = part; 467 d->part = part;
469 468
470 snprintf(bi_path.bootpath, sizeof(bi_path.bootpath), name); 469 snprintf(bi_path.bootpath, sizeof(bi_path.bootpath), name);
471 if (dlp->d_partitions[part].p_fstype == FS_BSDFFS) { 470 if (dlp->d_partitions[part].p_fstype == FS_BSDFFS) {
472 if ((error = ffsv2_open(name, f)) == 0) { 471 if ((error = ffsv2_open(name, f)) == 0) {
473 fs = &fs_ffsv2; 472 fs = &fs_ffsv2;
474 goto found; 473 goto found;
475 } 474 }
476 if (error == EINVAL && (error = ffsv1_open(name, f)) == 0) { 475 if (error == EINVAL && (error = ffsv1_open(name, f)) == 0) {
477 fs = &fs_ffsv1; 476 fs = &fs_ffsv1;
478 goto found; 477 goto found;
479 } 478 }
480 return error; 479 return error;
481 } 480 }
482 return ENXIO; 481 return ENXIO;
483 found: 482 found:
484#if 0 483#if 0
485printf("dsk_open found %s\n", fsmod); 484printf("dsk_open found %s\n", fsmod);
486#endif 485#endif
487 d->fsops = fs; 486 d->fsops = fs;
488 f->f_devdata = d; 487 f->f_devdata = d;
489 488
490 /* build btinfo to identify disk device */ 489 /* build btinfo to identify disk device */
491 snprintf(bi_rdev.devname, sizeof(bi_rdev.devname), "wd"); 490 snprintf(bi_rdev.devname, sizeof(bi_rdev.devname), "wd");
492 bi_rdev.cookie = d->unittag; /* disk unit number */ 491 bi_rdev.cookie = d->unittag; /* disk unit number */
493 return 0; 492 return 0;
494} 493}
495 494
496int 495int
497dsk_close(struct open_file *f) 496dsk_close(struct open_file *f)
498{ 497{
499 struct disk *d = f->f_devdata; 498 struct disk *d = f->f_devdata;
500 struct fs_ops *fs = d->fsops; 499 struct fs_ops *fs = d->fsops;
501 500
502 (*fs->close)(f); 501 (*fs->close)(f);
503 d->fsops = NULL; 502 d->fsops = NULL;
504 f->f_devdata = NULL; 503 f->f_devdata = NULL;
505 return 0; 504 return 0;
506} 505}
507 506
508int 507int
509dsk_strategy(void *devdata, int rw, daddr_t dblk, size_t size, 508dsk_strategy(void *devdata, int rw, daddr_t dblk, size_t size,
510 void *p, size_t *rsize) 509 void *p, size_t *rsize)
511{ 510{
512 struct disk *d = devdata; 511 struct disk *d = devdata;
513 struct disklabel *dlp; 512 struct disklabel *dlp;
514 uint64_t bno; 513 int64_t bno;
515 514
516#if 0 515#if 0
517printf("%s %d %d\n", d->xname, (int)dblk, size); 516printf("%s %lld %d\n", d->xname, dblk, size);
518#endif 517#endif
519 if (size == 0) 518 if (size == 0)
520 return 0; 519 return 0;
521 if (rw != F_READ) 520 if (rw != F_READ)
522 return EOPNOTSUPP; 521 return EOPNOTSUPP;
523 522
524 bno = dblk; 523 bno = dblk;
525 if ((dlp = d->dlabel) != NULL) 524 if ((dlp = d->dlabel) != NULL)
526 bno += dlp->d_partitions[d->part].p_offset; 525 bno += dlp->d_partitions[d->part].p_offset;
527 (*d->lba_read)(d, bno, size / 512, p); 526 (*d->lba_read)(d, bno, size / 512, p);
528 if (rsize != NULL) 527 if (rsize != NULL)
529 *rsize = size; 528 *rsize = size;
530 return 0; 529 return 0;
531} 530}
532 531
533struct fs_ops * 532struct fs_ops *
534dsk_fsops(struct open_file *f) 533dsk_fsops(struct open_file *f)
535{ 534{
536 struct disk *d = f->f_devdata; 535 struct disk *d = f->f_devdata;
537 536
538 return d->fsops; 537 return d->fsops;
539} 538}

cvs diff -r1.1 -r1.2 src/sys/arch/sandpoint/stand/altboot/globals.h (switch to unified diff)

--- src/sys/arch/sandpoint/stand/altboot/globals.h 2011/01/23 01:05:30 1.1
+++ src/sys/arch/sandpoint/stand/altboot/globals.h 2011/01/23 01:32:08 1.2
@@ -1,194 +1,194 @@ @@ -1,194 +1,194 @@
1/* $NetBSD: globals.h,v 1.1 2011/01/23 01:05:30 nisimura Exp $ */ 1/* $NetBSD: globals.h,v 1.2 2011/01/23 01:32:08 nisimura Exp $ */
2 2
3/* clock feed */ 3/* clock feed */
4#ifndef EXT_CLK_FREQ 4#ifndef EXT_CLK_FREQ
5#define EXT_CLK_FREQ 33333333 /* external clock (PCI clock) */ 5#define EXT_CLK_FREQ 33333333 /* external clock (PCI clock) */
6#endif 6#endif
7 7
8/* brd type */ 8/* brd type */
9extern int brdtype; 9extern int brdtype;
10#define BRD_SANDPOINTX2 2 10#define BRD_SANDPOINTX2 2
11#define BRD_SANDPOINTX3 3 11#define BRD_SANDPOINTX3 3
12#define BRD_ENCOREPP1 10 12#define BRD_ENCOREPP1 10
13#define BRD_KUROBOX 100 13#define BRD_KUROBOX 100
14#define BRD_QNAPTS101 101 14#define BRD_QNAPTS101 101
15#define BRD_SYNOLOGY 102 15#define BRD_SYNOLOGY 102
16#define BRD_STORCENTER 103 16#define BRD_STORCENTER 103
17#define BRD_UNKNOWN -1 17#define BRD_UNKNOWN -1
18 18
19struct brdprop { 19struct brdprop {
20 const char *family; 20 const char *family;
21 const char *verbose; 21 const char *verbose;
22 int brdtype; 22 int brdtype;
23 uint32_t extclk; 23 uint32_t extclk;
24 char *consname; 24 char *consname;
25 int consport; 25 int consport;
26 int consspeed; 26 int consspeed;
27 void (*setup)(struct brdprop *); 27 void (*setup)(struct brdprop *);
28 void (*brdfix)(struct brdprop *); 28 void (*brdfix)(struct brdprop *);
29 void (*pcifix)(struct brdprop *); 29 void (*pcifix)(struct brdprop *);
30 void (*reset)(void); 30 void (*reset)(void);
31}; 31};
32 32
33extern uint32_t cpuclock, busclock; 33extern uint32_t cpuclock, busclock;
34 34
35/* board specific support code */ 35/* board specific support code */
36struct brdprop *brd_lookup(int); 36struct brdprop *brd_lookup(int);
37unsigned mpc107memsize(void); 37unsigned mpc107memsize(void);
38void read_mac_from_flash(uint8_t *); 38void read_mac_from_flash(uint8_t *);
39 39
40/* PPC processor ctl */ 40/* PPC processor ctl */
41void __syncicache(void *, size_t); 41void __syncicache(void *, size_t);
42 42
43/* byte swap access */ 43/* byte swap access */
44void out16rb(unsigned, unsigned); 44void out16rb(unsigned, unsigned);
45void out32rb(unsigned, unsigned); 45void out32rb(unsigned, unsigned);
46unsigned in16rb(unsigned); 46unsigned in16rb(unsigned);
47unsigned in32rb(unsigned); 47unsigned in32rb(unsigned);
48void iohtole16(unsigned, unsigned); 48void iohtole16(unsigned, unsigned);
49void iohtole32(unsigned, unsigned); 49void iohtole32(unsigned, unsigned);
50unsigned iole32toh(unsigned); 50unsigned iole32toh(unsigned);
51unsigned iole16toh(unsigned); 51unsigned iole16toh(unsigned);
52 52
53/* far call would never return */ 53/* far call would never return */
54void run(void *, void *, void *, void *, void *); 54void run(void *, void *, void *, void *, void *);
55 55
56/* micro second precision delay */ 56/* micro second precision delay */
57void delay(unsigned); 57void delay(unsigned);
58 58
59/* PCI stuff */ 59/* PCI stuff */
60void pcisetup(void); 60void pcisetup(void);
61void pcifixup(void); 61void pcifixup(void);
62unsigned pcimaketag(int, int, int); 62unsigned pcimaketag(int, int, int);
63void pcidecomposetag(unsigned, int *, int *, int *); 63void pcidecomposetag(unsigned, int *, int *, int *);
64int pcifinddev(unsigned, unsigned, unsigned *); 64int pcifinddev(unsigned, unsigned, unsigned *);
65int pcilookup(unsigned, unsigned [][2], int); 65int pcilookup(unsigned, unsigned [][2], int);
66unsigned pcicfgread(unsigned, int); 66unsigned pcicfgread(unsigned, int);
67void pcicfgwrite(unsigned, int, unsigned); 67void pcicfgwrite(unsigned, int, unsigned);
68 68
69#define PCI_ID_REG 0x00 69#define PCI_ID_REG 0x00
70#define PCI_COMMAND_STATUS_REG 0x04 70#define PCI_COMMAND_STATUS_REG 0x04
71#define PCI_VENDOR(id) ((id) & 0xffff) 71#define PCI_VENDOR(id) ((id) & 0xffff)
72#define PCI_PRODUCT(id) (((id) >> 16) & 0xffff) 72#define PCI_PRODUCT(id) (((id) >> 16) & 0xffff)
73#define PCI_VENDOR_INVALID 0xffff 73#define PCI_VENDOR_INVALID 0xffff
74#define PCI_DEVICE(v,p) ((v) | ((p) << 16)) 74#define PCI_DEVICE(v,p) ((v) | ((p) << 16))
75#define PCI_CLASS_REG 0x08 75#define PCI_CLASS_REG 0x08
76#define PCI_CLASS_PPB 0x0604 76#define PCI_CLASS_PPB 0x0604
77#define PCI_CLASS_ETH 0x0200 77#define PCI_CLASS_ETH 0x0200
78#define PCI_CLASS_IDE 0x0101 78#define PCI_CLASS_IDE 0x0101
79#define PCI_CLASS_RAID 0x0104 79#define PCI_CLASS_RAID 0x0104
80#define PCI_CLASS_SATA 0x0106 80#define PCI_CLASS_SATA 0x0106
81#define PCI_CLASS_MISCSTORAGE 0x0180 81#define PCI_CLASS_MISCSTORAGE 0x0180
82#define PCI_BHLC_REG 0x0c 82#define PCI_BHLC_REG 0x0c
83#define PCI_HDRTYPE_TYPE(r) (((r) >> 16) & 0x7f) 83#define PCI_HDRTYPE_TYPE(r) (((r) >> 16) & 0x7f)
84#define PCI_HDRTYPE_MULTIFN(r) ((r) & (0x80 << 16)) 84#define PCI_HDRTYPE_MULTIFN(r) ((r) & (0x80 << 16))
85 85
86/* 86/*
87 * "Map B" layout 87 * "Map B" layout
88 * 88 *
89 * practice direct mode configuration scheme with CONFIG_ADDR 89 * practice direct mode configuration scheme with CONFIG_ADDR
90 * (0xfec0'0000) and CONFIG_DATA (0xfee0'0000). 90 * (0xfec0'0000) and CONFIG_DATA (0xfee0'0000).
91 */ 91 */
92#define PCI_MEMBASE 0x80000000 /* PCI memory space */ 92#define PCI_MEMBASE 0x80000000 /* PCI memory space */
93#define PCI_MEMLIMIT 0xfbffffff /* EUMB is next to this */ 93#define PCI_MEMLIMIT 0xfbffffff /* EUMB is next to this */
94#define PCI_IOBASE 0x00001000 /* reserves room for southbridge */ 94#define PCI_IOBASE 0x00001000 /* reserves room for southbridge */
95#define PCI_IOLIMIT 0x000fffff 95#define PCI_IOLIMIT 0x000fffff
96#define PCI_XIOBASE 0xfe000000 /* ISA/PCI io space */ 96#define PCI_XIOBASE 0xfe000000 /* ISA/PCI io space */
97#define CONFIG_ADDR 0xfec00000 97#define CONFIG_ADDR 0xfec00000
98#define CONFIG_DATA 0xfee00000 98#define CONFIG_DATA 0xfee00000
99 99
100/* cache ops */ 100/* cache ops */
101void _wb(uint32_t, uint32_t); 101void _wb(uint32_t, uint32_t);
102void _wbinv(uint32_t, uint32_t); 102void _wbinv(uint32_t, uint32_t);
103void _inv(uint32_t, uint32_t); 103void _inv(uint32_t, uint32_t);
104 104
105/* heap */ 105/* heap */
106void *allocaligned(size_t, size_t); 106void *allocaligned(size_t, size_t);
107 107
108/* NIF support */ 108/* NIF support */
109int net_open(struct open_file *, ...); 109int net_open(struct open_file *, ...);
110int net_close(struct open_file *); 110int net_close(struct open_file *);
111int net_strategy(void *, int, daddr_t, size_t, void *, size_t *); 111int net_strategy(void *, int, daddr_t, size_t, void *, size_t *);
112 112
113int netif_init(unsigned); 113int netif_init(unsigned);
114int netif_open(void *);  114int netif_open(void *);
115int netif_close(int);  115int netif_close(int);
116 116
117#define NIF_DECL(xxx) \ 117#define NIF_DECL(xxx) \
118 int xxx ## _match(unsigned, void *); \ 118 int xxx ## _match(unsigned, void *); \
119 void * xxx ## _init(unsigned, void *); \ 119 void * xxx ## _init(unsigned, void *); \
120 int xxx ## _send(void *, char *, unsigned); \ 120 int xxx ## _send(void *, char *, unsigned); \
121 int xxx ## _recv(void *, char *, unsigned, unsigned) 121 int xxx ## _recv(void *, char *, unsigned, unsigned)
122 122
123NIF_DECL(fxp); 123NIF_DECL(fxp);
124NIF_DECL(tlp); 124NIF_DECL(tlp);
125NIF_DECL(rge); 125NIF_DECL(rge);
126NIF_DECL(skg); 126NIF_DECL(skg);
127 127
128/* DSK support */ 128/* DSK support */
129int dskdv_init(unsigned, void **); 129int dskdv_init(unsigned, void **);
130int disk_scan(void *); 130int disk_scan(void *);
131 131
132int dsk_open(struct open_file *, ...); 132int dsk_open(struct open_file *, ...);
133int dsk_close(struct open_file *); 133int dsk_close(struct open_file *);
134int dsk_strategy(void *, int, daddr_t, size_t, void *, size_t *); 134int dsk_strategy(void *, int, daddr_t, size_t, void *, size_t *);
135struct fs_ops *dsk_fsops(struct open_file *); 135struct fs_ops *dsk_fsops(struct open_file *);
136 136
137/* status */ 137/* status */
138#define ATA_STS_BUSY 0x80 138#define ATA_STS_BUSY 0x80
139#define ATA_STS_DRDY 0x40 139#define ATA_STS_DRDY 0x40
140#define ATA_STS_ERR 0x01 140#define ATA_STS_ERR 0x01
141/* command */ 141/* command */
142#define ATA_CMD_IDENT 0xec 142#define ATA_CMD_IDENT 0xec
143#define ATA_CMD_READ 0x20 143#define ATA_CMD_READ 0x20
144#define ATA_CMD_READ_EXT 0x24 144#define ATA_CMD_READ_EXT 0x24
145#define ATA_CMD_SETF 0xef 145#define ATA_CMD_SETF 0xef
146/* device */ 146/* device */
147#define ATA_DEV_LBA 0xe0 147#define ATA_DEV_LBA 0xe0
148#define ATA_DEV_OBS 0x90 148#define ATA_DEV_OBS 0x90
149/* control */ 149/* control */
150#define ATA_DREQ 0x08 150#define ATA_DREQ 0x08
151#define ATA_SRST 0x04 151#define ATA_SRST 0x04
152 152
153#define ATA_XFER 0x03 153#define ATA_XFER 0x03
154#define XFER_PIO4 0x0c 154#define XFER_PIO4 0x0c
155#define XFER_PIO0 0x08 155#define XFER_PIO0 0x08
156 156
157struct dvata_chan { 157struct dvata_chan {
158 uint32_t cmd, ctl, alt, dma; 158 uint32_t cmd, ctl, alt, dma;
159}; 159};
160#define _DAT 0 /* RW */ 160#define _DAT 0 /* RW */
161#define _ERR 1 /* R */ 161#define _ERR 1 /* R */
162#define _FEA 1 /* W */ 162#define _FEA 1 /* W */
163#define _NSECT 2 /* RW */ 163#define _NSECT 2 /* RW */
164#define _LBAL 3 /* RW */ 164#define _LBAL 3 /* RW */
165#define _LBAM 4 /* RW */ 165#define _LBAM 4 /* RW */
166#define _LBAH 5 /* RW */ 166#define _LBAH 5 /* RW */
167#define _DEV 6 /* W */ 167#define _DEV 6 /* W */
168#define _STS 7 /* R */ 168#define _STS 7 /* R */
169#define _CMD 7 /* W */ 169#define _CMD 7 /* W */
170 170
171struct dkdev_ata { 171struct dkdev_ata {
172 unsigned tag; 172 unsigned tag;
173 uint32_t bar[6]; 173 uint32_t bar[6];
174 struct dvata_chan chan[4]; 174 struct dvata_chan chan[4];
175 int presense[4]; 175 int presense[4];
176 char *iobuf; 176 char *iobuf;
177}; 177};
178 178
179struct disk { 179struct disk {
180 char xname[8]; 180 char xname[8];
181 void *dvops; 181 void *dvops;
182 unsigned unittag; 182 unsigned unittag;
183 uint16_t ident[128]; 183 uint16_t ident[128];
184 uint64_t nsect; 184 uint64_t nsect;
185 uint64_t first; 185 uint64_t first;
186 void *dlabel; 186 void *dlabel;
187 int part; 187 int part;
188 void *fsops; 188 void *fsops;
189 int (*lba_read)(struct disk *, uint64_t, uint32_t, void *); 189 int (*lba_read)(struct disk *, int64_t, int, void *);
190}; 190};
191 191
192int spinwait_unbusy(struct dkdev_ata *, int, int, const char **); 192int spinwait_unbusy(struct dkdev_ata *, int, int, const char **);
193int perform_atareset(struct dkdev_ata *, int); 193int perform_atareset(struct dkdev_ata *, int);
194int satapresense(struct dkdev_ata *, int); 194int satapresense(struct dkdev_ata *, int);

cvs diff -r1.1 -r1.2 src/sys/arch/sandpoint/stand/altboot/Attic/printf.c (switch to unified diff)

--- src/sys/arch/sandpoint/stand/altboot/Attic/printf.c 2011/01/23 01:05:30 1.1
+++ src/sys/arch/sandpoint/stand/altboot/Attic/printf.c 2011/01/23 01:32:08 1.2
@@ -1,260 +1,271 @@ @@ -1,260 +1,271 @@
1/* $NetBSD: printf.c,v 1.1 2011/01/23 01:05:30 nisimura Exp $ */ 1/* $NetBSD: printf.c,v 1.2 2011/01/23 01:32:08 nisimura Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tohru Nishimura. 8 * by Tohru Nishimura.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 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 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 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * printf -- format and write output using 'func' to write characters 33 * printf -- format and write output using 'func' to write characters
34 */ 34 */
35 35
36#include <sys/types.h> 36#include <sys/types.h>
37#include <machine/stdarg.h> 37#include <machine/stdarg.h>
38#include <lib/libsa/stand.h> 38#include <lib/libsa/stand.h>
39 39
40#define MAXSTR 80 40#define MAXSTR 80
41 41
42static int _doprnt(void (*)(int), const char *, va_list); 42static int _doprnt(void (*)(int), const char *, va_list);
43static void pr_int(unsigned long, int, char *); 43static void mkdigit(unsigned long long, int, char *);
44static void sputchar(int); 44static void sputchar(int);
45 45
46static char *sbuf, *ebuf; 46static char *sbuf, *ebuf;
47 47
48void 48void
49printf(const char *fmt, ...) 49printf(const char *fmt, ...)
50{ 50{
51 va_list ap; 51 va_list ap;
52 52
53 va_start(ap, fmt); 53 va_start(ap, fmt);
54 _doprnt(putchar, fmt, ap); 54 _doprnt(putchar, fmt, ap);
55 va_end(ap); 55 va_end(ap);
56} 56}
57 57
58void 58void
59vprintf(const char *fmt, va_list ap) 59vprintf(const char *fmt, va_list ap)
60{ 60{
61 61
62 _doprnt(putchar, fmt, ap); 62 _doprnt(putchar, fmt, ap);
63} 63}
64 64
65int 65int
66sprintf(char *buf, const char *fmt, ...) 66sprintf(char *buf, const char *fmt, ...)
67{ 67{
68 va_list ap; 68 va_list ap;
69 69
70 sbuf = buf; 70 sbuf = buf;
71 ebuf = buf + -(size_t)buf - 1; 71 ebuf = buf + -(size_t)buf - 1;
72 va_start(ap, fmt); 72 va_start(ap, fmt);
73 _doprnt(sputchar, fmt, ap); 73 _doprnt(sputchar, fmt, ap);
74 *sbuf = '\0'; 74 *sbuf = '\0';
75 return (sbuf - buf); 75 return (sbuf - buf);
76} 76}
77 77
78int 78int
79snprintf(char *buf, size_t size, const char *fmt, ...) 79snprintf(char *buf, size_t size, const char *fmt, ...)
80{ 80{
81 va_list ap; 81 va_list ap;
82 82
83 sbuf = buf; 83 sbuf = buf;
84 ebuf = buf + size - 1; 84 ebuf = buf + size - 1;
85 va_start(ap, fmt); 85 va_start(ap, fmt);
86 _doprnt(sputchar, fmt, ap); 86 _doprnt(sputchar, fmt, ap);
87 *sbuf = '\0'; 87 *sbuf = '\0';
88 return (sbuf - buf); 88 return (sbuf - buf);
89} 89}
90 90
91static int 91static int
92_doprnt(func, fmt, ap) 92_doprnt(void (*func)(int), const char *fmt, va_list ap)
93 void (*func)(int); /* Function to put a character */ 
94 const char *fmt; /* Format string for pr_int/pr_float */ 
95 va_list ap; /* Arguments to pr_int/pr_float */ 
96{ 93{
97 int i; 94 int i, outcnt;
98 char *str; 95 char buf[23], *str; /* requires 23 digits in octal at most */
99 char string[20]; 96 int length, fmax, fmin, leading;
100 int length; 97 int leftjust, llflag;
101 int leftjust; 98 char fill, sign;
102 int longflag; 99 long long v;
103 int fmax, fmin; 
104 int leading; 
105 int outcnt; 
106 char fill; 
107 char sign; 
108 100
109 outcnt = 0; 101 outcnt = 0;
110 while ((i = *fmt++) != '\0') { 102 while ((i = *fmt++) != '\0') {
111 if (i != '%') { 103 if (i != '%') {
112 (*func)(i); 104 (*func)(i);
113 outcnt += 1; 105 outcnt += 1;
114 continue; 106 continue;
115 } 107 }
116 if (*fmt == '%') { 108 if (*fmt == '%') {
117 (*func)(*fmt++); 109 (*func)(*fmt++);
118 outcnt += 1; 110 outcnt += 1;
119 continue; 111 continue;
120 } 112 }
121 leftjust = (*fmt == '-'); 113 leftjust = (*fmt == '-');
122 if (leftjust) 114 if (leftjust)
123 fmt++; 115 fmt++;
124 fill = (*fmt == '0') ? *fmt++ : ' '; 116 fill = (*fmt == '0') ? *fmt++ : ' ';
125 if (*fmt == '*') 117 if (*fmt == '*')
126 fmin = va_arg(ap, int); 118 fmin = va_arg(ap, int);
127 else { 119 else {
128 fmin = 0; 120 fmin = 0;
129 while ('0' <= *fmt && *fmt <= '9') 121 while ('0' <= *fmt && *fmt <= '9')
130 fmin = fmin * 10 + *fmt++ - '0'; 122 fmin = fmin * 10 + *fmt++ - '0';
131 } 123 }
132 if (*fmt != '.') 124 if (*fmt != '.')
133 fmax = 0; 125 fmax = 0;
134 else { 126 else {
135 fmt++; 127 fmt++;
136 if (*fmt == '*') 128 if (*fmt == '*')
137 fmax = va_arg(ap, int); 129 fmax = va_arg(ap, int);
138 else { 130 else {
139 fmax = 0; 131 fmax = 0;
140 while ('0' <= *fmt && *fmt <= '9') 132 while ('0' <= *fmt && *fmt <= '9')
141 fmax = fmax * 10 + *fmt++ - '0'; 133 fmax = fmax * 10 + *fmt++ - '0';
142 } 134 }
143 } 135 }
144 longflag = (*fmt == 'l'); 136 llflag = 0;
145 if (longflag) 137 if (*fmt == 'l' && *++fmt == 'l') {
146 fmt++; 138 llflag = 1;
 139 fmt += 1;
 140 }
147 if ((i = *fmt++) == '\0') { 141 if ((i = *fmt++) == '\0') {
148 (*func)('%'); 142 (*func)('%');
149 outcnt += 1; 143 outcnt += 1;
150 break; 144 break;
151 } 145 }
152 str = string; 146 str = buf;
153 sign = ' '; 147 sign = ' ';
154 switch (i) { 148 switch (i) {
155 case 'c': 149 case 'c':
156 str[0] = va_arg(ap, int); 150 str[0] = va_arg(ap, int);
157 str[1] = '\0'; 151 str[1] = '\0';
158 fmax = 0; 152 fmax = 0;
159 fill = ' '; 153 fill = ' ';
160 break; 154 break;
161 155
162 case 's': 156 case 's':
163 str = va_arg(ap, char *); 157 str = va_arg(ap, char *);
164 fill = ' '; 158 fill = ' ';
165 break; 159 break;
166 160
167 case 'd': 161 case 'd':
168 { 162 if (llflag)
169 long l = va_arg(ap, long); 163 v = va_arg(ap, long long);
170 if (l < 0) { sign = '-' ; l = -l; } 164 else
171 pr_int((unsigned long)l, 10, str); 165 v = va_arg(ap, int);
172 } 166 if (v < 0) {
 167 sign = '-' ; v = -v;
 168 }
 169 mkdigit((unsigned long long)v, 10, str);
173 break; 170 break;
174 171
175 case 'u': 172 case 'u':
176 pr_int(va_arg(ap, unsigned long), 10, str); 173 if (llflag)
 174 v = va_arg(ap, long long);
 175 else
 176 v = va_arg(ap, int);
 177 mkdigit((unsigned long long)v, 10, str);
177 break; 178 break;
178 179
179 case 'o': 180 case 'o':
180 pr_int(va_arg(ap, unsigned long), 8, str); 181 if (llflag)
 182 v = va_arg(ap, long long);
 183 else
 184 v = va_arg(ap, int);
 185 mkdigit((unsigned long long)v, 8, str);
181 fmax = 0; 186 fmax = 0;
182 break; 187 break;
183 188
184 case 'X': 189 case 'X':
185 case 'x': 190 case 'x':
186 pr_int(va_arg(ap, unsigned long), 16, str); 191 if (llflag)
 192 v = va_arg(ap, long long);
 193 else
 194 v = va_arg(ap, int);
 195 mkdigit((unsigned long long)v, 16, str);
187 fmax = 0; 196 fmax = 0;
188 break; 197 break;
189 198
190 case 'p': 199 case 'p':
191 pr_int(va_arg(ap, unsigned long), 16, str); 200 mkdigit(va_arg(ap, unsigned int), 16, str);
192 fill = '0'; 201 fill = '0';
193 fmin = 8; 202 fmin = 8;
194 fmax = 0; 203 fmax = 0;
195 (*func)('0'); (*func)('x'); 204 (*func)('0'); (*func)('x');
196 outcnt += 2; 205 outcnt += 2;
197 break; 206 break;
 207
198 default: 208 default:
199 (*func)(i); 209 (*func)(i);
200 break; 210 break;
201 } 211 }
202 for (i = 0; str[i] != '\0'; i++) 212 for (i = 0; str[i] != '\0'; i++)
203 ; 213 ;
204 length = i; 214 length = i;
205 if (fmin > MAXSTR || fmin < 0) 215 if (fmin > MAXSTR || fmin < 0)
206 fmin = 0; 216 fmin = 0;
207 if (fmax > MAXSTR || fmax < 0) 217 if (fmax > MAXSTR || fmax < 0)
208 fmax = 0; 218 fmax = 0;
209 leading = 0; 219 leading = 0;
210 if (fmax != 0 || fmin != 0) { 220 if (fmax != 0 || fmin != 0) {
211 if (fmax != 0 && length > fmax) 221 if (fmax != 0 && length > fmax)
212 length = fmax; 222 length = fmax;
213 if (fmin != 0) 223 if (fmin != 0)
214 leading = fmin - length; 224 leading = fmin - length;
215 if (sign == '-') 225 if (sign == '-')
216 --leading; 226 --leading;
217 } 227 }
218 outcnt += leading + length; 228 outcnt += leading + length;
219 if (sign == '-') 229 if (sign == '-')
220 outcnt += 1; 230 outcnt += 1;
221 if (sign == '-' && fill == '0') 231 if (sign == '-' && fill == '0')
222 (*func)(sign); 232 (*func)(sign);
223 if (leftjust == 0) 233 if (leftjust == 0)
224 for (i = 0; i < leading; i++) (*func)(fill); 234 for (i = 0; i < leading; i++) (*func)(fill);
225 if (sign == '-' && fill == ' ') 235 if (sign == '-' && fill == ' ')
226 (*func)(sign); 236 (*func)(sign);
227 for (i = 0; i < length; i++) 237 for (i = 0; i < length; i++)
228 (*func)(str[i]); 238 (*func)(str[i]);
229 if (leftjust != 0) 239 if (leftjust != 0)
230 for (i = 0; i < leading; i++) (*func)(fill); 240 for (i = 0; i < leading; i++) (*func)(fill);
231 } 241 }
232 return outcnt; 242 return outcnt;
233} 243}
234 244
235static void pr_int(lval, base, s) 245
236 unsigned long lval; 246static void
237 int base; 247mkdigit(unsigned long long llval, int base, char *s)
238 char *s; 
239{ 248{
240 char ptmp[12]; /* unsigned long requires 11 digit in octal form */ 249 char ptmp[23], *t; /* requires 22 digit in octal at most */
241 int i; 250 int n;
242 char *t = ptmp; 
243 static const char hexdigit[] = "0123456789abcdef"; 251 static const char hexdigit[] = "0123456789abcdef";
244 252
245 i = 1; 253 n = 1;
 254 t = ptmp;
246 *t++ = '\0'; 255 *t++ = '\0';
247 do { 256 do {
248 *t++ = hexdigit[lval % base]; 257 int d = (int)llval % base;
249 } while ((lval /= base) != 0 && ++i < sizeof(ptmp)); 258 *t++ = hexdigit[d];
 259 llval /= base;
 260 } while (llval != 0 && ++n < sizeof(ptmp));
250 while ((*s++ = *--t) != '\0') 261 while ((*s++ = *--t) != '\0')
251 ; 262 /* copy reserved digits */ ;
252} 263}
253 264
254static void 265static void
255sputchar(int c) 266sputchar(int c)
256{ 267{
257 268
258 if (sbuf < ebuf) 269 if (sbuf < ebuf)
259 *sbuf++ = c; 270 *sbuf++ = c;
260} 271}

File Added: src/sys/arch/sandpoint/stand/altboot/Attic/newvers.sh
#
# Usage: newvers.sh <historyrecord>
#
while read vers comment
do
	version=$vers
done < $1
developer=${USER:-"releng"}
[ -f /bin/hostname ] && buildhost=@`/bin/hostname`
date=`date`

cat <<EoF >vers.c
const char bootprog_rev[] = "$version";
const char bootprog_date[] = "$date";
const char bootprog_maker[] = "$developer$buildhost";
EoF

File Added: src/sys/arch/sandpoint/stand/altboot/version
1.0	initial version
1.1	PCI autoconf for multiple NIC device drivers
1.2	Synology-DS support, Marvell-Yukon driver, fixed aligned alloc
1.3	allow to have boot options, brdsetup.c cleanup to make brdtype
	maintainance more confortable
1.4	load kernels from local disk
1.5	altboot is the new name as this is capable of handling net & dsk.