xref: /dragonfly/sys/bus/pccard/card_if.m (revision 333227be)
1#
2# Copyright (c) 1999 M. Warner Losh.
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9#    notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11#    notice, this list of conditions and the following disclaimer in the
12#    documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24# SUCH DAMAGE.
25#
26# $FreeBSD: src/sys/dev/pccard/card_if.m,v 1.21 2002/11/02 23:00:28 imp Exp $
27# $DragonFly: src/sys/bus/pccard/card_if.m,v 1.1 2004/02/10 07:55:45 joerg Exp $
28#
29
30#include <sys/bus.h>
31#include <bus/pccard/pccardvar.h>
32
33INTERFACE card;
34
35# WARNING: THIS FILE IS USED BY BOTH OLDCARD AND NEWCARD.  MAKE SURE
36# YOU TEST BOTH KERNELS IF CHANGING THIS FILE.
37
38#
39# Companion interface for pccard.  We need to set attributes for memory
40# and i/o port mappings (as well as other types of attributes) that have
41# a well defined meaning inside the pccard/cardbus system.  The bus
42# methods are inadequate for this because this must be done at the time the
43# resources are set for the device, which predates their activation.  Also,
44# the driver activating the resources doesn't necessarily know or need to know
45# these attributes.
46#
47METHOD int set_res_flags {
48	device_t dev;
49	device_t child;
50	int	 restype;
51	int	 rid;
52	u_long	 value;
53};
54
55METHOD int get_res_flags {
56	device_t dev;
57	device_t child;
58	int	 restype;
59	int	 rid;
60	u_long	 *value;
61};
62
63#
64# Sets the memory offset of the pccard bridge's window into attribute
65# or common memory space.
66#
67METHOD int set_memory_offset {
68	device_t  dev;
69	device_t  child;
70	int	  rid;
71	u_int32_t cardaddr;
72	u_int32_t *deltap;
73}
74
75METHOD int get_memory_offset {
76	device_t  dev;
77	device_t  child;
78	int	  rid;
79	u_int32_t *offset;
80}
81
82#
83# pccard bridges call this method to initate the attachment of a card
84#
85METHOD int attach_card {
86	device_t  dev;
87}
88
89#
90# pccard bridges call this to detach a card.
91#
92METHOD int detach_card {
93	device_t  dev;
94}
95
96#
97# Returns the type of card this is.  Maybe we don't need this.
98#
99METHOD int get_type {
100	device_t  dev;
101	int	  *type;
102}
103
104#
105# Returns the function number for this device.
106#
107METHOD int get_function {
108	device_t  dev;
109	device_t  child;
110	int	  *func;
111}
112
113#
114# Activates (and powers up if necessary) the card's nth function
115# since each function gets its own device, there is no need to
116# to specify a function number
117#
118METHOD int activate_function {
119	device_t  dev;
120	device_t  child;
121}
122
123METHOD int deactivate_function {
124	device_t  dev;
125	device_t  child;
126}
127
128#
129# Compatibility methods for OLDCARD drivers.  We use these routines to make
130# it possible to call the OLDCARD driver's probe routine in the context that
131# it expects.  For OLDCARD these are implemented as pass throughs to the
132# device_{probe,attach} routines.  For NEWCARD they are implemented such
133# such that probe becomes strictly a matching routine and attach does both
134# the old probe and old attach.
135#
136# compat devices should use the following:
137#
138#	/* Device interface */
139#	DEVMETHOD(device_probe),	pccard_compat_probe),
140#	DEVMETHOD(device_attach),	pccard_compat_attach),
141#	/* Card interface */
142#	DEVMETHOD(card_compat_match,	foo_match),	/* newly written */
143#	DEVMETHOD(card_compat_probe,	foo_probe),	/* old probe */
144#	DEVMETHOD(card_compat_attach,	foo_attach),	/* old attach */
145#
146# This will allow a single driver binary image to be used for both
147# OLDCARD and NEWCARD.
148#
149# Drivers wishing to not retain OLDCARD compatibility needn't do this.
150#
151# The compat_do_* versions are so that we can make the pccard_compat_probe
152# and _attach static lines and have the bus system pick the right version
153# to use so we don't enshrine pccard_* symbols in the driver's module.
154#
155METHOD int compat_probe {
156	device_t dev;
157}
158
159METHOD int compat_attach {
160	device_t dev;
161}
162
163CODE {
164	static int null_do_probe(device_t bus, device_t dev)
165	{
166		return (CARD_COMPAT_DO_PROBE(device_get_parent(bus), dev));
167	}
168
169	static int null_do_attach(device_t bus, device_t dev)
170	{
171		return (CARD_COMPAT_DO_ATTACH(device_get_parent(bus), dev));
172	}
173}
174
175METHOD int compat_do_probe {
176	device_t bus;
177	device_t dev;
178} DEFAULT null_do_probe;
179
180METHOD int compat_do_attach {
181	device_t bus;
182	device_t dev;
183} DEFAULT null_do_attach;
184
185#
186# Find "dev" in the passed table of devices.  Return it or NULL.
187#
188METHOD struct pccard_product * do_product_lookup {
189	device_t bus;
190	device_t dev;
191	const struct pccard_product *tab;
192	size_t ent_size;
193	pccard_product_match_fn matchfn;
194}
195
196#
197# Helper method for the above.  When a compatibility driver is converted,
198# one must write a match routine.  This routine is unused on OLDCARD but
199# is used as a discriminator for NEWCARD.
200#
201METHOD int compat_match {
202	device_t dev;
203}
204
205#
206# Method for devices to ask its CIS-enabled parent bus for CIS info.
207# Device driver requests all tuples if type 'id', the routine places
208# 'nret' number of tuples in 'buff'.  Returns 0 if all tuples processed,
209# or an error code if processing was aborted.
210# Users of this method will be responsible for freeing the memory allocated
211# by calling the cis_free method.
212#
213
214HEADER {
215	struct cis_tupleinfo {
216		u_int8_t id;
217		int len;
218		char *data;
219	};
220};
221
222CODE  {
223	static int
224	null_cis_read(device_t dev, device_t child, u_int8_t id,
225	    struct cis_tupleinfo **buff, int *nret)
226	{
227		*nret = 0;
228		*buff = NULL;
229		return ENXIO;
230	}
231
232	static void
233	null_cis_free(device_t dev, struct cis_tupleinfo *buff, int *nret)
234	{
235		return;
236	}
237};
238
239METHOD int cis_read {
240	device_t dev;
241	device_t child;
242	u_int8_t id;
243	struct	 cis_tupleinfo **buff;
244	int	 *nret;
245} DEFAULT null_cis_read;
246
247METHOD int cis_free {
248	device_t dev;
249	struct	 cis_tupleinfo *buff;
250	int	 nret;
251} DEFAULT null_cis_free;
252
253