card_if.m revision 106362
1251877Speter#
2251877Speter# Copyright (c) 1999 M. Warner Losh.
3251877Speter# All rights reserved.
4251877Speter#
5251877Speter# Redistribution and use in source and binary forms, with or without
6251877Speter# modification, are permitted provided that the following conditions
7251877Speter# are met:
8251877Speter# 1. Redistributions of source code must retain the above copyright
9251877Speter#    notice, this list of conditions and the following disclaimer.
10251877Speter# 2. Redistributions in binary form must reproduce the above copyright
11251877Speter#    notice, this list of conditions and the following disclaimer in the
12251877Speter#    documentation and/or other materials provided with the distribution.
13251877Speter#
14251877Speter# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15251877Speter# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16251877Speter# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17251877Speter# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18251877Speter# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19251877Speter# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20251877Speter# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21251877Speter# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22251877Speter# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23251877Speter# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24251877Speter# SUCH DAMAGE.
25251877Speter#
26262339Speter# $FreeBSD: head/sys/dev/pccard/card_if.m 106362 2002-11-02 23:00:28Z imp $
27262339Speter#
28262339Speter
29251877Speter#include <sys/bus.h>
30251877Speter#include <dev/pccard/pccardvar.h>
31253895Speter
32253895SpeterINTERFACE card;
33253895Speter
34253895Speter# WARNING: THIS FILE IS USED BY BOTH OLDCARD AND NEWCARD.  MAKE SURE
35253895Speter# YOU TEST BOTH KERNELS IF CHANGING THIS FILE.
36253895Speter
37253895Speter#
38251877Speter# Companion interface for pccard.  We need to set attributes for memory
39251877Speter# and i/o port mappings (as well as other types of attributes) that have
40251877Speter# a well defined meaning inside the pccard/cardbus system.  The bus
41251877Speter# methods are inadequate for this because this must be done at the time the
42251877Speter# resources are set for the device, which predates their activation.  Also,
43251877Speter# the driver activating the resources doesn't necessarily know or need to know
44251877Speter# these attributes.
45251877Speter#
46251877SpeterMETHOD int set_res_flags {
47251877Speter	device_t dev;
48251877Speter	device_t child;
49251877Speter	int	 restype;
50251877Speter	int	 rid;
51253895Speter	u_long	 value;
52253895Speter};
53251877Speter
54253895SpeterMETHOD int get_res_flags {
55253895Speter	device_t dev;
56253895Speter	device_t child;
57253895Speter	int	 restype;
58253895Speter	int	 rid;
59253895Speter	u_long	 *value;
60253895Speter};
61253895Speter
62253895Speter#
63253895Speter# Sets the memory offset of the pccard bridge's window into attribute
64251877Speter# or common memory space.
65251877Speter#
66251877SpeterMETHOD int set_memory_offset {
67251877Speter	device_t  dev;
68251877Speter	device_t  child;
69251877Speter	int	  rid;
70251877Speter	u_int32_t cardaddr;
71251877Speter	u_int32_t *deltap;
72251877Speter}
73251877Speter
74251877SpeterMETHOD int get_memory_offset {
75251877Speter	device_t  dev;
76251877Speter	device_t  child;
77251877Speter	int	  rid;
78251877Speter	u_int32_t *offset;
79251877Speter}
80251877Speter
81251877Speter#
82251877Speter# pccard bridges call this method to initate the attachment of a card
83251877Speter#
84251877SpeterMETHOD int attach_card {
85251877Speter	device_t  dev;
86251877Speter}
87251877Speter
88251877Speter#
89251877Speter# pccard bridges call this to detach a card.
90251877Speter#
91251877SpeterMETHOD int detach_card {
92251877Speter	device_t  dev;
93251877Speter}
94251877Speter
95251877Speter#
96251877Speter# Returns the type of card this is.  Maybe we don't need this.
97251877Speter#
98262339SpeterMETHOD int get_type {
99251877Speter	device_t  dev;
100253895Speter	int	  *type;
101253895Speter}
102251877Speter
103251877Speter#
104251877Speter# Returns the function number for this device.
105251877Speter#
106251877SpeterMETHOD int get_function {
107251877Speter	device_t  dev;
108251877Speter	device_t  child;
109251877Speter	int	  *func;
110251877Speter}
111251877Speter
112251877Speter#
113251877Speter# Activates (and powers up if necessary) the card's nth function
114251877Speter# since each function gets its own device, there is no need to
115251877Speter# to specify a function number
116251877Speter#
117251877SpeterMETHOD int activate_function {
118251877Speter	device_t  dev;
119251877Speter	device_t  child;
120251877Speter}
121251877Speter
122262339SpeterMETHOD int deactivate_function {
123262339Speter	device_t  dev;
124251877Speter	device_t  child;
125251877Speter}
126251877Speter
127251877Speter#
128251877Speter# Compatibility methods for OLDCARD drivers.  We use these routines to make
129251877Speter# it possible to call the OLDCARD driver's probe routine in the context that
130251877Speter# it expects.  For OLDCARD these are implemented as pass throughs to the
131251877Speter# device_{probe,attach} routines.  For NEWCARD they are implemented such
132251877Speter# such that probe becomes strictly a matching routine and attach does both
133251877Speter# the old probe and old attach.
134251877Speter#
135251877Speter# compat devices should use the following:
136251877Speter#
137251877Speter#	/* Device interface */
138251877Speter#	DEVMETHOD(device_probe),	pccard_compat_probe),
139251877Speter#	DEVMETHOD(device_attach),	pccard_compat_attach),
140251877Speter#	/* Card interface */
141251877Speter#	DEVMETHOD(card_compat_match,	foo_match),	/* newly written */
142251877Speter#	DEVMETHOD(card_compat_probe,	foo_probe),	/* old probe */
143251877Speter#	DEVMETHOD(card_compat_attach,	foo_attach),	/* old attach */
144251877Speter#
145251877Speter# This will allow a single driver binary image to be used for both
146251877Speter# OLDCARD and NEWCARD.
147251877Speter#
148251877Speter# Drivers wishing to not retain OLDCARD compatibility needn't do this.
149251877Speter#
150253895Speter# The compat_do_* versions are so that we can make the pccard_compat_probe
151253895Speter# and _attach static lines and have the bus system pick the right version
152253895Speter# to use so we don't enshrine pccard_* symbols in the driver's module.
153253895Speter#
154253895SpeterMETHOD int compat_probe {
155253895Speter	device_t dev;
156253895Speter}
157253895Speter
158253895SpeterMETHOD int compat_attach {
159251877Speter	device_t dev;
160251877Speter}
161251877Speter
162251877SpeterCODE {
163251877Speter	static int null_do_probe(device_t bus, device_t dev)
164251877Speter	{
165251877Speter		return (CARD_COMPAT_DO_PROBE(device_get_parent(bus), dev));
166251877Speter	}
167251877Speter
168251877Speter	static int null_do_attach(device_t bus, device_t dev)
169251877Speter	{
170251877Speter		return (CARD_COMPAT_DO_ATTACH(device_get_parent(bus), dev));
171251877Speter	}
172251877Speter}
173251877Speter
174251877SpeterMETHOD int compat_do_probe {
175251877Speter	device_t bus;
176251877Speter	device_t dev;
177251877Speter} DEFAULT null_do_probe;
178251877Speter
179251877SpeterMETHOD int compat_do_attach {
180251877Speter	device_t bus;
181251877Speter	device_t dev;
182251877Speter} DEFAULT null_do_attach;
183251877Speter
184251877Speter#
185251877Speter# Find "dev" in the passed table of devices.  Return it or NULL.
186251877Speter#
187251877SpeterMETHOD struct pccard_product * do_product_lookup {
188251877Speter	device_t bus;
189251877Speter	device_t dev;
190251877Speter	const struct pccard_product *tab;
191253895Speter	size_t ent_size;
192251877Speter	pccard_product_match_fn matchfn;
193251877Speter}
194251877Speter
195251877Speter#
196251877Speter# Helper method for the above.  When a compatibility driver is converted,
197251877Speter# one must write a match routine.  This routine is unused on OLDCARD but
198251877Speter# is used as a discriminator for NEWCARD.
199251877Speter#
200251877SpeterMETHOD int compat_match {
201251877Speter	device_t dev;
202251877Speter}
203251877Speter
204251877Speter#
205251877Speter# Method for devices to ask its CIS-enabled parent bus for CIS info.
206251877Speter# Device driver requests all tuples if type 'id', the routine places
207251877Speter# 'nret' number of tuples in 'buff'.  Returns 0 if all tuples processed,
208251877Speter# or an error code if processing was aborted.
209251877Speter# Users of this method will be responsible for freeing the memory allocated
210251877Speter# by calling the cis_free method.
211251877Speter#
212251877Speter
213251877SpeterHEADER {
214251877Speter	struct cis_tupleinfo {
215251877Speter		u_int8_t id;
216251877Speter		int len;
217251877Speter		char *data;
218251877Speter	};
219251877Speter};
220251877Speter
221251877SpeterCODE  {
222251877Speter	static int
223251877Speter	null_cis_read(device_t dev, device_t child, u_int8_t id,
224251877Speter	    struct cis_tupleinfo **buff, int *nret)
225251877Speter	{
226251877Speter		*nret = 0;
227251877Speter		*buff = NULL;
228251877Speter		return ENXIO;
229251877Speter	}
230251877Speter
231251877Speter	static void
232251877Speter	null_cis_free(device_t dev, struct cis_tupleinfo *buff, int *nret)
233251877Speter	{
234251877Speter		return;
235251877Speter	}
236251877Speter};
237251877Speter
238251877SpeterMETHOD int cis_read {
239251877Speter	device_t dev;
240251877Speter	device_t child;
241251877Speter	u_int8_t id;
242251877Speter	struct	 cis_tupleinfo **buff;
243251877Speter	int	 *nret;
244251877Speter} DEFAULT null_cis_read;
245251877Speter
246251877SpeterMETHOD int cis_free {
247251877Speter	device_t dev;
248251877Speter	struct	 cis_tupleinfo *buff;
249251877Speter	int	 nret;
250251877Speter} DEFAULT null_cis_free;
251251877Speter
252251877Speter