xref: /freebsd/sys/dev/pccbb/pccbbvar.h (revision 0957b409)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2003-2004 M. Warner Losh.
5  * Copyright (c) 2000,2001 Jonathan Chen.
6  * All rights reserved.
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 AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31 
32 /*
33  * Structure definitions for the Cardbus Bridge driver
34  */
35 
36 struct cbb_intrhand {
37 	driver_filter_t	*filt;
38 	driver_intr_t	*intr;
39 	void 		*arg;
40 	struct cbb_softc *sc;
41 	void		*cookie;
42 };
43 
44 struct cbb_reslist {
45 	SLIST_ENTRY(cbb_reslist) link;
46 	struct	resource *res;
47 	int	type;
48 	int	rid;
49 		/* note: unlike the regular resource list, there can be
50 		 * duplicate rid's in the same list.  However, the
51 		 * combination of rid and res->r_dev should be unique.
52 		 */
53 	bus_addr_t cardaddr; /* for 16-bit pccard memory */
54 };
55 
56 #define	CBB_AUTO_OPEN_SMALLHOLE 0x100
57 #define CBB_NSLOTS		4
58 
59 struct cbb_softc {
60 	device_t	dev;
61 	struct exca_softc exca[CBB_NSLOTS];
62 	struct		resource *base_res;
63 	struct		resource *irq_res;
64 	void		*intrhand;
65 	bus_space_tag_t bst;
66 	bus_space_handle_t bsh;
67 	uint32_t	domain;
68 	unsigned int	pribus;
69 	struct pcib_secbus bus;
70 	struct mtx	mtx;
71 	int		cardok;
72 	u_int32_t	flags;
73 #define	CBB_16BIT_CARD		0x20000000
74 #define	CBB_KTHREAD_RUNNING	0x40000000
75 #define	CBB_KTHREAD_DONE	0x80000000
76 	int		chipset;		/* chipset id */
77 #define	CB_UNKNOWN	0		/* NOT Cardbus-PCI bridge */
78 #define	CB_TI113X	1		/* TI PCI1130/1131 */
79 #define	CB_TI12XX	2		/* TI PCI12xx/14xx/44xx/15xx/45xx */
80 #define	CB_TI125X	3		/* TI PCI1250/1251(B)/1450 */
81 #define	CB_RF5C47X	4		/* RICOH RF5C475/476/477 */
82 #define	CB_RF5C46X	5		/* RICOH RF5C465/466/467 */
83 #define	CB_CIRRUS	6		/* Cirrus Logic CLPD683x */
84 #define	CB_TOPIC95	7		/* Toshiba ToPIC95 */
85 #define	CB_TOPIC97	8		/* Toshiba ToPIC97/100 */
86 #define	CB_O2MICRO	9		/* O2Micro chips */
87 	SLIST_HEAD(, cbb_reslist) rl;
88 	device_t	cbdev;
89 	struct proc	*event_thread;
90 	void (*chipinit)(struct cbb_softc *);
91 	int	powerintr;
92 	struct root_hold_token *sc_root_token;
93 };
94 
95 /* result of detect_card */
96 #define	CARD_UKN_CARD	0x00
97 #define	CARD_5V_CARD	0x01
98 #define	CARD_3V_CARD	0x02
99 #define	CARD_XV_CARD	0x04
100 #define	CARD_YV_CARD	0x08
101 
102 /* for power_socket */
103 #define	CARD_VCC(X)	(X)
104 #define CARD_VPP_VCC	0xf0
105 #define CARD_VCCMASK	0xf
106 #define CARD_VCCSHIFT	0
107 #define XV		2
108 #define YV		1
109 
110 #define CARD_OFF	(CARD_VCC(0))
111 
112 extern int cbb_debug;
113 extern devclass_t cbb_devclass;
114 
115 int	cbb_activate_resource(device_t brdev, device_t child,
116 	    int type, int rid, struct resource *r);
117 struct resource	*cbb_alloc_resource(device_t brdev, device_t child,
118 	    int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count,
119 	    u_int flags);
120 void	cbb_child_detached(device_t brdev, device_t child);
121 int	cbb_child_present(device_t parent, device_t child);
122 int	cbb_deactivate_resource(device_t brdev, device_t child,
123 	    int type, int rid, struct resource *r);
124 int	cbb_detach(device_t brdev);
125 void	cbb_disable_func_intr(struct cbb_softc *sc);
126 void	cbb_driver_added(device_t brdev, driver_t *driver);
127 void	cbb_event_thread(void *arg);
128 int	cbb_pcic_set_memory_offset(device_t brdev, device_t child, int rid,
129 	    uint32_t cardaddr, uint32_t *deltap);
130 int	cbb_pcic_set_res_flags(device_t brdev, device_t child, int type,
131 	    int rid, u_long flags);
132 int	cbb_power(device_t brdev, int volts);
133 int	cbb_power_enable_socket(device_t brdev, device_t child);
134 int	cbb_power_disable_socket(device_t brdev, device_t child);
135 int	cbb_read_ivar(device_t brdev, device_t child, int which,
136 	    uintptr_t *result);
137 int	cbb_release_resource(device_t brdev, device_t child,
138 	    int type, int rid, struct resource *r);
139 int	cbb_setup_intr(device_t dev, device_t child, struct resource *irq,
140 	    int flags, driver_filter_t *filt, driver_intr_t *intr, void *arg,
141 	    void **cookiep);
142 int	cbb_teardown_intr(device_t dev, device_t child, struct resource *irq,
143 	    void *cookie);
144 int	cbb_write_ivar(device_t brdev, device_t child, int which,
145 	    uintptr_t value);
146 
147 /*
148  */
149 static __inline void
150 cbb_set(struct cbb_softc *sc, uint32_t reg, uint32_t val)
151 {
152 	bus_space_write_4(sc->bst, sc->bsh, reg, val);
153 }
154 
155 static __inline uint32_t
156 cbb_get(struct cbb_softc *sc, uint32_t reg)
157 {
158 	return (bus_space_read_4(sc->bst, sc->bsh, reg));
159 }
160 
161 static __inline void
162 cbb_setb(struct cbb_softc *sc, uint32_t reg, uint32_t bits)
163 {
164 	cbb_set(sc, reg, cbb_get(sc, reg) | bits);
165 }
166 
167 static __inline void
168 cbb_clrb(struct cbb_softc *sc, uint32_t reg, uint32_t bits)
169 {
170 	cbb_set(sc, reg, cbb_get(sc, reg) & ~bits);
171 }
172