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