xref: /netbsd-src/sys/arch/bebox/stand/boot/wdvar.h (revision 01f89bfdb369485a8ed325225f07a5cd0fe1eb4d)
1 /*	$NetBSD: wdvar.h,v 1.1 2010/10/14 06:50:43 kiyohara Exp $	*/
2 
3 /*-
4  * Copyright (c) 2003 The NetBSD Foundation, Inc.
5  * Copyright (c) 2001 Dynarc AB, Sweden. All rights reserved.
6  *
7  * This code is derived from software written by Anders Magnusson,
8  * ragge@ludd.luth.se
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
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.
18  * 3. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef _STAND_WDVAR_H
34 #define _STAND_WDVAR_H
35 
36 #include <dev/ic/wdcreg.h>
37 #include <dev/ata/atareg.h>
38 
39 #include <sys/disklabel.h>
40 #include <sys/bootblock.h>
41 
42 #define WDC_TIMEOUT		2000000
43 #define WDC_NPORTS		8	/* XXX */
44 #define WDC_NSHADOWREG		2	/* XXX */
45 
46 struct wdc_channel {
47 	int c_cmdbase;
48 	int c_ctlbase;
49 	int c_data;
50 	int c_cmdreg[WDC_NPORTS + WDC_NSHADOWREG];
51 };
52 
53 #define WDC_READ_REG(chp, reg)		inb((chp)->c_cmdreg[(reg)])
54 #define WDC_WRITE_REG(chp, reg, val)	outb((chp)->c_cmdreg[(reg)], (val))
55 #define WDC_READ_CTLREG(chp, reg)	inb((chp)->c_ctlbase)
56 #define WDC_WRITE_CTLREG(chp, reg, val)	outb((chp)->c_ctlbase, (val))
57 #define WDC_READ_DATA_STREAM(chp)	inw((chp)->c_data)
58 #define WDC_READ_DATA(chp)		inwrb((chp)->c_data)
59 
60 struct wd_softc {
61 #define WDF_LBA		0x0001
62 #define WDF_LBA48	0x0002
63 	uint16_t sc_flags;
64 
65 	u_int sc_part;
66 	u_int sc_unit;
67 	u_int sc_ctlr;
68 
69 	uint64_t sc_capacity;
70 	uint32_t sc_capacity28;
71 
72 	struct ataparams sc_params;
73 	struct disklabel sc_label;
74 };
75 
76 struct wdc_command {
77 	uint8_t drive;		/* drive id */
78 
79 	uint8_t r_command;	/* Parameters to upload to registers */
80 	uint8_t r_head;
81 	uint16_t r_cyl;
82 	uint8_t r_sector;
83 	uint8_t r_count;
84 	uint8_t r_features;
85 
86 	uint16_t bcount;
87 	void *data;
88 
89 	uint64_t r_blkno;
90 };
91 
92 int	wdc_init(int);
93 int	wdc_exec_identify(struct wd_softc *, void *);
94 int	wdc_exec_read(struct wd_softc *, uint8_t, daddr_t, void *);
95 
96 #endif /* _STAND_WDVAR_H */
97