card_if.m revision 150098
1139749Simp#- 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 150098 2005-09-13 17:56:36Z imp $ 2753855Simp# 2853855Simp 2959272Simp#include <sys/bus.h> 30129798Simp#include <machine/bus.h> 3197613Stakawata#include <dev/pccard/pccardvar.h> 3259272Simp 3353855SimpINTERFACE card; 3453855Simp 3574636Simp# WARNING: THIS FILE IS USED BY BOTH OLDCARD AND NEWCARD. MAKE SURE 3674636Simp# YOU TEST BOTH KERNELS IF CHANGING THIS FILE. 3774636Simp 3853855Simp# 3953855Simp# Companion interface for pccard. We need to set attributes for memory 4053855Simp# and i/o port mappings (as well as other types of attributes) that have 4153855Simp# a well defined meaning inside the pccard/cardbus system. The bus 4253855Simp# methods are inadequate for this because this must be done at the time the 4353855Simp# resources are set for the device, which predates their activation. Also, 4453855Simp# the driver activating the resources doesn't necessarily know or need to know 4553855Simp# these attributes. 4653855Simp# 4759193SimpMETHOD int set_res_flags { 4853855Simp device_t dev; 4953855Simp device_t child; 5059193Simp int restype; 5158581Simp int rid; 5259193Simp u_long value; 5353855Simp}; 5453855Simp 5559193SimpMETHOD int get_res_flags { 5653855Simp device_t dev; 5753855Simp device_t child; 5859193Simp int restype; 5953855Simp int rid; 6059193Simp u_long *value; 6153855Simp}; 6259193Simp 6361779Simp# 6461779Simp# Sets the memory offset of the pccard bridge's window into attribute 6561779Simp# or common memory space. 6661779Simp# 6759193SimpMETHOD int set_memory_offset { 6859193Simp device_t dev; 6959193Simp device_t child; 7082376Sjon int rid; 71140692Simp uint32_t cardaddr; 72140692Simp uint32_t *deltap; 7359193Simp} 7459193Simp 7564544SimpMETHOD int get_memory_offset { 7664544Simp device_t dev; 7764544Simp device_t child; 7882376Sjon int rid; 79140692Simp uint32_t *offset; 8064544Simp} 8164544Simp 8261779Simp# 8361779Simp# pccard bridges call this method to initate the attachment of a card 8461779Simp# 8559193SimpMETHOD int attach_card { 8659193Simp device_t dev; 8759193Simp} 8859193Simp 8961779Simp# 9061779Simp# pccard bridges call this to detach a card. 9161779Simp# 9259193SimpMETHOD int detach_card { 9359193Simp device_t dev; 9459193Simp} 9559193Simp 9661779Simp# 9766058Simp# Compatibility methods for OLDCARD drivers. We use these routines to make 9866058Simp# it possible to call the OLDCARD driver's probe routine in the context that 9966058Simp# it expects. For OLDCARD these are implemented as pass throughs to the 10066058Simp# device_{probe,attach} routines. For NEWCARD they are implemented such 10166058Simp# such that probe becomes strictly a matching routine and attach does both 10266058Simp# the old probe and old attach. 10366058Simp# 10466058Simp# compat devices should use the following: 10566058Simp# 10666058Simp# /* Device interface */ 10766058Simp# DEVMETHOD(device_probe), pccard_compat_probe), 10866058Simp# DEVMETHOD(device_attach), pccard_compat_attach), 10966058Simp# /* Card interface */ 11066058Simp# DEVMETHOD(card_compat_match, foo_match), /* newly written */ 11166058Simp# DEVMETHOD(card_compat_probe, foo_probe), /* old probe */ 11266058Simp# DEVMETHOD(card_compat_attach, foo_attach), /* old attach */ 11366058Simp# 11466058Simp# This will allow a single driver binary image to be used for both 11566058Simp# OLDCARD and NEWCARD. 11666058Simp# 11766058Simp# Drivers wishing to not retain OLDCARD compatibility needn't do this. 11866058Simp# 11974636Simp# The compat_do_* versions are so that we can make the pccard_compat_probe 12074636Simp# and _attach static lines and have the bus system pick the right version 12174636Simp# to use so we don't enshrine pccard_* symbols in the driver's module. 12274636Simp# 12366058SimpMETHOD int compat_probe { 12466058Simp device_t dev; 12566058Simp} 12666058Simp 12766058SimpMETHOD int compat_attach { 12866058Simp device_t dev; 12966058Simp} 13066058Simp 13174636SimpCODE { 13274636Simp static int null_do_probe(device_t bus, device_t dev) 13374636Simp { 13474636Simp return (CARD_COMPAT_DO_PROBE(device_get_parent(bus), dev)); 13574636Simp } 13674636Simp 13774636Simp static int null_do_attach(device_t bus, device_t dev) 13874636Simp { 13974636Simp return (CARD_COMPAT_DO_ATTACH(device_get_parent(bus), dev)); 14074636Simp } 14174636Simp} 14274636Simp 14374636SimpMETHOD int compat_do_probe { 14474636Simp device_t bus; 14574636Simp device_t dev; 146100218Simp} DEFAULT null_do_probe; 14774636Simp 14874636SimpMETHOD int compat_do_attach { 14974636Simp device_t bus; 15074636Simp device_t dev; 15174636Simp} DEFAULT null_do_attach; 15274636Simp 153100218Simp# 154100218Simp# Find "dev" in the passed table of devices. Return it or NULL. 155100218Simp# 15697613StakawataMETHOD struct pccard_product * do_product_lookup { 15797613Stakawata device_t bus; 15897613Stakawata device_t dev; 15997613Stakawata const struct pccard_product *tab; 16097613Stakawata size_t ent_size; 16197613Stakawata pccard_product_match_fn matchfn; 16297613Stakawata} 163100218Simp 16466058Simp# 16566058Simp# Helper method for the above. When a compatibility driver is converted, 16666058Simp# one must write a match routine. This routine is unused on OLDCARD but 16766058Simp# is used as a discriminator for NEWCARD. 16866058Simp# 16966058SimpMETHOD int compat_match { 17066058Simp device_t dev; 17166058Simp} 172147711Simp 173147711Simp# 174147711Simp# Scanning function for accessing the CIS of a card in its driver. 175147711Simp# 176147711SimpMETHOD int cis_scan { 177147711Simp device_t bus; 178150098Simp device_t dev; 179147711Simp pccard_scan_t fnp; 180147711Simp void *argp; 181147711Simp}; 182150098Simp 183150098Simp# 184150098Simp# Convenience function to read attribute memory. 185150098Simp# 186150098SimpMETHOD int attr_read { 187150098Simp device_t bus; 188150098Simp device_t dev; 189150098Simp uint32_t offset; 190150098Simp uint8_t *val; 191150098Simp} 192150098Simp 193150098Simp# 194150098Simp# Convenience function to write attribute memory. 195150098Simp# 196150098SimpMETHOD int attr_write { 197150098Simp device_t bus; 198150098Simp device_t dev; 199150098Simp uint32_t offset; 200150098Simp uint8_t val; 201150098Simp} 202150098Simp 203150098Simp# 204150098Simp# Read the CCR register 205150098Simp# 206150098SimpMETHOD int ccr_read { 207150098Simp device_t bus; 208150098Simp device_t dev; 209150098Simp uint32_t offset; 210150098Simp uint8_t *val; 211150098Simp} 212150098Simp 213150098Simp# 214150098Simp# Write the CCR register 215150098Simp# 216150098SimpMETHOD int ccr_write { 217150098Simp device_t bus; 218150098Simp device_t dev; 219150098Simp uint32_t offset; 220150098Simp uint8_t val; 221150098Simp} 222