card_if.m revision 82378
1235633Sdim#
2224133Sdim# Copyright (c) 1999 M. Warner Losh.
3224133Sdim# All rights reserved.
4224133Sdim#
5224133Sdim# Redistribution and use in source and binary forms, with or without
6224133Sdim# modification, are permitted provided that the following conditions
7224133Sdim# are met:
8224133Sdim# 1. Redistributions of source code must retain the above copyright
9224133Sdim#    notice, this list of conditions and the following disclaimer.
10224133Sdim# 2. Redistributions in binary form must reproduce the above copyright
11224133Sdim#    notice, this list of conditions and the following disclaimer in the
12224133Sdim#    documentation and/or other materials provided with the distribution.
13224133Sdim#
14224133Sdim# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15252723Sdim# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16224133Sdim# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17226890Sdim# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18224133Sdim# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19224133Sdim# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20224133Sdim# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21235633Sdim# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22226890Sdim# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23224133Sdim# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24224133Sdim# SUCH DAMAGE.
25224133Sdim#
26224133Sdim# $FreeBSD: head/sys/dev/pccard/card_if.m 82378 2001-08-27 00:09:42Z jon $
27224133Sdim#
28224133Sdim
29224133Sdim#include <sys/bus.h>
30224133Sdim
31224133SdimINTERFACE card;
32224133Sdim
33224133Sdim# WARNING: THIS FILE IS USED BY BOTH OLDCARD AND NEWCARD.  MAKE SURE
34224133Sdim# YOU TEST BOTH KERNELS IF CHANGING THIS FILE.
35224133Sdim
36224133Sdim#
37224133Sdim# Companion interface for pccard.  We need to set attributes for memory
38224133Sdim# and i/o port mappings (as well as other types of attributes) that have
39224133Sdim# a well defined meaning inside the pccard/cardbus system.  The bus
40224133Sdim# methods are inadequate for this because this must be done at the time the
41226890Sdim# resources are set for the device, which predates their activation.  Also,
42226890Sdim# the driver activating the resources doesn't necessarily know or need to know
43226890Sdim# these attributes.
44226890Sdim#
45224133SdimMETHOD int set_res_flags {
46224133Sdim	device_t dev;
47224133Sdim	device_t child;
48224133Sdim	int	 restype;
49224133Sdim	int	 rid;
50224133Sdim	u_long	 value;
51224133Sdim};
52224133Sdim
53224133SdimMETHOD int get_res_flags {
54263509Sdim	device_t dev;
55263509Sdim	device_t child;
56263509Sdim	int	 restype;
57226890Sdim	int	 rid;
58226890Sdim	u_long	 *value;
59263509Sdim};
60263509Sdim
61226890Sdim#
62226890Sdim# Sets the memory offset of the pccard bridge's window into attribute
63226890Sdim# or common memory space.
64226890Sdim#
65226890SdimMETHOD int set_memory_offset {
66235633Sdim	device_t  dev;
67235633Sdim	device_t  child;
68226890Sdim	int	  rid;
69252723Sdim	u_int32_t cardaddr;
70252723Sdim	u_int32_t *deltap;
71252723Sdim}
72235633Sdim
73226890SdimMETHOD int get_memory_offset {
74226890Sdim	device_t  dev;
75226890Sdim	device_t  child;
76252723Sdim	int	  rid;
77252723Sdim	u_int32_t *offset;
78252723Sdim}
79252723Sdim
80252723Sdim#
81252723Sdim# pccard bridges call this method to initate the attachment of a card
82252723Sdim#
83252723SdimMETHOD int attach_card {
84252723Sdim	device_t  dev;
85226890Sdim}
86226890Sdim
87226890Sdim#
88226890Sdim# pccard bridges call this to detach a card.
89226890Sdim#
90226890SdimMETHOD int detach_card {
91226890Sdim	device_t  dev;
92226890Sdim	int	  flags;
93226890Sdim}
94226890Sdim
95226890Sdim#
96226890Sdim# pccard/cardbus buses call this to request a reprobe of the bus.
97226890Sdim# reprobe only initiated if the child bus is the same type the card inserted.
98226890Sdim#
99226890SdimMETHOD int reprobe_card {
100226890Sdim	device_t  dev;
101224133Sdim	device_t  child;
102224133Sdim}
103252723Sdim
104252723SdimHEADER {
105252723Sdim	#define DETACH_FORCE 0x01
106252723Sdim	#define DETACH_NOWARN 0x02
107224133Sdim}
108
109#
110# Returns the type of card this is.  Maybe we don't need this.
111#
112METHOD int get_type {
113	device_t  dev;
114	int	  *type;
115}
116
117#
118# Returns the function number for this device.
119#
120METHOD int get_function {
121	device_t  dev;
122	device_t  child;
123	int	  *func;
124}
125
126#
127# Activates (and powers up if necessary) the card's nth function
128# since each function gets its own device, there is no need to
129# to specify a function number
130#
131METHOD int activate_function {
132	device_t  dev;
133	device_t  child;
134}
135
136METHOD int deactivate_function {
137	device_t  dev;
138	device_t  child;
139}
140
141#
142# Compatibility methods for OLDCARD drivers.  We use these routines to make
143# it possible to call the OLDCARD driver's probe routine in the context that
144# it expects.  For OLDCARD these are implemented as pass throughs to the
145# device_{probe,attach} routines.  For NEWCARD they are implemented such
146# such that probe becomes strictly a matching routine and attach does both
147# the old probe and old attach.
148#
149# compat devices should use the following:
150#
151#	/* Device interface */
152#	DEVMETHOD(device_probe),	pccard_compat_probe),
153#	DEVMETHOD(device_attach),	pccard_compat_attach),
154#	/* Card interface */
155#	DEVMETHOD(card_compat_match,	foo_match),	/* newly written */
156#	DEVMETHOD(card_compat_probe,	foo_probe),	/* old probe */
157#	DEVMETHOD(card_compat_attach,	foo_attach),	/* old attach */
158#
159# This will allow a single driver binary image to be used for both
160# OLDCARD and NEWCARD.
161#
162# Drivers wishing to not retain OLDCARD compatibility needn't do this.
163#
164# The compat_do_* versions are so that we can make the pccard_compat_probe
165# and _attach static lines and have the bus system pick the right version
166# to use so we don't enshrine pccard_* symbols in the driver's module.
167#
168METHOD int compat_probe {
169	device_t dev;
170}
171
172METHOD int compat_attach {
173	device_t dev;
174}
175
176CODE {
177	static int null_do_probe(device_t bus, device_t dev) __unused;
178
179	static int null_do_probe(device_t bus, device_t dev)
180	{
181		return (CARD_COMPAT_DO_PROBE(device_get_parent(bus), dev));
182	}
183
184	static int null_do_attach(device_t bus, device_t dev)
185	{
186		return (CARD_COMPAT_DO_ATTACH(device_get_parent(bus), dev));
187	}
188}
189
190METHOD int compat_do_probe {
191	device_t bus;
192	device_t dev;
193} DEFAULT null_do_attach;
194
195METHOD int compat_do_attach {
196	device_t bus;
197	device_t dev;
198} DEFAULT null_do_attach;
199
200#
201# Helper method for the above.  When a compatibility driver is converted,
202# one must write a match routine.  This routine is unused on OLDCARD but
203# is used as a discriminator for NEWCARD.
204#
205METHOD int compat_match {
206	device_t dev;
207}
208
209#
210# Method for devices to ask its CIS-enabled parent bus for CIS info.
211# Device driver requests all tuples if type 'id', the routine places
212# 'nret' number of tuples in 'buff'.  Returns 0 if all tuples processed,
213# or an error code if processing was aborted.
214# Users of this method will be responsible for freeing the memory allocated
215# by calling the cis_free method.
216#
217
218HEADER {
219	struct cis_tupleinfo {
220		u_int8_t id;
221		int len;
222		char *data;
223	};
224};
225
226CODE  {
227	static int
228	null_cis_read(device_t dev, device_t child, u_int8_t id,
229	    struct cis_tupleinfo **buff, int *nret)
230	{
231		*nret = 0;
232		*buff = NULL;
233		return ENXIO;
234	}
235	static void
236	null_cis_free(device_t dev, struct cis_tupleinfo *buff, int *nret)
237	{
238		return;
239	}
240};
241
242
243METHOD int cis_read {
244	device_t dev;
245	device_t child;
246	u_int8_t id;
247	struct	 cis_tupleinfo **buff;
248	int	 *nret;
249} DEFAULT null_cis_read;
250
251METHOD int cis_free {
252	device_t dev;
253	struct	 cis_tupleinfo *buff;
254	int	 nret;
255} DEFAULT null_cis_free;
256
257
258