xref: /freebsd/sys/dev/pccard/pccardvarp.h (revision d91f8db5f1822c43cd256f19aae1d059e4b25a26)
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  * $FreeBSD$
29  */
30 
31 #ifndef _PCCARD_PCCARDVARP_H
32 #define _PCCARD_PCCARDVARP_H
33 
34 /* pccard itself */
35 
36 #define PCCARD_MEM_PAGE_SIZE		1024
37 
38 #define PCCARD_CFE_MWAIT_REQUIRED	0x0001
39 #define PCCARD_CFE_RDYBSY_ACTIVE	0x0002
40 #define PCCARD_CFE_WP_ACTIVE		0x0004
41 #define PCCARD_CFE_BVD_ACTIVE		0x0008
42 #define PCCARD_CFE_IO8			0x0010
43 #define PCCARD_CFE_IO16			0x0020
44 #define PCCARD_CFE_IRQSHARE		0x0040
45 #define PCCARD_CFE_IRQPULSE		0x0080
46 #define PCCARD_CFE_IRQLEVEL		0x0100
47 #define PCCARD_CFE_POWERDOWN		0x0200
48 #define PCCARD_CFE_READONLY		0x0400
49 #define PCCARD_CFE_AUDIO		0x0800
50 
51 struct pccard_ce_iospace {
52 	rman_res_t	length;
53 	rman_res_t	start;
54 };
55 
56 struct pccard_ce_memspace {
57 	rman_res_t	length;
58 	rman_res_t	cardaddr;
59 	rman_res_t	hostaddr;
60 };
61 
62 struct pccard_config_entry {
63 	int		number;
64 	uint32_t	flags;
65 	int		iftype;
66 	int		num_iospace;
67 	/*
68 	 * The card will only decode this mask in any case, so we can
69 	 * do dynamic allocation with this in mind, in case the suggestions
70 	 * below are no good.
71 	 */
72 	u_long		iomask;
73 	struct pccard_ce_iospace iospace[4]; /* XXX up to 16 */
74 	uint16_t	irqmask;
75 	int		num_memspace;
76 	struct pccard_ce_memspace memspace[2];	/* XXX up to 8 */
77 	int		maxtwins;
78 	STAILQ_ENTRY(pccard_config_entry) cfe_list;
79 };
80 
81 struct pccard_funce_disk {
82 	uint8_t pfd_interface;
83 	uint8_t pfd_power;
84 };
85 
86 struct pccard_funce_lan {
87 	int pfl_nidlen;
88 	uint8_t pfl_nid[8];
89 };
90 
91 union pccard_funce {
92 	struct pccard_funce_disk pfv_disk;
93 	struct pccard_funce_lan pfv_lan;
94 };
95 
96 struct pccard_function {
97 	/* read off the card */
98 	int		number;
99 	int		function;
100 	int		last_config_index;
101 	uint32_t	ccr_base;	/* Offset with card's memory */
102 	uint32_t	ccr_mask;
103 	struct resource *ccr_res;
104 	int		ccr_rid;
105 	STAILQ_HEAD(, pccard_config_entry) cfe_head;
106 	STAILQ_ENTRY(pccard_function) pf_list;
107 	/* run-time state */
108 	struct pccard_softc *sc;
109 	struct pccard_config_entry *cfe;
110 	struct pccard_mem_handle pf_pcmh;
111 	device_t	dev;
112 #define	pf_ccrt		pf_pcmh.memt
113 #define	pf_ccrh		pf_pcmh.memh
114 #define	pf_ccr_realsize	pf_pcmh.realsize
115 	uint32_t	pf_ccr_offset;	/* Offset from ccr_base of CIS */
116 	int		pf_ccr_window;
117 	bus_addr_t	pf_mfc_iobase;
118 	bus_addr_t	pf_mfc_iomax;
119 	int		pf_flags;
120 	driver_filter_t	*intr_filter;
121 	driver_intr_t	*intr_handler;
122 	void		*intr_handler_arg;
123 	void		*intr_handler_cookie;
124 
125 	union pccard_funce pf_funce; /* CISTPL_FUNCE */
126 #define pf_funce_disk_interface pf_funce.pfv_disk.pfd_interface
127 #define pf_funce_disk_power pf_funce.pfv_disk.pfd_power
128 #define pf_funce_lan_nid pf_funce.pfv_lan.pfl_nid
129 #define pf_funce_lan_nidlen pf_funce.pfv_lan.pfl_nidlen
130 };
131 
132 /* pf_flags */
133 #define	PFF_ENABLED	0x0001		/* function is enabled */
134 
135 struct pccard_card {
136 	int		cis1_major;
137 	int		cis1_minor;
138 	/* XXX waste of space? */
139 	char		cis1_info_buf[256];
140 	char		*cis1_info[4];
141 	/*
142 	 * Use int32_t for manufacturer and product so that they can
143 	 * hold the id value found in card CIS and special value that
144 	 * indicates no id was found.
145 	 */
146 	int32_t		manufacturer;
147 #define	PCMCIA_VENDOR_INVALID	-1
148 	int32_t		product;
149 #define	PCMCIA_PRODUCT_INVALID		-1
150 	int16_t		prodext;
151 	uint16_t	error;
152 #define	PCMCIA_CIS_INVALID		{ NULL, NULL, NULL, NULL }
153 	STAILQ_HEAD(, pccard_function) pf_head;
154 };
155 
156 /* More later? */
157 struct pccard_ivar {
158 	struct resource_list resources;
159 	struct pccard_function *pf;
160 };
161 
162 struct cis_buffer
163 {
164 	size_t	len;			/* Actual length of the CIS */
165 	uint8_t buffer[2040];		/* small enough to be 2k */
166 };
167 
168 struct pccard_softc {
169 	device_t		dev;
170 	/* this stuff is for the socket */
171 
172 	/* this stuff is for the card */
173 	struct pccard_card card;
174 	int		sc_enabled_count;	/* num functions enabled */
175 	struct cdev *cisdev;
176 	int	cis_open;
177 	struct cis_buffer *cis;
178 };
179 
180 struct pccard_cis_quirk {
181 	int32_t manufacturer;
182 	int32_t product;
183 	char *cis1_info[4];
184 	struct pccard_function *pf;
185 	struct pccard_config_entry *cfe;
186 };
187 
188 void	pccard_read_cis(struct pccard_softc *);
189 void	pccard_check_cis_quirks(device_t);
190 void	pccard_print_cis(device_t);
191 int	pccard_scan_cis(device_t, device_t, pccard_scan_t, void *);
192 
193 int	pccard_device_create(struct pccard_softc *);
194 int	pccard_device_destroy(struct pccard_softc *);
195 
196 #define PCCARD_SOFTC(d) (struct pccard_softc *) device_get_softc(d)
197 #define PCCARD_IVAR(d) (struct pccard_ivar *) device_get_ivars(d)
198 
199 #endif /* _PCCARD_PCCARDVARP_H */
200