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