xref: /openbsd/sys/dev/pci/pucvar.h (revision 4cfece93)
1 /*	$OpenBSD: pucvar.h,v 1.16 2018/05/02 19:11:01 phessler Exp $	*/
2 /*	$NetBSD: pucvar.h,v 1.2 1999/02/06 06:29:54 cgd Exp $	*/
3 
4 /*
5  * Copyright (c) 1998, 1999 Christopher G. Demetriou.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Christopher G. Demetriou
18  *	for the NetBSD Project.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * Exported (or conveniently located) PCI "universal" communications card
36  * software structures.
37  *
38  * Author: Christopher G. Demetriou, May 14, 1998.
39  */
40 
41 #include <dev/ic/comreg.h>
42 
43 #define	PUC_MAX_PORTS		16
44 
45 struct puc_device_description {
46 	u_int16_t	rval[4];
47 	u_int16_t	rmask[4];
48 	struct {
49 		u_char	type;
50 		u_char	bar;
51 		u_short	offset;
52 	}			ports[PUC_MAX_PORTS];
53 };
54 
55 struct puc_port_type {
56 	enum {
57 		PUC_PORT_LPT = 1,
58 		PUC_PORT_COM,
59 		PUC_PORT_COM_MUL4,
60 		PUC_PORT_COM_MUL8,
61 		PUC_PORT_COM_MUL10,
62 		PUC_PORT_COM_MUL128,
63 		PUC_PORT_COM_125MHZ,
64 	} type;
65 	u_int32_t	freq;
66 };
67 
68 static const struct puc_port_type puc_port_types[] = {
69 	{ PUC_PORT_LPT,		0		},
70 	{ PUC_PORT_COM,		COM_FREQ	},
71 	{ PUC_PORT_COM_MUL4,	COM_FREQ * 4	},
72 	{ PUC_PORT_COM_MUL8,	COM_FREQ * 8	},
73 	{ PUC_PORT_COM_MUL10,	COM_FREQ * 10	},
74 	{ PUC_PORT_COM_MUL128,	COM_FREQ * 128	},
75 };
76 
77 #define PUC_IS_LPT(type)	((type) == PUC_PORT_LPT)
78 #define PUC_IS_COM(type)	((type) != PUC_PORT_LPT)
79 
80 #define PUC_PORT_BAR_INDEX(bar)	(((bar) - PCI_MAPREG_START) / 4)
81 
82 struct puc_attach_args {
83 	int			port;
84 	int			type;
85 	void			*puc;
86 
87 	bus_addr_t		a;
88 	bus_space_tag_t		t;
89 	bus_space_handle_t	h;
90 
91 	const char *(*intr_string)(struct puc_attach_args *);
92 	void *(*intr_establish)(struct puc_attach_args *, int, int (*)(void *),
93 	    void *, char *);
94 };
95 
96 extern const struct puc_device_description puc_devs[];
97 extern int puc_ndevs;
98 
99 #define	PUC_NBARS	6
100 struct puc_softc {
101 	struct device		sc_dev;
102 
103 	/* static configuration data */
104 	const struct puc_device_description *sc_desc;
105 
106 	/* card-global dynamic data */
107 	struct {
108 		int		mapped;
109 		bus_addr_t	a;
110 		bus_size_t	s;
111 		bus_space_tag_t	t;
112 		bus_space_handle_t h;
113 	} sc_bar_mappings[PUC_NBARS];
114 
115 	/* per-port dynamic data */
116 	struct {
117 		struct device   *dev;
118 		/* filled in by port attachments */
119 		void	*intrhand;
120 	} sc_ports[PUC_MAX_PORTS];
121 };
122 
123 const struct puc_device_description *
124     puc_find_description(u_int16_t, u_int16_t, u_int16_t, u_int16_t);
125 void	puc_print_ports(const struct puc_device_description *);
126 void	puc_common_attach(struct puc_softc *, struct puc_attach_args *);
127 int	puc_print(void *, const char *);
128 int	puc_submatch(struct device *, void *, void *);
129