card_if.m revision 100218
153855Simp# 253855Simp# Copyright (c) 1999 M. Warner Losh. 353855Simp# All rights reserved. 453855Simp# 553855Simp# Redistribution and use in source and binary forms, with or without 653855Simp# modification, are permitted provided that the following conditions 753855Simp# are met: 853855Simp# 1. Redistributions of source code must retain the above copyright 953855Simp# notice, this list of conditions and the following disclaimer. 1053855Simp# 2. Redistributions in binary form must reproduce the above copyright 1153855Simp# notice, this list of conditions and the following disclaimer in the 1253855Simp# documentation and/or other materials provided with the distribution. 1353855Simp# 1453855Simp# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1553855Simp# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1653855Simp# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1753855Simp# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1853855Simp# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1953855Simp# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2053855Simp# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2153855Simp# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2253855Simp# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2353855Simp# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2453855Simp# SUCH DAMAGE. 2553855Simp# 2653855Simp# $FreeBSD: head/sys/dev/pccard/card_if.m 100218 2002-07-17 05:20:43Z imp $ 2753855Simp# 2853855Simp 2959272Simp#include <sys/bus.h> 3097613Stakawata#include <dev/pccard/pccardvar.h> 3159272Simp 3253855SimpINTERFACE card; 3353855Simp 3474636Simp# WARNING: THIS FILE IS USED BY BOTH OLDCARD AND NEWCARD. MAKE SURE 3574636Simp# YOU TEST BOTH KERNELS IF CHANGING THIS FILE. 3674636Simp 3753855Simp# 3853855Simp# Companion interface for pccard. We need to set attributes for memory 3953855Simp# and i/o port mappings (as well as other types of attributes) that have 4053855Simp# a well defined meaning inside the pccard/cardbus system. The bus 4153855Simp# methods are inadequate for this because this must be done at the time the 4253855Simp# resources are set for the device, which predates their activation. Also, 4353855Simp# the driver activating the resources doesn't necessarily know or need to know 4453855Simp# these attributes. 4553855Simp# 4659193SimpMETHOD int set_res_flags { 4753855Simp device_t dev; 4853855Simp device_t child; 4959193Simp int restype; 5058581Simp int rid; 5159193Simp u_long value; 5253855Simp}; 5353855Simp 5459193SimpMETHOD int get_res_flags { 5553855Simp device_t dev; 5653855Simp device_t child; 5759193Simp int restype; 5853855Simp int rid; 5959193Simp u_long *value; 6053855Simp}; 6159193Simp 6261779Simp# 6361779Simp# Sets the memory offset of the pccard bridge's window into attribute 6461779Simp# or common memory space. 6561779Simp# 6659193SimpMETHOD int set_memory_offset { 6759193Simp device_t dev; 6859193Simp device_t child; 6982376Sjon int rid; 7082376Sjon u_int32_t cardaddr; 7182376Sjon u_int32_t *deltap; 7259193Simp} 7359193Simp 7464544SimpMETHOD int get_memory_offset { 7564544Simp device_t dev; 7664544Simp device_t child; 7782376Sjon int rid; 7882376Sjon u_int32_t *offset; 7964544Simp} 8064544Simp 8161779Simp# 8261779Simp# pccard bridges call this method to initate the attachment of a card 8361779Simp# 8459193SimpMETHOD int attach_card { 8559193Simp device_t dev; 8659193Simp} 8759193Simp 8861779Simp# 8961779Simp# pccard bridges call this to detach a card. 9061779Simp# 9159193SimpMETHOD int detach_card { 9259193Simp device_t dev; 9359193Simp int flags; 9459193Simp} 9559193Simp 9682378Sjon# 9782378Sjon# pccard/cardbus buses call this to request a reprobe of the bus. 9882378Sjon# reprobe only initiated if the child bus is the same type the card inserted. 9982378Sjon# 10082378SjonMETHOD int reprobe_card { 10182378Sjon device_t dev; 10282378Sjon device_t child; 10382378Sjon} 10482378Sjon 10569308SjonHEADER { 10669308Sjon #define DETACH_FORCE 0x01 10769308Sjon} 10869308Sjon 10961779Simp# 11061779Simp# Returns the type of card this is. Maybe we don't need this. 11161779Simp# 11259193SimpMETHOD int get_type { 11359193Simp device_t dev; 11459193Simp int *type; 11559193Simp} 11661779Simp 11761779Simp# 11861779Simp# Returns the function number for this device. 11961779Simp# 12061779SimpMETHOD int get_function { 12161779Simp device_t dev; 12261779Simp device_t child; 12361779Simp int *func; 12461779Simp} 12561779Simp 12661779Simp# 12761779Simp# Activates (and powers up if necessary) the card's nth function 12861779Simp# since each function gets its own device, there is no need to 12961779Simp# to specify a function number 13061779Simp# 13161779SimpMETHOD int activate_function { 13261779Simp device_t dev; 13361779Simp device_t child; 13461779Simp} 13561779Simp 13661779SimpMETHOD int deactivate_function { 13761779Simp device_t dev; 13861779Simp device_t child; 13961779Simp} 14066058Simp 14166058Simp# 14266058Simp# Compatibility methods for OLDCARD drivers. We use these routines to make 14366058Simp# it possible to call the OLDCARD driver's probe routine in the context that 14466058Simp# it expects. For OLDCARD these are implemented as pass throughs to the 14566058Simp# device_{probe,attach} routines. For NEWCARD they are implemented such 14666058Simp# such that probe becomes strictly a matching routine and attach does both 14766058Simp# the old probe and old attach. 14866058Simp# 14966058Simp# compat devices should use the following: 15066058Simp# 15166058Simp# /* Device interface */ 15266058Simp# DEVMETHOD(device_probe), pccard_compat_probe), 15366058Simp# DEVMETHOD(device_attach), pccard_compat_attach), 15466058Simp# /* Card interface */ 15566058Simp# DEVMETHOD(card_compat_match, foo_match), /* newly written */ 15666058Simp# DEVMETHOD(card_compat_probe, foo_probe), /* old probe */ 15766058Simp# DEVMETHOD(card_compat_attach, foo_attach), /* old attach */ 15866058Simp# 15966058Simp# This will allow a single driver binary image to be used for both 16066058Simp# OLDCARD and NEWCARD. 16166058Simp# 16266058Simp# Drivers wishing to not retain OLDCARD compatibility needn't do this. 16366058Simp# 16474636Simp# The compat_do_* versions are so that we can make the pccard_compat_probe 16574636Simp# and _attach static lines and have the bus system pick the right version 16674636Simp# to use so we don't enshrine pccard_* symbols in the driver's module. 16774636Simp# 16866058SimpMETHOD int compat_probe { 16966058Simp device_t dev; 17066058Simp} 17166058Simp 17266058SimpMETHOD int compat_attach { 17366058Simp device_t dev; 17466058Simp} 17566058Simp 17674636SimpCODE { 17774636Simp static int null_do_probe(device_t bus, device_t dev) 17874636Simp { 17974636Simp return (CARD_COMPAT_DO_PROBE(device_get_parent(bus), dev)); 18074636Simp } 18174636Simp 18274636Simp static int null_do_attach(device_t bus, device_t dev) 18374636Simp { 18474636Simp return (CARD_COMPAT_DO_ATTACH(device_get_parent(bus), dev)); 18574636Simp } 18674636Simp} 18774636Simp 18874636SimpMETHOD int compat_do_probe { 18974636Simp device_t bus; 19074636Simp device_t dev; 191100218Simp} DEFAULT null_do_probe; 19274636Simp 19374636SimpMETHOD int compat_do_attach { 19474636Simp device_t bus; 19574636Simp device_t dev; 19674636Simp} DEFAULT null_do_attach; 19774636Simp 198100218Simp# 199100218Simp# Find "dev" in the passed table of devices. Return it or NULL. 200100218Simp# 20197613StakawataMETHOD struct pccard_product * do_product_lookup { 20297613Stakawata device_t bus; 20397613Stakawata device_t dev; 20497613Stakawata const struct pccard_product *tab; 20597613Stakawata size_t ent_size; 20697613Stakawata pccard_product_match_fn matchfn; 20797613Stakawata} 208100218Simp 20966058Simp# 21066058Simp# Helper method for the above. When a compatibility driver is converted, 21166058Simp# one must write a match routine. This routine is unused on OLDCARD but 21266058Simp# is used as a discriminator for NEWCARD. 21366058Simp# 21466058SimpMETHOD int compat_match { 21566058Simp device_t dev; 21666058Simp} 21770715Sjon 21870715Sjon# 21970715Sjon# Method for devices to ask its CIS-enabled parent bus for CIS info. 22070715Sjon# Device driver requests all tuples if type 'id', the routine places 22170715Sjon# 'nret' number of tuples in 'buff'. Returns 0 if all tuples processed, 22270715Sjon# or an error code if processing was aborted. 22370715Sjon# Users of this method will be responsible for freeing the memory allocated 22470715Sjon# by calling the cis_free method. 22570715Sjon# 22670715Sjon 22770715SjonHEADER { 22870715Sjon struct cis_tupleinfo { 22970715Sjon u_int8_t id; 23070715Sjon int len; 23182376Sjon char *data; 23270715Sjon }; 23370715Sjon}; 23470715Sjon 23570715SjonCODE { 23670715Sjon static int 23770715Sjon null_cis_read(device_t dev, device_t child, u_int8_t id, 23882376Sjon struct cis_tupleinfo **buff, int *nret) 23970715Sjon { 24070715Sjon *nret = 0; 24170715Sjon *buff = NULL; 24270715Sjon return ENXIO; 24370715Sjon } 244100218Simp 24570715Sjon static void 24682376Sjon null_cis_free(device_t dev, struct cis_tupleinfo *buff, int *nret) 24770715Sjon { 24870715Sjon return; 24970715Sjon } 25070715Sjon}; 25170715Sjon 25270715SjonMETHOD int cis_read { 25370715Sjon device_t dev; 25470715Sjon device_t child; 25570715Sjon u_int8_t id; 25682376Sjon struct cis_tupleinfo **buff; 25782376Sjon int *nret; 25870715Sjon} DEFAULT null_cis_read; 25970715Sjon 26070715SjonMETHOD int cis_free { 26170715Sjon device_t dev; 26282376Sjon struct cis_tupleinfo *buff; 26382376Sjon int nret; 26470715Sjon} DEFAULT null_cis_free; 26570715Sjon 266