card_if.m revision 90338
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 90338 2002-02-07 06:43:29Z imp $ 27# 28 29#include <sys/bus.h> 30 31INTERFACE card; 32 33# WARNING: THIS FILE IS USED BY BOTH OLDCARD AND NEWCARD. MAKE SURE 34# YOU TEST BOTH KERNELS IF CHANGING THIS FILE. 35 36# 37# Companion interface for pccard. We need to set attributes for memory 38# and i/o port mappings (as well as other types of attributes) that have 39# a well defined meaning inside the pccard/cardbus system. The bus 40# methods are inadequate for this because this must be done at the time the 41# resources are set for the device, which predates their activation. Also, 42# the driver activating the resources doesn't necessarily know or need to know 43# these attributes. 44# 45METHOD int set_res_flags { 46 device_t dev; 47 device_t child; 48 int restype; 49 int rid; 50 u_long value; 51}; 52 53METHOD int get_res_flags { 54 device_t dev; 55 device_t child; 56 int restype; 57 int rid; 58 u_long *value; 59}; 60 61# 62# Sets the memory offset of the pccard bridge's window into attribute 63# or common memory space. 64# 65METHOD int set_memory_offset { 66 device_t dev; 67 device_t child; 68 int rid; 69 u_int32_t cardaddr; 70 u_int32_t *deltap; 71} 72 73METHOD int get_memory_offset { 74 device_t dev; 75 device_t child; 76 int rid; 77 u_int32_t *offset; 78} 79 80# 81# pccard bridges call this method to initate the attachment of a card 82# 83METHOD int attach_card { 84 device_t dev; 85} 86 87# 88# pccard bridges call this to detach a card. 89# 90METHOD int detach_card { 91 device_t dev; 92 int flags; 93} 94 95# 96# pccard/cardbus buses call this to request a reprobe of the bus. 97# reprobe only initiated if the child bus is the same type the card inserted. 98# 99METHOD int reprobe_card { 100 device_t dev; 101 device_t child; 102} 103 104HEADER { 105 #define DETACH_FORCE 0x01 106} 107 108# 109# Returns the type of card this is. Maybe we don't need this. 110# 111METHOD int get_type { 112 device_t dev; 113 int *type; 114} 115 116# 117# Returns the function number for this device. 118# 119METHOD int get_function { 120 device_t dev; 121 device_t child; 122 int *func; 123} 124 125# 126# Activates (and powers up if necessary) the card's nth function 127# since each function gets its own device, there is no need to 128# to specify a function number 129# 130METHOD int activate_function { 131 device_t dev; 132 device_t child; 133} 134 135METHOD int deactivate_function { 136 device_t dev; 137 device_t child; 138} 139 140# 141# Compatibility methods for OLDCARD drivers. We use these routines to make 142# it possible to call the OLDCARD driver's probe routine in the context that 143# it expects. For OLDCARD these are implemented as pass throughs to the 144# device_{probe,attach} routines. For NEWCARD they are implemented such 145# such that probe becomes strictly a matching routine and attach does both 146# the old probe and old attach. 147# 148# compat devices should use the following: 149# 150# /* Device interface */ 151# DEVMETHOD(device_probe), pccard_compat_probe), 152# DEVMETHOD(device_attach), pccard_compat_attach), 153# /* Card interface */ 154# DEVMETHOD(card_compat_match, foo_match), /* newly written */ 155# DEVMETHOD(card_compat_probe, foo_probe), /* old probe */ 156# DEVMETHOD(card_compat_attach, foo_attach), /* old attach */ 157# 158# This will allow a single driver binary image to be used for both 159# OLDCARD and NEWCARD. 160# 161# Drivers wishing to not retain OLDCARD compatibility needn't do this. 162# 163# The compat_do_* versions are so that we can make the pccard_compat_probe 164# and _attach static lines and have the bus system pick the right version 165# to use so we don't enshrine pccard_* symbols in the driver's module. 166# 167METHOD int compat_probe { 168 device_t dev; 169} 170 171METHOD int compat_attach { 172 device_t dev; 173} 174 175CODE { 176 static int null_do_probe(device_t bus, device_t dev) __unused; 177 178 static int null_do_probe(device_t bus, device_t dev) 179 { 180 return (CARD_COMPAT_DO_PROBE(device_get_parent(bus), dev)); 181 } 182 183 static int null_do_attach(device_t bus, device_t dev) 184 { 185 return (CARD_COMPAT_DO_ATTACH(device_get_parent(bus), dev)); 186 } 187} 188 189METHOD int compat_do_probe { 190 device_t bus; 191 device_t dev; 192} DEFAULT null_do_attach; 193 194METHOD int compat_do_attach { 195 device_t bus; 196 device_t dev; 197} DEFAULT null_do_attach; 198 199# 200# Helper method for the above. When a compatibility driver is converted, 201# one must write a match routine. This routine is unused on OLDCARD but 202# is used as a discriminator for NEWCARD. 203# 204METHOD int compat_match { 205 device_t dev; 206} 207 208# 209# Method for devices to ask its CIS-enabled parent bus for CIS info. 210# Device driver requests all tuples if type 'id', the routine places 211# 'nret' number of tuples in 'buff'. Returns 0 if all tuples processed, 212# or an error code if processing was aborted. 213# Users of this method will be responsible for freeing the memory allocated 214# by calling the cis_free method. 215# 216 217HEADER { 218 struct cis_tupleinfo { 219 u_int8_t id; 220 int len; 221 char *data; 222 }; 223}; 224 225CODE { 226 static int 227 null_cis_read(device_t dev, device_t child, u_int8_t id, 228 struct cis_tupleinfo **buff, int *nret) 229 { 230 *nret = 0; 231 *buff = NULL; 232 return ENXIO; 233 } 234 static void 235 null_cis_free(device_t dev, struct cis_tupleinfo *buff, int *nret) 236 { 237 return; 238 } 239}; 240 241 242METHOD int cis_read { 243 device_t dev; 244 device_t child; 245 u_int8_t id; 246 struct cis_tupleinfo **buff; 247 int *nret; 248} DEFAULT null_cis_read; 249 250METHOD int cis_free { 251 device_t dev; 252 struct cis_tupleinfo *buff; 253 int nret; 254} DEFAULT null_cis_free; 255 256 257