xref: /openbsd/sys/dev/pci/pucvar.h (revision ad41fa76)
1 /*	$OpenBSD: pucvar.h,v 1.18 2024/05/24 04:36:26 jsg 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_XR17V35X,
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 	{ PUC_PORT_COM_XR17V35X, 125000000	},
76 };
77 
78 #define PUC_IS_LPT(type)	((type) == PUC_PORT_LPT)
79 #define PUC_IS_COM(type)	((type) != PUC_PORT_LPT)
80 
81 #define PUC_PORT_BAR_INDEX(bar)	(((bar) - PCI_MAPREG_START) / 4)
82 
83 struct puc_attach_args {
84 	int			port;
85 	int			type;
86 	void			*puc;
87 
88 	bus_addr_t		a;
89 	bus_space_tag_t		t;
90 	bus_space_handle_t	h;
91 
92 	const char *(*intr_string)(struct puc_attach_args *);
93 	void *(*intr_establish)(struct puc_attach_args *, int, int (*)(void *),
94 	    void *, char *);
95 };
96 
97 extern const struct puc_device_description puc_devs[];
98 extern int puc_ndevs;
99 
100 #define	PUC_NBARS	6
101 struct puc_softc {
102 	struct device		sc_dev;
103 
104 	/* static configuration data */
105 	const struct puc_device_description *sc_desc;
106 
107 	/* card-global dynamic data */
108 	struct {
109 		int		mapped;
110 		u_long		type;
111 		bus_addr_t	a;
112 		bus_size_t	s;
113 		bus_space_tag_t	t;
114 		bus_space_handle_t h;
115 	} sc_bar_mappings[PUC_NBARS];
116 
117 	/* per-port dynamic data */
118 	struct {
119 		struct device   *dev;
120 		/* filled in by port attachments */
121 		void	*intrhand;
122 		int	(*real_intrhand)(void *);
123 		void	*real_intrhand_arg;
124 	} sc_ports[PUC_MAX_PORTS];
125 
126 	int			sc_xr17v35x;
127 };
128 
129 const struct puc_device_description *
130     puc_find_description(u_int16_t, u_int16_t, u_int16_t, u_int16_t);
131 void	puc_print_ports(const struct puc_device_description *);
132 void	puc_common_attach(struct puc_softc *, struct puc_attach_args *);
133 int	puc_print(void *, const char *);
134 int	puc_submatch(struct device *, void *, void *);
135