xref: /openbsd/sys/dev/pci/pucvar.h (revision cca36db2)
1 /*	$OpenBSD: pucvar.h,v 1.13 2011/11/15 22:27:53 deraadt 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 #define	PUC_MAX_PORTS		16
42 
43 struct puc_device_description {
44 	u_int16_t	rval[4];
45 	u_int16_t	rmask[4];
46 	struct {
47 		u_char	type;
48 		u_char	bar;
49 		u_short	offset;
50 	}			ports[PUC_MAX_PORTS];
51 };
52 
53 /*
54  * For serial ports, the type field also encodes a multiplier
55  * of the speed.
56  */
57 #define PUC_LPT			(0x00 | 0x40)
58 #define PUC_COM_MUL(mul)	(0x80 | 0x40 | (mul))
59 #define PUC_COM_POW2(pow2)	(0x80 |        (pow2))
60 
61 #define PUC_IS_LPT(type)	(((type) & 0xc0) == 0x40)
62 #define PUC_IS_COM(type)	(((type) & 0x80) == 0x80)
63 
64 #define PUC_IS_COM_MUL(type)	((type) & 0x40)
65 #define PUC_COM_GET_MUL(type)	((type) & 0x3f)
66 #define PUC_COM_GET_POW2(type)	((type) & 0x3f)
67 
68 #define PUC_PORT_BAR_INDEX(bar)	(((bar) - PCI_MAPREG_START) / 4)
69 
70 struct puc_attach_args {
71 	int			port;
72 	int			type;
73 	void			*puc;
74 
75 	bus_addr_t		a;
76 	bus_space_tag_t		t;
77 	bus_space_handle_t	h;
78 
79 	const char *(*intr_string)(struct puc_attach_args *);
80 	void *(*intr_establish)(struct puc_attach_args *, int, int (*)(void *),
81 	    void *, char *);
82 };
83 
84 extern const struct puc_device_description puc_devs[];
85 extern int puc_ndevs;
86 
87 #define	PUC_NBARS	6
88 struct puc_softc {
89 	struct device		sc_dev;
90 
91 	/* static configuration data */
92 	const struct puc_device_description *sc_desc;
93 
94 	/* card-global dynamic data */
95 	struct {
96 		int		mapped;
97 		bus_addr_t	a;
98 		bus_size_t	s;
99 		bus_space_tag_t	t;
100 		bus_space_handle_t h;
101 	} sc_bar_mappings[PUC_NBARS];
102 
103 	/* per-port dynamic data */
104 	struct {
105 		struct device   *dev;
106 		/* filled in by port attachments */
107 		void	*intrhand;
108 	} sc_ports[PUC_MAX_PORTS];
109 };
110 
111 const struct puc_device_description *
112     puc_find_description(u_int16_t, u_int16_t, u_int16_t, u_int16_t);
113 void	puc_print_ports(const struct puc_device_description *);
114 void	puc_common_attach(struct puc_softc *, struct puc_attach_args *);
115 int	puc_print(void *, const char *);
116 int	puc_submatch(struct device *, void *, void *);
117