xref: /dragonfly/sys/dev/disk/fd/fdc.h (revision 0066c2fb)
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. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  *	from:	@(#)fd.c	7.4 (Berkeley) 5/25/91
30  * $FreeBSD: src/sys/isa/fdc.h,v 1.20.2.3 2002/02/03 14:08:46 nyan Exp $
31  *
32  */
33 
34 enum fdc_type
35 {
36 	FDC_NE765, FDC_I82077, FDC_NE72065, FDC_UNKNOWN = -1
37 };
38 
39 
40 /***********************************************************************\
41 * Per controller structure.						*
42 \***********************************************************************/
43 struct fdc_data
44 {
45 	int	fdcu;		/* our unit number */
46 	int	dmachan;
47 	int	flags;
48 #define FDC_ATTACHED	0x01
49 #define FDC_STAT_VALID	0x08
50 #define FDC_HAS_FIFO	0x10
51 #define FDC_NEEDS_RESET	0x20
52 #define FDC_NODMA	0x40
53 #define FDC_ISPNP	0x80
54 #define FDC_ISPCMCIA	0x100
55 	struct	fd_data *fd;
56 	int	fdu;		/* the active drive	*/
57 	int	state;
58 	int	retry;
59 	int	fdout;		/* mirror of the w/o digital output reg */
60 	u_int	status[7];	/* copy of the registers */
61 	enum	fdc_type fdct;	/* chip version of FDC */
62 	int	fdc_errs;	/* number of logged errors */
63 	struct	bio_queue_head bio_queue;
64 	struct	bio *bio;	/* active buffer */
65 	int	dma_overruns;	/* number of DMA overruns */
66 	struct	resource *res_ioport, *res_ctl, *res_irq, *res_drq;
67 	int	rid_ioport, rid_ctl, rid_irq, rid_drq;
68 	int	port_off;
69 	bus_space_tag_t portt;
70 	bus_space_handle_t porth;
71 	bus_space_tag_t ctlt;
72 	bus_space_handle_t ctlh;
73 	void	*fdc_intr;
74 	device_t fdc_dev;
75 	struct	callout pseudointr_ch;
76 	void	(*fdctl_wr)(struct fdc_data *fdc, u_int8_t v);
77 };
78 
79 /***********************************************************************\
80 * Throughout this file the following conventions will be used:		*
81 * fd is a pointer to the fd_data struct for the drive in question	*
82 * fdc is a pointer to the fdc_data struct for the controller		*
83 * fdu is the floppy drive unit number					*
84 * fdcu is the floppy controller unit number				*
85 * fdsu is the floppy drive unit number on that controller. (sub-unit)	*
86 \***********************************************************************/
87 typedef int	fdu_t;
88 typedef int	fdcu_t;
89 typedef int	fdsu_t;
90 typedef	struct fd_data *fd_p;
91 typedef struct fdc_data *fdc_p;
92 typedef enum fdc_type fdc_t;
93 
94 /*
95  * fdc maintains a set (1!) of ivars per child of each controller.
96  */
97 enum fdc_device_ivars {
98 	FDC_IVAR_FDUNIT,
99 };
100 
101 /*
102  * Simple access macros for the ivars.
103  */
104 #define FDC_ACCESSOR(A, B, T)						\
105 static __inline T fdc_get_ ## A(device_t dev)				\
106 {									\
107 	uintptr_t v;							\
108 	BUS_READ_IVAR(device_get_parent(dev), dev, FDC_IVAR_ ## B, &v);	\
109 	return (T) v;							\
110 }
111 FDC_ACCESSOR(fdunit, FDUNIT, int)
112 
113 int	fdc_alloc_resources(struct fdc_data *fdc);
114 void	fdc_release_resources(struct fdc_data *fdc);
115 int	fdc_attach(device_t dev);
116 int	fdc_print_child(device_t me, device_t child);
117 int	fdc_read_ivar(device_t dev, device_t child, int which, u_long *result);
118 void	fdout_wr(fdc_p fdc, u_int8_t v);
119 int	fd_cmd(struct fdc_data *fdc, int n_out, ...);
120 
121 extern	devclass_t fdc_devclass;
122