card_if.m revision 141882
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: head/sys/dev/pccard/card_if.m 141882 2005-02-14 07:00:39Z imp $
27#
28
29#include <sys/bus.h>
30#include <machine/bus.h>
31#include <dev/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	uint32_t cardaddr;
72	uint32_t *deltap;
73}
74
75METHOD int get_memory_offset {
76	device_t  dev;
77	device_t  child;
78	int	  rid;
79	uint32_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# Activates (and powers up if necessary) the card's nth function
98# since each function gets its own device, there is no need to
99# to specify a function number
100#
101METHOD int activate_function {
102	device_t  dev;
103	device_t  child;
104}
105
106METHOD int deactivate_function {
107	device_t  dev;
108	device_t  child;
109}
110
111#
112# Compatibility methods for OLDCARD drivers.  We use these routines to make
113# it possible to call the OLDCARD driver's probe routine in the context that
114# it expects.  For OLDCARD these are implemented as pass throughs to the
115# device_{probe,attach} routines.  For NEWCARD they are implemented such
116# such that probe becomes strictly a matching routine and attach does both
117# the old probe and old attach.
118#
119# compat devices should use the following:
120#
121#	/* Device interface */
122#	DEVMETHOD(device_probe),	pccard_compat_probe),
123#	DEVMETHOD(device_attach),	pccard_compat_attach),
124#	/* Card interface */
125#	DEVMETHOD(card_compat_match,	foo_match),	/* newly written */
126#	DEVMETHOD(card_compat_probe,	foo_probe),	/* old probe */
127#	DEVMETHOD(card_compat_attach,	foo_attach),	/* old attach */
128#
129# This will allow a single driver binary image to be used for both
130# OLDCARD and NEWCARD.
131#
132# Drivers wishing to not retain OLDCARD compatibility needn't do this.
133#
134# The compat_do_* versions are so that we can make the pccard_compat_probe
135# and _attach static lines and have the bus system pick the right version
136# to use so we don't enshrine pccard_* symbols in the driver's module.
137#
138METHOD int compat_probe {
139	device_t dev;
140}
141
142METHOD int compat_attach {
143	device_t dev;
144}
145
146CODE {
147	static int null_do_probe(device_t bus, device_t dev)
148	{
149		return (CARD_COMPAT_DO_PROBE(device_get_parent(bus), dev));
150	}
151
152	static int null_do_attach(device_t bus, device_t dev)
153	{
154		return (CARD_COMPAT_DO_ATTACH(device_get_parent(bus), dev));
155	}
156}
157
158METHOD int compat_do_probe {
159	device_t bus;
160	device_t dev;
161} DEFAULT null_do_probe;
162
163METHOD int compat_do_attach {
164	device_t bus;
165	device_t dev;
166} DEFAULT null_do_attach;
167
168#
169# Find "dev" in the passed table of devices.  Return it or NULL.
170#
171METHOD struct pccard_product * do_product_lookup {
172	device_t bus;
173	device_t dev;
174	const struct pccard_product *tab;
175	size_t ent_size;
176	pccard_product_match_fn matchfn;
177}
178
179#
180# Helper method for the above.  When a compatibility driver is converted,
181# one must write a match routine.  This routine is unused on OLDCARD but
182# is used as a discriminator for NEWCARD.
183#
184METHOD int compat_match {
185	device_t dev;
186}
187