xref: /dragonfly/sys/dev/disk/fd/fdc.h (revision 9bb2a92d)
1 /*-
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by the University of
16  *	California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *	from:	@(#)fd.c	7.4 (Berkeley) 5/25/91
34  * $FreeBSD: src/sys/isa/fdc.h,v 1.20.2.3 2002/02/03 14:08:46 nyan Exp $
35  * $DragonFly: src/sys/dev/disk/fd/fdc.h,v 1.3 2004/01/11 16:45:16 joerg Exp $
36  *
37  */
38 
39 enum fdc_type
40 {
41 	FDC_NE765, FDC_I82077, FDC_NE72065, FDC_UNKNOWN = -1
42 };
43 
44 
45 /***********************************************************************\
46 * Per controller structure.						*
47 \***********************************************************************/
48 struct fdc_data
49 {
50 	int	fdcu;		/* our unit number */
51 	int	dmachan;
52 	int	flags;
53 #define FDC_ATTACHED	0x01
54 #define FDC_STAT_VALID	0x08
55 #define FDC_HAS_FIFO	0x10
56 #define FDC_NEEDS_RESET	0x20
57 #define FDC_NODMA	0x40
58 #define FDC_ISPNP	0x80
59 #define FDC_ISPCMCIA	0x100
60 	struct	fd_data *fd;
61 	int	fdu;		/* the active drive	*/
62 	int	state;
63 	int	retry;
64 #ifndef PC98
65 	int	fdout;		/* mirror of the w/o digital output reg */
66 #endif
67 	u_int	status[7];	/* copy of the registers */
68 	enum	fdc_type fdct;	/* chip version of FDC */
69 	int	fdc_errs;	/* number of logged errors */
70 	struct	buf_queue_head head;
71 	struct	buf *bp;	/* active buffer */
72 	int	dma_overruns;	/* number of DMA overruns */
73 #ifdef PC98
74 	struct	resource *res_ioport, *res_fdsio, *res_fdemsio;
75 	struct	resource *res_irq, *res_drq;
76 	int	rid_ioport, rid_irq, rid_drq;
77 #else
78 	struct	resource *res_ioport, *res_ctl, *res_irq, *res_drq;
79 	int	rid_ioport, rid_ctl, rid_irq, rid_drq;
80 #endif
81 	int	port_off;
82 	bus_space_tag_t portt;
83 	bus_space_handle_t porth;
84 #ifdef PC98
85 	bus_space_tag_t		sc_fdsiot;
86 	bus_space_handle_t	sc_fdsioh;
87 	bus_space_tag_t		sc_fdemsiot;
88 	bus_space_handle_t	sc_fdemsioh;
89 #else
90 	bus_space_tag_t ctlt;
91 	bus_space_handle_t ctlh;
92 #endif
93 	void	*fdc_intr;
94 	struct	device *fdc_dev;
95 #ifndef PC98
96 	void	(*fdctl_wr)(struct fdc_data *fdc, u_int8_t v);
97 #endif
98 };
99 
100 /***********************************************************************\
101 * Throughout this file the following conventions will be used:		*
102 * fd is a pointer to the fd_data struct for the drive in question	*
103 * fdc is a pointer to the fdc_data struct for the controller		*
104 * fdu is the floppy drive unit number					*
105 * fdcu is the floppy controller unit number				*
106 * fdsu is the floppy drive unit number on that controller. (sub-unit)	*
107 \***********************************************************************/
108 typedef int	fdu_t;
109 typedef int	fdcu_t;
110 typedef int	fdsu_t;
111 typedef	struct fd_data *fd_p;
112 typedef struct fdc_data *fdc_p;
113 typedef enum fdc_type fdc_t;
114 
115 #define FDUNIT(s)	(((s) >> 6) & 3)
116 #define FDTYPE(s)	((s) & 0x3f)
117 
118 /*
119  * fdc maintains a set (1!) of ivars per child of each controller.
120  */
121 enum fdc_device_ivars {
122 	FDC_IVAR_FDUNIT,
123 };
124 
125 /*
126  * Simple access macros for the ivars.
127  */
128 #define FDC_ACCESSOR(A, B, T)						\
129 static __inline T fdc_get_ ## A(device_t dev)				\
130 {									\
131 	uintptr_t v;							\
132 	BUS_READ_IVAR(device_get_parent(dev), dev, FDC_IVAR_ ## B, &v);	\
133 	return (T) v;							\
134 }
135 FDC_ACCESSOR(fdunit,	FDUNIT,	int)
136 
137 int	fdc_alloc_resources(struct fdc_data *fdc);
138 void	fdc_release_resources(struct fdc_data *fdc);
139 int	fdc_attach(device_t dev);
140 int	fdc_print_child(device_t me, device_t child);
141 int	fdc_read_ivar(device_t dev, device_t child, int which, u_long *result);
142 void	fdout_wr(fdc_p fdc, u_int8_t v);
143 int	fd_cmd(struct fdc_data *fdc, int n_out, ...);
144 
145 extern	devclass_t fdc_devclass;
146