1150362Simp/*-
2150362Simp * Copyright (c) 2005, M. Warner Losh
3150362Simp * All rights reserved.
4150362Simp *
5150362Simp * Redistribution and use in source and binary forms, with or without
6150362Simp * modification, are permitted provided that the following conditions
7150362Simp * are met:
8150362Simp * 1. Redistributions of source code must retain the above copyright
9150362Simp *    notice unmodified, this list of conditions, and the following
10150362Simp *    disclaimer.
11150362Simp * 2. Redistributions in binary form must reproduce the above copyright
12150362Simp *    notice, this list of conditions and the following disclaimer in the
13150362Simp *    documentation and/or other materials provided with the distribution.
14150362Simp *
15150362Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16150362Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17150362Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18150362Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19150362Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20150362Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21150362Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22150362Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23150362Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24150362Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25150362Simp * SUCH DAMAGE.
26150362Simp *
27150362Simp * $FreeBSD$
28150362Simp */
29150362Simp
30150362Simp#ifndef _PCCARD_PCCARDVARP_H
31150362Simp#define _PCCARD_PCCARDVARP_H
32150362Simp
33150362Simp/* pccard itself */
34150362Simp
35151368Simp#define PCCARD_MEM_PAGE_SIZE		1024
36150362Simp
37150362Simp#define PCCARD_CFE_MWAIT_REQUIRED	0x0001
38150362Simp#define PCCARD_CFE_RDYBSY_ACTIVE	0x0002
39150362Simp#define PCCARD_CFE_WP_ACTIVE		0x0004
40150362Simp#define PCCARD_CFE_BVD_ACTIVE		0x0008
41150362Simp#define PCCARD_CFE_IO8			0x0010
42150362Simp#define PCCARD_CFE_IO16			0x0020
43150362Simp#define PCCARD_CFE_IRQSHARE		0x0040
44150362Simp#define PCCARD_CFE_IRQPULSE		0x0080
45150362Simp#define PCCARD_CFE_IRQLEVEL		0x0100
46150362Simp#define PCCARD_CFE_POWERDOWN		0x0200
47150362Simp#define PCCARD_CFE_READONLY		0x0400
48150362Simp#define PCCARD_CFE_AUDIO		0x0800
49150362Simp
50237692Simpstruct pccard_ce_iospace {
51294883Sjhibbits	rman_res_t	length;
52294883Sjhibbits	rman_res_t	start;
53237692Simp};
54237692Simp
55237692Simpstruct pccard_ce_memspace {
56294883Sjhibbits	rman_res_t	length;
57294883Sjhibbits	rman_res_t	cardaddr;
58294883Sjhibbits	rman_res_t	hostaddr;
59237692Simp};
60237692Simp
61150362Simpstruct pccard_config_entry {
62150362Simp	int		number;
63150362Simp	uint32_t	flags;
64150362Simp	int		iftype;
65150362Simp	int		num_iospace;
66150362Simp	/*
67150362Simp	 * The card will only decode this mask in any case, so we can
68150362Simp	 * do dynamic allocation with this in mind, in case the suggestions
69150362Simp	 * below are no good.
70150362Simp	 */
71150362Simp	u_long		iomask;
72237692Simp	struct pccard_ce_iospace iospace[4]; /* XXX up to 16 */
73150362Simp	uint16_t	irqmask;
74150362Simp	int		num_memspace;
75237692Simp	struct pccard_ce_memspace memspace[2];	/* XXX up to 8 */
76150362Simp	int		maxtwins;
77150362Simp	STAILQ_ENTRY(pccard_config_entry) cfe_list;
78150362Simp};
79150362Simp
80150362Simpstruct pccard_funce_disk {
81188219Simp	uint8_t pfd_interface;
82188219Simp	uint8_t pfd_power;
83150362Simp};
84150362Simp
85150362Simpstruct pccard_funce_lan {
86150362Simp	int pfl_nidlen;
87150362Simp	uint8_t pfl_nid[8];
88150362Simp};
89150362Simp
90150362Simpunion pccard_funce {
91150362Simp	struct pccard_funce_disk pfv_disk;
92150362Simp	struct pccard_funce_lan pfv_lan;
93150362Simp};
94150362Simp
95150362Simpstruct pccard_function {
96150362Simp	/* read off the card */
97150362Simp	int		number;
98150362Simp	int		function;
99150362Simp	int		last_config_index;
100150362Simp	uint32_t	ccr_base;	/* Offset with card's memory */
101150362Simp	uint32_t	ccr_mask;
102150362Simp	struct resource *ccr_res;
103150362Simp	int		ccr_rid;
104150362Simp	STAILQ_HEAD(, pccard_config_entry) cfe_head;
105150362Simp	STAILQ_ENTRY(pccard_function) pf_list;
106150362Simp	/* run-time state */
107150362Simp	struct pccard_softc *sc;
108150362Simp	struct pccard_config_entry *cfe;
109150362Simp	struct pccard_mem_handle pf_pcmh;
110150362Simp	device_t	dev;
111150362Simp#define	pf_ccrt		pf_pcmh.memt
112150362Simp#define	pf_ccrh		pf_pcmh.memh
113150362Simp#define	pf_ccr_realsize	pf_pcmh.realsize
114150362Simp	uint32_t	pf_ccr_offset;	/* Offset from ccr_base of CIS */
115150362Simp	int		pf_ccr_window;
116150362Simp	bus_addr_t	pf_mfc_iobase;
117150362Simp	bus_addr_t	pf_mfc_iomax;
118150362Simp	int		pf_flags;
119170163Spiso	driver_filter_t	*intr_filter;
120150362Simp	driver_intr_t	*intr_handler;
121150362Simp	void		*intr_handler_arg;
122150362Simp	void		*intr_handler_cookie;
123150362Simp
124150362Simp	union pccard_funce pf_funce; /* CISTPL_FUNCE */
125150362Simp#define pf_funce_disk_interface pf_funce.pfv_disk.pfd_interface
126188219Simp#define pf_funce_disk_power pf_funce.pfv_disk.pfd_power
127150362Simp#define pf_funce_lan_nid pf_funce.pfv_lan.pfl_nid
128150362Simp#define pf_funce_lan_nidlen pf_funce.pfv_lan.pfl_nidlen
129150362Simp};
130150362Simp
131150362Simp/* pf_flags */
132150362Simp#define	PFF_ENABLED	0x0001		/* function is enabled */
133150362Simp
134150362Simpstruct pccard_card {
135150362Simp	int		cis1_major;
136150362Simp	int		cis1_minor;
137150362Simp	/* XXX waste of space? */
138150362Simp	char		cis1_info_buf[256];
139150362Simp	char		*cis1_info[4];
140150362Simp	/*
141150362Simp	 * Use int32_t for manufacturer and product so that they can
142150362Simp	 * hold the id value found in card CIS and special value that
143150362Simp	 * indicates no id was found.
144150362Simp	 */
145150362Simp	int32_t		manufacturer;
146150362Simp#define	PCMCIA_VENDOR_INVALID	-1
147150362Simp	int32_t		product;
148150362Simp#define	PCMCIA_PRODUCT_INVALID		-1
149150362Simp	int16_t		prodext;
150150362Simp	uint16_t	error;
151150362Simp#define	PCMCIA_CIS_INVALID		{ NULL, NULL, NULL, NULL }
152150362Simp	STAILQ_HEAD(, pccard_function) pf_head;
153150362Simp};
154150362Simp
155150362Simp/* More later? */
156150362Simpstruct pccard_ivar {
157150362Simp	struct resource_list resources;
158150362Simp	struct pccard_function *pf;
159150362Simp};
160150362Simp
161150362Simpstruct cis_buffer
162150362Simp{
163150362Simp	size_t	len;			/* Actual length of the CIS */
164150362Simp	uint8_t buffer[2040];		/* small enough to be 2k */
165150362Simp};
166150362Simp
167150362Simpstruct pccard_softc {
168150362Simp	device_t		dev;
169150362Simp	/* this stuff is for the socket */
170150362Simp
171150362Simp	/* this stuff is for the card */
172150362Simp	struct pccard_card card;
173150362Simp	int		sc_enabled_count;	/* num functions enabled */
174150362Simp	struct cdev *cisdev;
175150362Simp	int	cis_open;
176150362Simp	struct cis_buffer *cis;
177150362Simp};
178150362Simp
179150362Simpstruct pccard_cis_quirk {
180150362Simp	int32_t manufacturer;
181150362Simp	int32_t product;
182150362Simp	char *cis1_info[4];
183150362Simp	struct pccard_function *pf;
184150362Simp	struct pccard_config_entry *cfe;
185150362Simp};
186150362Simp
187150362Simpvoid	pccard_read_cis(struct pccard_softc *);
188150362Simpvoid	pccard_check_cis_quirks(device_t);
189150362Simpvoid	pccard_print_cis(device_t);
190150362Simpint	pccard_scan_cis(device_t, device_t, pccard_scan_t, void *);
191150362Simp
192150362Simpint	pccard_device_create(struct pccard_softc *);
193150362Simpint	pccard_device_destroy(struct pccard_softc *);
194150362Simp
195150362Simp#define PCCARD_SOFTC(d) (struct pccard_softc *) device_get_softc(d)
196150362Simp#define PCCARD_IVAR(d) (struct pccard_ivar *) device_get_ivars(d)
197150362Simp
198150362Simp#endif /* _PCCARD_PCCARDVARP_H */
199