card_if.m revision 140692
1239310Sdim#- 2239310Sdim# Copyright (c) 1999 M. Warner Losh. 3239310Sdim# All rights reserved. 4239310Sdim# 5239310Sdim# Redistribution and use in source and binary forms, with or without 6239310Sdim# modification, are permitted provided that the following conditions 7239310Sdim# are met: 8239310Sdim# 1. Redistributions of source code must retain the above copyright 9239310Sdim# notice, this list of conditions and the following disclaimer. 10239310Sdim# 2. Redistributions in binary form must reproduce the above copyright 11239310Sdim# notice, this list of conditions and the following disclaimer in the 12239310Sdim# documentation and/or other materials provided with the distribution. 13239310Sdim# 14239310Sdim# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15249423Sdim# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16249423Sdim# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17249423Sdim# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18249423Sdim# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19249423Sdim# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20249423Sdim# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21249423Sdim# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22249423Sdim# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23249423Sdim# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24239310Sdim# SUCH DAMAGE. 25239310Sdim# 26239310Sdim# $FreeBSD: head/sys/dev/pccard/card_if.m 140692 2005-01-24 06:48:26Z imp $ 27239310Sdim# 28249423Sdim 29239310Sdim#include <sys/bus.h> 30239310Sdim#include <machine/bus.h> 31239310Sdim#include <dev/pccard/pccardvar.h> 32239310Sdim 33249423SdimINTERFACE card; 34249423Sdim 35249423Sdim# WARNING: THIS FILE IS USED BY BOTH OLDCARD AND NEWCARD. MAKE SURE 36249423Sdim# YOU TEST BOTH KERNELS IF CHANGING THIS FILE. 37239310Sdim 38239310Sdim# 39239310Sdim# Companion interface for pccard. We need to set attributes for memory 40239310Sdim# and i/o port mappings (as well as other types of attributes) that have 41239310Sdim# a well defined meaning inside the pccard/cardbus system. The bus 42239310Sdim# methods are inadequate for this because this must be done at the time the 43239310Sdim# resources are set for the device, which predates their activation. Also, 44239310Sdim# the driver activating the resources doesn't necessarily know or need to know 45239310Sdim# these attributes. 46239310Sdim# 47239310SdimMETHOD int set_res_flags { 48249423Sdim device_t dev; 49249423Sdim device_t child; 50239310Sdim int restype; 51239310Sdim int rid; 52239310Sdim u_long value; 53239310Sdim}; 54239310Sdim 55239310SdimMETHOD int get_res_flags { 56239310Sdim device_t dev; 57239310Sdim device_t child; 58239310Sdim int restype; 59239310Sdim int rid; 60239310Sdim u_long *value; 61239310Sdim}; 62239310Sdim 63239310Sdim# 64239310Sdim# Sets the memory offset of the pccard bridge's window into attribute 65239310Sdim# or common memory space. 66239310Sdim# 67239310SdimMETHOD int set_memory_offset { 68239310Sdim device_t dev; 69239310Sdim device_t child; 70239310Sdim int rid; 71239310Sdim uint32_t cardaddr; 72239310Sdim uint32_t *deltap; 73239310Sdim} 74239310Sdim 75239310SdimMETHOD int get_memory_offset { 76239310Sdim device_t dev; 77239310Sdim device_t child; 78239310Sdim int rid; 79239310Sdim uint32_t *offset; 80239310Sdim} 81239310Sdim 82239310Sdim# 83239310Sdim# pccard bridges call this method to initate the attachment of a card 84249423Sdim# 85239310SdimMETHOD int attach_card { 86239310Sdim device_t dev; 87249423Sdim} 88249423Sdim 89239310Sdim# 90239310Sdim# pccard bridges call this to detach a card. 91239310Sdim# 92239310SdimMETHOD int detach_card { 93239310Sdim device_t dev; 94239310Sdim} 95239310Sdim 96239310Sdim# 97239310Sdim# Returns the function number for this device. 98239310Sdim# 99239310SdimMETHOD int get_function { 100239310Sdim device_t dev; 101239310Sdim device_t child; 102239310Sdim int *func; 103239310Sdim} 104239310Sdim 105239310Sdim# 106239310Sdim# Activates (and powers up if necessary) the card's nth function 107243830Sdim# since each function gets its own device, there is no need to 108239310Sdim# to specify a function number 109239310Sdim# 110239310SdimMETHOD int activate_function { 111239310Sdim device_t dev; 112239310Sdim device_t child; 113239310Sdim} 114239310Sdim 115239310SdimMETHOD int deactivate_function { 116239310Sdim device_t dev; 117249423Sdim device_t child; 118249423Sdim} 119239310Sdim 120249423Sdim# 121249423Sdim# Compatibility methods for OLDCARD drivers. We use these routines to make 122239310Sdim# it possible to call the OLDCARD driver's probe routine in the context that 123249423Sdim# it expects. For OLDCARD these are implemented as pass throughs to the 124249423Sdim# device_{probe,attach} routines. For NEWCARD they are implemented such 125239310Sdim# such that probe becomes strictly a matching routine and attach does both 126239310Sdim# the old probe and old attach. 127249423Sdim# 128239310Sdim# compat devices should use the following: 129249423Sdim# 130239310Sdim# /* Device interface */ 131239310Sdim# DEVMETHOD(device_probe), pccard_compat_probe), 132249423Sdim# DEVMETHOD(device_attach), pccard_compat_attach), 133239310Sdim# /* Card interface */ 134239310Sdim# DEVMETHOD(card_compat_match, foo_match), /* newly written */ 135239310Sdim# DEVMETHOD(card_compat_probe, foo_probe), /* old probe */ 136249423Sdim# DEVMETHOD(card_compat_attach, foo_attach), /* old attach */ 137239310Sdim# 138239310Sdim# This will allow a single driver binary image to be used for both 139239310Sdim# OLDCARD and NEWCARD. 140239310Sdim# 141239310Sdim# Drivers wishing to not retain OLDCARD compatibility needn't do this. 142239310Sdim# 143239310Sdim# The compat_do_* versions are so that we can make the pccard_compat_probe 144249423Sdim# and _attach static lines and have the bus system pick the right version 145239310Sdim# to use so we don't enshrine pccard_* symbols in the driver's module. 146249423Sdim# 147239310SdimMETHOD int compat_probe { 148239310Sdim device_t dev; 149239310Sdim} 150239310Sdim 151239310SdimMETHOD int compat_attach { 152239310Sdim device_t dev; 153239310Sdim} 154239310Sdim 155239310SdimCODE { 156239310Sdim static int null_do_probe(device_t bus, device_t dev) 157249423Sdim { 158249423Sdim return (CARD_COMPAT_DO_PROBE(device_get_parent(bus), dev)); 159249423Sdim } 160239310Sdim 161239310Sdim static int null_do_attach(device_t bus, device_t dev) 162239310Sdim { 163239310Sdim return (CARD_COMPAT_DO_ATTACH(device_get_parent(bus), dev)); 164239310Sdim } 165239310Sdim} 166239310Sdim 167239310SdimMETHOD int compat_do_probe { 168239310Sdim device_t bus; 169239310Sdim device_t dev; 170239310Sdim} DEFAULT null_do_probe; 171239310Sdim 172239310SdimMETHOD int compat_do_attach { 173239310Sdim device_t bus; 174239310Sdim device_t dev; 175239310Sdim} DEFAULT null_do_attach; 176239310Sdim 177239310Sdim# 178239310Sdim# Find "dev" in the passed table of devices. Return it or NULL. 179239310Sdim# 180239310SdimMETHOD struct pccard_product * do_product_lookup { 181239310Sdim device_t bus; 182239310Sdim device_t dev; 183239310Sdim const struct pccard_product *tab; 184239310Sdim size_t ent_size; 185239310Sdim pccard_product_match_fn matchfn; 186239310Sdim} 187239310Sdim 188239310Sdim# 189239310Sdim# Helper method for the above. When a compatibility driver is converted, 190239310Sdim# one must write a match routine. This routine is unused on OLDCARD but 191239310Sdim# is used as a discriminator for NEWCARD. 192239310Sdim# 193239310SdimMETHOD int compat_match { 194239310Sdim device_t dev; 195239310Sdim} 196239310Sdim