xref: /freebsd/sys/dev/exca/excavar.h (revision 6580f5c38dd5b01aeeaed16b370f1a12423437f0)
1 
2 /*-
3  * SPDX-License-Identifier: BSD-4-Clause AND BSD-2-Clause
4  *
5  * Copyright (c) 2002 M. Warner Losh <imp@FreeBSD.org>
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  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * This software may be derived from NetBSD i82365.c and other files with
28  * the following copyright:
29  *
30  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
31  *
32  * Redistribution and use in source and binary forms, with or without
33  * modification, are permitted provided that the following conditions
34  * are met:
35  * 1. Redistributions of source code must retain the above copyright
36  *    notice, this list of conditions and the following disclaimer.
37  * 2. Redistributions in binary form must reproduce the above copyright
38  *    notice, this list of conditions and the following disclaimer in the
39  *    documentation and/or other materials provided with the distribution.
40  * 3. All advertising materials mentioning features or use of this software
41  *    must display the following acknowledgement:
42  *	This product includes software developed by Marc Horowitz.
43  * 4. The name of the author may not be used to endorse or promote products
44  *    derived from this software without specific prior written permission.
45  *
46  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
47  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
48  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
50  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
51  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
55  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56  */
57 
58 #ifndef _SYS_DEV_EXCA_EXCAVAR_H
59 #define _SYS_DEV_EXCA_EXCAVAR_H
60 
61 /*
62  * Structure to manage the ExCA part of the chip.
63  */
64 struct exca_softc;
65 typedef uint8_t (exca_getb_fn)(struct exca_softc *, int);
66 typedef void (exca_putb_fn)(struct exca_softc *, int, uint8_t);
67 
68 struct exca_softc
69 {
70 	device_t	dev;
71 	int		memalloc;
72 	struct		pccard_mem_handle mem[EXCA_MEM_WINS];
73 	int		ioalloc;
74 	struct		pccard_io_handle io[EXCA_IO_WINS];
75 	bus_space_tag_t	bst;
76 	bus_space_handle_t bsh;
77 	uint32_t	flags;
78 #define EXCA_SOCKET_PRESENT	0x00000001
79 #define EXCA_HAS_MEMREG_WIN	0x00000002
80 #define EXCA_CARD_OK		0x00000004
81 #define EXCA_EVENT		0x80000000
82 	uint32_t	offset;
83 	int		chipset;
84 #define EXCA_CARDBUS	0
85 #define	EXCA_I82365	1		/* Intel i82365SL-A/B or clone */
86 #define EXCA_I82365SL_DF 2		/* Intel i82365sl-DF step */
87 #define	EXCA_VLSI	3		/* VLSI chip */
88 #define	EXCA_PD6710	4		/* Cirrus logic PD6710 */
89 #define	EXCA_PD6722	5		/* Cirrus logic PD6722 */
90 #define EXCA_PD6729	6		/* Cirrus Logic PD6729 */
91 #define	EXCA_VG365	7		/* Vadem 365 */
92 #define	EXCA_VG465      8		/* Vadem 465 */
93 #define	EXCA_VG468	9		/* Vadem 468 */
94 #define	EXCA_VG469	10		/* Vadem 469 */
95 #define	EXCA_RF5C296	11		/* Ricoh RF5C296 */
96 #define	EXCA_RF5C396	12		/* Ricoh RF5C396 */
97 #define	EXCA_IBM	13		/* IBM clone */
98 #define	EXCA_IBM_KING	14		/* IBM KING PCMCIA Controller */
99 #define EXCA_BOGUS	-1		/* Invalid/not present/etc */
100 	exca_getb_fn	*getb;
101 	exca_putb_fn	*putb;
102 	device_t	pccarddev;
103 	uint32_t	status;		/* status, hw dependent */
104 };
105 
106 void exca_init(struct exca_softc *sc, device_t dev,
107     bus_space_tag_t, bus_space_handle_t, uint32_t);
108 void exca_insert(struct exca_softc *sc);
109 int exca_io_map(struct exca_softc *sc, int width, struct resource *r);
110 int exca_io_unmap_res(struct exca_softc *sc, struct resource *res);
111 int exca_is_pcic(struct exca_softc *sc);
112 int exca_mem_map(struct exca_softc *sc, int kind, struct resource *res);
113 int exca_mem_set_flags(struct exca_softc *sc, struct resource *res,
114     uint32_t flags);
115 int exca_mem_set_offset(struct exca_softc *sc, struct resource *res,
116     uint32_t cardaddr, uint32_t *deltap);
117 int exca_mem_unmap_res(struct exca_softc *sc, struct resource *res);
118 int exca_probe_slots(device_t dev, struct exca_softc *exca,
119     bus_space_tag_t iot, bus_space_handle_t ioh);
120 void exca_removal(struct exca_softc *);
121 void exca_reset(struct exca_softc *, device_t child);
122 
123 /* bus/device interfaces */
124 int exca_activate_resource(struct exca_softc *exca, device_t child,
125     struct resource *res);
126 int exca_deactivate_resource(struct exca_softc *exca, device_t child,
127     struct resource *res);
128 
129 static __inline uint8_t
130 exca_getb(struct exca_softc *sc, int reg)
131 {
132 	return (sc->getb(sc, reg));
133 }
134 
135 static __inline void
136 exca_putb(struct exca_softc *sc, int reg, uint8_t val)
137 {
138 	sc->putb(sc, reg, val);
139 }
140 
141 static __inline void
142 exca_setb(struct exca_softc *sc, int reg, uint8_t mask)
143 {
144 	exca_putb(sc, reg, exca_getb(sc, reg) | mask);
145 }
146 
147 static __inline void
148 exca_clrb(struct exca_softc *sc, int reg, uint8_t mask)
149 {
150 	exca_putb(sc, reg, exca_getb(sc, reg) & ~mask);
151 }
152 
153 enum {
154 	EXCA_IVAR_SLOT = 100,
155 };
156 
157 #define EXCA_ACCESSOR(A, B, T)						\
158 static inline int							\
159 exca_get_ ## A(device_t dev, T *t)					\
160 {									\
161 	return BUS_READ_IVAR(device_get_parent(dev), dev,		\
162 	    EXCA_IVAR_ ## B, (uintptr_t *) t);			\
163 }
164 
165 EXCA_ACCESSOR(slot,		SLOT,			uint32_t)
166 #endif /* !_SYS_DEV_EXCA_EXCAVAR_H */
167