xref: /freebsd/sys/dev/pccard/pccardvarp.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2005 M. Warner Losh <imp@FreeBSD.org>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice unmodified, this list of conditions, and the following
11  *    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 AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _PCCARD_PCCARDVARP_H
30 #define _PCCARD_PCCARDVARP_H
31 
32 /* pccard itself */
33 
34 #define PCCARD_MEM_PAGE_SIZE		1024
35 
36 #define PCCARD_CFE_MWAIT_REQUIRED	0x0001
37 #define PCCARD_CFE_RDYBSY_ACTIVE	0x0002
38 #define PCCARD_CFE_WP_ACTIVE		0x0004
39 #define PCCARD_CFE_BVD_ACTIVE		0x0008
40 #define PCCARD_CFE_IO8			0x0010
41 #define PCCARD_CFE_IO16			0x0020
42 #define PCCARD_CFE_IRQSHARE		0x0040
43 #define PCCARD_CFE_IRQPULSE		0x0080
44 #define PCCARD_CFE_IRQLEVEL		0x0100
45 #define PCCARD_CFE_POWERDOWN		0x0200
46 #define PCCARD_CFE_READONLY		0x0400
47 #define PCCARD_CFE_AUDIO		0x0800
48 
49 struct pccard_ce_iospace {
50 	rman_res_t	length;
51 	rman_res_t	start;
52 };
53 
54 struct pccard_ce_memspace {
55 	rman_res_t	length;
56 	rman_res_t	cardaddr;
57 	rman_res_t	hostaddr;
58 };
59 
60 struct pccard_config_entry {
61 	int		number;
62 	uint32_t	flags;
63 	int		iftype;
64 	int		num_iospace;
65 	/*
66 	 * The card will only decode this mask in any case, so we can
67 	 * do dynamic allocation with this in mind, in case the suggestions
68 	 * below are no good.
69 	 */
70 	u_long		iomask;
71 	struct pccard_ce_iospace iospace[4]; /* XXX up to 16 */
72 	uint16_t	irqmask;
73 	int		num_memspace;
74 	struct pccard_ce_memspace memspace[2];	/* XXX up to 8 */
75 	int		maxtwins;
76 	STAILQ_ENTRY(pccard_config_entry) cfe_list;
77 };
78 
79 struct pccard_funce_disk {
80 	uint8_t pfd_interface;
81 	uint8_t pfd_power;
82 };
83 
84 struct pccard_funce_lan {
85 	int pfl_nidlen;
86 	uint8_t pfl_nid[8];
87 };
88 
89 union pccard_funce {
90 	struct pccard_funce_disk pfv_disk;
91 	struct pccard_funce_lan pfv_lan;
92 };
93 
94 struct pccard_function {
95 	/* read off the card */
96 	int		number;
97 	int		function;
98 	int		last_config_index;
99 	uint32_t	ccr_base;	/* Offset with card's memory */
100 	uint32_t	ccr_mask;
101 	struct resource *ccr_res;
102 	int		ccr_rid;
103 	STAILQ_HEAD(, pccard_config_entry) cfe_head;
104 	STAILQ_ENTRY(pccard_function) pf_list;
105 	/* run-time state */
106 	struct pccard_softc *sc;
107 	struct pccard_config_entry *cfe;
108 	struct pccard_mem_handle pf_pcmh;
109 	device_t	dev;
110 #define	pf_ccrt		pf_pcmh.memt
111 #define	pf_ccrh		pf_pcmh.memh
112 #define	pf_ccr_realsize	pf_pcmh.realsize
113 	uint32_t	pf_ccr_offset;	/* Offset from ccr_base of CIS */
114 	int		pf_ccr_window;
115 	bus_addr_t	pf_mfc_iobase;
116 	bus_addr_t	pf_mfc_iomax;
117 	int		pf_flags;
118 	driver_filter_t	*intr_filter;
119 	driver_intr_t	*intr_handler;
120 	void		*intr_handler_arg;
121 	void		*intr_handler_cookie;
122 
123 	union pccard_funce pf_funce; /* CISTPL_FUNCE */
124 #define pf_funce_disk_interface pf_funce.pfv_disk.pfd_interface
125 #define pf_funce_disk_power pf_funce.pfv_disk.pfd_power
126 #define pf_funce_lan_nid pf_funce.pfv_lan.pfl_nid
127 #define pf_funce_lan_nidlen pf_funce.pfv_lan.pfl_nidlen
128 };
129 
130 /* pf_flags */
131 #define	PFF_ENABLED	0x0001		/* function is enabled */
132 
133 struct pccard_card {
134 	int		cis1_major;
135 	int		cis1_minor;
136 	/* XXX waste of space? */
137 	char		cis1_info_buf[256];
138 	char		*cis1_info[4];
139 	/*
140 	 * Use int32_t for manufacturer and product so that they can
141 	 * hold the id value found in card CIS and special value that
142 	 * indicates no id was found.
143 	 */
144 	int32_t		manufacturer;
145 #define	PCMCIA_VENDOR_INVALID	-1
146 	int32_t		product;
147 #define	PCMCIA_PRODUCT_INVALID		-1
148 	int16_t		prodext;
149 	uint16_t	error;
150 #define	PCMCIA_CIS_INVALID		{ NULL, NULL, NULL, NULL }
151 	STAILQ_HEAD(, pccard_function) pf_head;
152 };
153 
154 /* More later? */
155 struct pccard_ivar {
156 	struct resource_list resources;
157 	struct pccard_function *pf;
158 };
159 
160 struct cis_buffer
161 {
162 	size_t	len;			/* Actual length of the CIS */
163 	uint8_t buffer[2040];		/* small enough to be 2k */
164 };
165 
166 struct pccard_softc {
167 	device_t		dev;
168 	/* this stuff is for the socket */
169 
170 	/* this stuff is for the card */
171 	struct pccard_card card;
172 	int		sc_enabled_count;	/* num functions enabled */
173 	struct cdev *cisdev;
174 	int	cis_open;
175 	struct cis_buffer *cis;
176 };
177 
178 struct pccard_cis_quirk {
179 	int32_t manufacturer;
180 	int32_t product;
181 	char *cis1_info[4];
182 	struct pccard_function *pf;
183 	struct pccard_config_entry *cfe;
184 };
185 
186 void	pccard_read_cis(struct pccard_softc *);
187 void	pccard_check_cis_quirks(device_t);
188 void	pccard_print_cis(device_t);
189 int	pccard_scan_cis(device_t, device_t, pccard_scan_t, void *);
190 
191 int	pccard_device_create(struct pccard_softc *);
192 int	pccard_device_destroy(struct pccard_softc *);
193 
194 #define PCCARD_SOFTC(d) (struct pccard_softc *) device_get_softc(d)
195 #define PCCARD_IVAR(d) (struct pccard_ivar *) device_get_ivars(d)
196 
197 #endif /* _PCCARD_PCCARDVARP_H */
198