166200Simp/* $NetBSD: pcmcia.c,v 1.23 2000/07/28 19:17:02 drochner Exp $ */ 252506Simp 3139749Simp/*- 452506Simp * Copyright (c) 1997 Marc Horowitz. All rights reserved. 552506Simp * 652506Simp * Redistribution and use in source and binary forms, with or without 752506Simp * modification, are permitted provided that the following conditions 852506Simp * are met: 952506Simp * 1. Redistributions of source code must retain the above copyright 1052506Simp * notice, this list of conditions and the following disclaimer. 1152506Simp * 2. Redistributions in binary form must reproduce the above copyright 1252506Simp * notice, this list of conditions and the following disclaimer in the 1352506Simp * documentation and/or other materials provided with the distribution. 1452506Simp * 3. All advertising materials mentioning features or use of this software 1552506Simp * must display the following acknowledgement: 1652506Simp * This product includes software developed by Marc Horowitz. 1752506Simp * 4. The name of the author may not be used to endorse or promote products 1852506Simp * derived from this software without specific prior written permission. 1952506Simp * 2052506Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2152506Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2252506Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2352506Simp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2452506Simp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2552506Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2652506Simp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2752506Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2852506Simp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2952506Simp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3052506Simp */ 3152506Simp 32119418Sobrien#include <sys/cdefs.h> 33119418Sobrien__FBSDID("$FreeBSD: stable/11/sys/dev/pccard/pccard.c 315221 2017-03-14 02:06:03Z pfg $"); 34119418Sobrien 3552506Simp#include <sys/param.h> 3652506Simp#include <sys/systm.h> 3752506Simp#include <sys/malloc.h> 3852506Simp#include <sys/module.h> 3952506Simp#include <sys/kernel.h> 4052506Simp#include <sys/queue.h> 4191786Simp#include <sys/sysctl.h> 4252506Simp#include <sys/types.h> 4352506Simp 4452506Simp#include <sys/bus.h> 4552506Simp#include <machine/bus.h> 4652506Simp#include <sys/rman.h> 4752506Simp#include <machine/resource.h> 4852506Simp 4982781Sshiba#include <net/ethernet.h> 5082781Sshiba 5152506Simp#include <dev/pccard/pccardreg.h> 5252506Simp#include <dev/pccard/pccardvar.h> 53150362Simp#include <dev/pccard/pccardvarp.h> 54144930Simp#include <dev/pccard/pccard_cis.h> 5552506Simp 5655500Simp#include "power_if.h" 5759193Simp#include "card_if.h" 5855500Simp 5955500Simp#define PCCARDDEBUG 6055500Simp 6191786Simp/* sysctl vars */ 62227309Sedstatic SYSCTL_NODE(_hw, OID_AUTO, pccard, CTLFLAG_RD, 0, "PCCARD parameters"); 6391786Simp 6491786Simpint pccard_debug = 0; 65267992ShselaskySYSCTL_INT(_hw_pccard, OID_AUTO, debug, CTLFLAG_RWTUN, 6691786Simp &pccard_debug, 0, 6791786Simp "pccard debug"); 6891786Simp 6991786Simpint pccard_cis_debug = 0; 70267992ShselaskySYSCTL_INT(_hw_pccard, OID_AUTO, cis_debug, CTLFLAG_RWTUN, 7191786Simp &pccard_cis_debug, 0, "pccard CIS debug"); 7291786Simp 7352506Simp#ifdef PCCARDDEBUG 7452506Simp#define DPRINTF(arg) if (pccard_debug) printf arg 7555500Simp#define DEVPRINTF(arg) if (pccard_debug) device_printf arg 7667333Simp#define PRVERBOSE(arg) printf arg 7767333Simp#define DEVPRVERBOSE(arg) device_printf arg 7852506Simp#else 7952506Simp#define DPRINTF(arg) 8055500Simp#define DEVPRINTF(arg) 8167333Simp#define PRVERBOSE(arg) if (bootverbose) printf arg 8267333Simp#define DEVPRVERBOSE(arg) if (bootverbose) device_printf arg 8352506Simp#endif 8452506Simp 8582378Sjonstatic int pccard_ccr_read(struct pccard_function *pf, int ccr); 8682378Sjonstatic void pccard_ccr_write(struct pccard_function *pf, int ccr, int val); 8782378Sjonstatic int pccard_attach_card(device_t dev); 88106362Simpstatic int pccard_detach_card(device_t dev); 89181342Simpstatic void pccard_function_init(struct pccard_function *pf, int entry); 9082378Sjonstatic void pccard_function_free(struct pccard_function *pf); 9182378Sjonstatic int pccard_function_enable(struct pccard_function *pf); 9282378Sjonstatic void pccard_function_disable(struct pccard_function *pf); 9382378Sjonstatic int pccard_probe(device_t dev); 9482378Sjonstatic int pccard_attach(device_t dev); 9582378Sjonstatic int pccard_detach(device_t dev); 9682378Sjonstatic void pccard_print_resources(struct resource_list *rl, 9782378Sjon const char *name, int type, int count, const char *format); 9882378Sjonstatic int pccard_print_child(device_t dev, device_t child); 9982378Sjonstatic int pccard_set_resource(device_t dev, device_t child, int type, 100294883Sjhibbits int rid, rman_res_t start, rman_res_t count); 10182378Sjonstatic int pccard_get_resource(device_t dev, device_t child, int type, 102294883Sjhibbits int rid, rman_res_t *startp, rman_res_t *countp); 10382378Sjonstatic void pccard_delete_resource(device_t dev, device_t child, int type, 10482378Sjon int rid); 10582378Sjonstatic int pccard_set_res_flags(device_t dev, device_t child, int type, 106188179Simp int rid, u_long flags); 10782378Sjonstatic int pccard_set_memory_offset(device_t dev, device_t child, int rid, 108140692Simp uint32_t offset, uint32_t *deltap); 109181342Simpstatic int pccard_probe_and_attach_child(device_t dev, device_t child, 110181342Simp struct pccard_function *pf); 111104641Simpstatic void pccard_probe_nomatch(device_t cbdev, device_t child); 11282378Sjonstatic int pccard_read_ivar(device_t bus, device_t child, int which, 113188179Simp uintptr_t *result); 11482378Sjonstatic void pccard_driver_added(device_t dev, driver_t *driver); 11582378Sjonstatic struct resource *pccard_alloc_resource(device_t dev, 116294883Sjhibbits device_t child, int type, int *rid, rman_res_t start, 117294883Sjhibbits rman_res_t end, rman_res_t count, u_int flags); 11882378Sjonstatic int pccard_release_resource(device_t dev, device_t child, int type, 11982378Sjon int rid, struct resource *r); 12082378Sjonstatic void pccard_child_detached(device_t parent, device_t dev); 121170163Spisostatic int pccard_filter(void *arg); 122170163Spisostatic void pccard_intr(void *arg); 12382378Sjonstatic int pccard_setup_intr(device_t dev, device_t child, 124166901Spiso struct resource *irq, int flags, driver_filter_t *filt, 125166901Spiso driver_intr_t *intr, void *arg, void **cookiep); 12682378Sjonstatic int pccard_teardown_intr(device_t dev, device_t child, 12782378Sjon struct resource *r, void *cookie); 12852506Simp 12997613Stakawatastatic const struct pccard_product * 13097613Stakawatapccard_do_product_lookup(device_t bus, device_t dev, 13197613Stakawata const struct pccard_product *tab, size_t ent_size, 13297613Stakawata pccard_product_match_fn matchfn); 13397613Stakawata 13497613Stakawata 13582378Sjonstatic int 13674632Simppccard_ccr_read(struct pccard_function *pf, int ccr) 13752506Simp{ 13852506Simp return (bus_space_read_1(pf->pf_ccrt, pf->pf_ccrh, 13952506Simp pf->pf_ccr_offset + ccr)); 14052506Simp} 14152506Simp 14282378Sjonstatic void 14374632Simppccard_ccr_write(struct pccard_function *pf, int ccr, int val) 14452506Simp{ 14552506Simp if ((pf->ccr_mask) & (1 << (ccr / 2))) { 14652506Simp bus_space_write_1(pf->pf_ccrt, pf->pf_ccrh, 14752506Simp pf->pf_ccr_offset + ccr, val); 14852506Simp } 14952506Simp} 15052506Simp 15159193Simpstatic int 152113242Simppccard_set_default_descr(device_t dev) 153113242Simp{ 154121521Simp const char *vendorstr, *prodstr; 155133865Simp uint32_t vendor, prod; 156121521Simp char *str; 157113242Simp 158113242Simp if (pccard_get_vendor_str(dev, &vendorstr)) 159113242Simp return (0); 160113242Simp if (pccard_get_product_str(dev, &prodstr)) 161113242Simp return (0); 162133865Simp if (vendorstr != NULL && prodstr != NULL) { 163133865Simp str = malloc(strlen(vendorstr) + strlen(prodstr) + 2, M_DEVBUF, 164133865Simp M_WAITOK); 165133865Simp sprintf(str, "%s %s", vendorstr, prodstr); 166133865Simp device_set_desc_copy(dev, str); 167133865Simp free(str, M_DEVBUF); 168133865Simp } else { 169133865Simp if (pccard_get_vendor(dev, &vendor)) 170133865Simp return (0); 171133865Simp if (pccard_get_product(dev, &prod)) 172133865Simp return (0); 173133865Simp str = malloc(100, M_DEVBUF, M_WAITOK); 174188212Swkoszek snprintf(str, 100, "vendor=%#x product=%#x", vendor, prod); 175133865Simp device_set_desc_copy(dev, str); 176133865Simp free(str, M_DEVBUF); 177133865Simp } 178113242Simp return (0); 179113242Simp} 180113242Simp 181113242Simpstatic int 18259193Simppccard_attach_card(device_t dev) 18352506Simp{ 18464850Simp struct pccard_softc *sc = PCCARD_SOFTC(dev); 18552506Simp struct pccard_function *pf; 18665917Simp struct pccard_ivar *ivar; 18761788Simp device_t child; 188102713Simp int i; 18952506Simp 190153773Simp if (!STAILQ_EMPTY(&sc->card.pf_head)) { 191153773Simp if (bootverbose || pccard_debug) 192153773Simp device_printf(dev, "Card already inserted.\n"); 193153773Simp } 19452506Simp 19555500Simp DEVPRINTF((dev, "chip_socket_enable\n")); 19655500Simp POWER_ENABLE_SOCKET(device_get_parent(dev), dev); 19752506Simp 19855500Simp DEVPRINTF((dev, "read_cis\n")); 19952506Simp pccard_read_cis(sc); 20052506Simp 20155500Simp DEVPRINTF((dev, "check_cis_quirks\n")); 20252506Simp pccard_check_cis_quirks(dev); 20352506Simp 20452506Simp /* 20552506Simp * bail now if the card has no functions, or if there was an error in 20652506Simp * the cis. 20752506Simp */ 20852506Simp 20970715Sjon if (sc->card.error) { 210102713Simp device_printf(dev, "CARD ERROR!\n"); 21152506Simp return (1); 21270715Sjon } 21370715Sjon if (STAILQ_EMPTY(&sc->card.pf_head)) { 214102713Simp device_printf(dev, "Card has no functions!\n"); 21552506Simp return (1); 21670715Sjon } 21752506Simp 21890436Simp if (bootverbose || pccard_debug) 21952506Simp pccard_print_cis(dev); 22052506Simp 22155500Simp DEVPRINTF((dev, "functions scanning\n")); 222102713Simp i = -1; 22352506Simp STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 224102713Simp i++; 225102713Simp if (STAILQ_EMPTY(&pf->cfe_head)) { 226102713Simp device_printf(dev, 227102713Simp "Function %d has no config entries.!\n", i); 22852506Simp continue; 229102713Simp } 23052506Simp pf->sc = sc; 23152506Simp pf->cfe = NULL; 23264927Simp pf->dev = NULL; 23352506Simp } 234104641Simp DEVPRINTF((dev, "Card has %d functions. pccard_mfc is %d\n", i + 1, 235102713Simp pccard_mfc(sc))); 23682378Sjon 23752506Simp STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 23852506Simp if (STAILQ_EMPTY(&pf->cfe_head)) 23952506Simp continue; 24067897Sdwmalone ivar = malloc(sizeof(struct pccard_ivar), M_DEVBUF, 241111119Simp M_WAITOK | M_ZERO); 242143815Simp resource_list_init(&ivar->resources); 24361788Simp child = device_add_child(dev, NULL, -1); 24465917Simp device_set_ivars(child, ivar); 245147963Simp ivar->pf = pf; 24667187Simp pf->dev = child; 247181342Simp pccard_probe_and_attach_child(dev, child, pf); 24852506Simp } 24974632Simp return (0); 25052506Simp} 25152506Simp 25259193Simpstatic int 253181342Simppccard_probe_and_attach_child(device_t dev, device_t child, 254181342Simp struct pccard_function *pf) 255181342Simp{ 256181342Simp struct pccard_softc *sc = PCCARD_SOFTC(dev); 257181342Simp int error; 258181342Simp 259181342Simp /* 260181342Simp * In NetBSD, the drivers are responsible for activating each 261181342Simp * function of a card and selecting the config to use. In 262181342Simp * FreeBSD, all that's done automatically in the typical lazy 263181342Simp * way we do device resoruce allocation (except we pick the 264181342Simp * cfe up front). This is the biggest depature from the 265181395Simp * inherited NetBSD model, apart from the FreeBSD resource code. 266181342Simp * 267181342Simp * This seems to work well in practice for most cards. 268181342Simp * However, there are two cases that are problematic. If a 269181342Simp * driver wishes to pick and chose which config entry to use, 270181342Simp * then this method falls down. These are usually older 271181342Simp * cards. In addition, there are some cards that have 272181342Simp * multiple hardware units on the cards, but presents only one 273181342Simp * CIS chain. These cards are combination cards, but only one 274181342Simp * of these units can be on at a time. 275181342Simp * 276181342Simp * To overcome this limitation, while preserving the basic 277181342Simp * model, the probe routine can select a cfe and try to 278181342Simp * activate it. If that succeeds, then we'll keep track of 279181342Simp * and let that information persist until we attach the card. 280181342Simp * Probe routines that do this MUST return 0, and cannot 281181342Simp * participate in the bidding process for a device. This 282181342Simp * seems harsh until you realize that if a probe routine knows 283181342Simp * enough to override the cfe we pick, then chances are very 284181342Simp * very good that it is the only driver that could hope to 285181342Simp * cope with the card. Bidding is for generic drivers, and 286181342Simp * while some of them may also match, none of them will do 287181342Simp * configuration override. 288181342Simp */ 289181342Simp error = device_probe(child); 290181342Simp if (error != 0) 291181342Simp goto out; 292181342Simp pccard_function_init(pf, -1); 293181342Simp if (sc->sc_enabled_count == 0) 294181342Simp POWER_ENABLE_SOCKET(device_get_parent(dev), dev); 295181342Simp if (pccard_function_enable(pf) == 0 && 296181342Simp pccard_set_default_descr(child) == 0 && 297181342Simp device_attach(child) == 0) { 298188212Swkoszek DEVPRINTF((sc->dev, "function %d CCR at %d offset %#x " 299188212Swkoszek "mask %#x: %#x %#x %#x %#x, %#x %#x %#x %#x, %#x\n", 300181342Simp pf->number, pf->pf_ccr_window, pf->pf_ccr_offset, 301181342Simp pf->ccr_mask, pccard_ccr_read(pf, 0x00), 302181342Simp pccard_ccr_read(pf, 0x02), pccard_ccr_read(pf, 0x04), 303181342Simp pccard_ccr_read(pf, 0x06), pccard_ccr_read(pf, 0x0A), 304181342Simp pccard_ccr_read(pf, 0x0C), pccard_ccr_read(pf, 0x0E), 305181342Simp pccard_ccr_read(pf, 0x10), pccard_ccr_read(pf, 0x12))); 306181342Simp return (0); 307181342Simp } 308181342Simp error = ENXIO; 309181342Simpout:; 310181342Simp /* 311181342Simp * Probe may fail AND also try to select a cfe, if so, free 312181342Simp * it. This is how we do cfe override. Or the attach fails. 313181342Simp * Either way, we have to clean up. 314181342Simp */ 315181342Simp if (pf->cfe != NULL) 316181342Simp pccard_function_disable(pf); 317181342Simp pf->cfe = NULL; 318181342Simp pccard_function_free(pf); 319181342Simp return error; 320181342Simp} 321181342Simp 322181342Simpstatic int 323106362Simppccard_detach_card(device_t dev) 32452506Simp{ 32564850Simp struct pccard_softc *sc = PCCARD_SOFTC(dev); 32652506Simp struct pccard_function *pf; 32782378Sjon struct pccard_config_entry *cfe; 328166453Simp struct pccard_ivar *devi; 329119755Simp int state; 33052506Simp 33152506Simp /* 33252506Simp * We are running on either the PCCARD socket's event thread 33352506Simp * or in user context detaching a device by user request. 33452506Simp */ 33552506Simp STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 336119755Simp if (pf->dev == NULL) 337119755Simp continue; 338119755Simp state = device_get_state(pf->dev); 33982378Sjon if (state == DS_ATTACHED || state == DS_BUSY) 34082378Sjon device_detach(pf->dev); 34186907Simp if (pf->cfe != NULL) 34286907Simp pccard_function_disable(pf); 34382378Sjon pccard_function_free(pf); 344166453Simp devi = PCCARD_IVAR(pf->dev); 345106896Simp device_delete_child(dev, pf->dev); 346166453Simp free(devi, M_DEVBUF); 34752506Simp } 34882378Sjon if (sc->sc_enabled_count == 0) 34982378Sjon POWER_DISABLE_SOCKET(device_get_parent(dev), dev); 35082378Sjon 35182378Sjon while (NULL != (pf = STAILQ_FIRST(&sc->card.pf_head))) { 35282378Sjon while (NULL != (cfe = STAILQ_FIRST(&pf->cfe_head))) { 35382378Sjon STAILQ_REMOVE_HEAD(&pf->cfe_head, cfe_list); 35482378Sjon free(cfe, M_DEVBUF); 35582378Sjon } 35682378Sjon STAILQ_REMOVE_HEAD(&sc->card.pf_head, pf_list); 35782378Sjon free(pf, M_DEVBUF); 35882378Sjon } 359153773Simp STAILQ_INIT(&sc->card.pf_head); 36074632Simp return (0); 36152506Simp} 36252506Simp 36397613Stakawatastatic const struct pccard_product * 36497613Stakawatapccard_do_product_lookup(device_t bus, device_t dev, 365112359Simp const struct pccard_product *tab, size_t ent_size, 366112359Simp pccard_product_match_fn matchfn) 36766200Simp{ 36866200Simp const struct pccard_product *ent; 36966200Simp int matches; 370140692Simp uint32_t vendor; 371140692Simp uint32_t prod; 372121521Simp const char *vendorstr; 373121521Simp const char *prodstr; 374140366Simp const char *cis3str; 375140366Simp const char *cis4str; 37666200Simp 37766200Simp#ifdef DIAGNOSTIC 37866200Simp if (sizeof *ent > ent_size) 379112359Simp panic("pccard_product_lookup: bogus ent_size %jd", 380112359Simp (intmax_t) ent_size); 38166200Simp#endif 38266200Simp if (pccard_get_vendor(dev, &vendor)) 38366200Simp return (NULL); 38466200Simp if (pccard_get_product(dev, &prod)) 38566200Simp return (NULL); 38666200Simp if (pccard_get_vendor_str(dev, &vendorstr)) 38766200Simp return (NULL); 38866200Simp if (pccard_get_product_str(dev, &prodstr)) 38966200Simp return (NULL); 390140366Simp if (pccard_get_cis3_str(dev, &cis3str)) 391140366Simp return (NULL); 392140366Simp if (pccard_get_cis4_str(dev, &cis4str)) 393140366Simp return (NULL); 394113313Simp for (ent = tab; ent->pp_vendor != 0; ent = 39582378Sjon (const struct pccard_product *) ((const char *) ent + ent_size)) { 39666200Simp matches = 1; 39786642Simp if (ent->pp_vendor == PCCARD_VENDOR_ANY && 398113078Ssanpei ent->pp_product == PCCARD_PRODUCT_ANY && 39986642Simp ent->pp_cis[0] == NULL && 40086642Simp ent->pp_cis[1] == NULL) { 401113300Simp if (ent->pp_name) 402113300Simp device_printf(dev, 403113300Simp "Total wildcard entry ignored for %s\n", 404113300Simp ent->pp_name); 40586642Simp continue; 40686642Simp } 40766200Simp if (matches && ent->pp_vendor != PCCARD_VENDOR_ANY && 40866200Simp vendor != ent->pp_vendor) 40966200Simp matches = 0; 41066200Simp if (matches && ent->pp_product != PCCARD_PRODUCT_ANY && 41166200Simp prod != ent->pp_product) 41266200Simp matches = 0; 41371322Simp if (matches && ent->pp_cis[0] && 414133865Simp (vendorstr == NULL || 415133865Simp strcmp(ent->pp_cis[0], vendorstr) != 0)) 41666200Simp matches = 0; 41771322Simp if (matches && ent->pp_cis[1] && 418133865Simp (prodstr == NULL || 419133865Simp strcmp(ent->pp_cis[1], prodstr) != 0)) 42066200Simp matches = 0; 421140366Simp if (matches && ent->pp_cis[2] && 422140366Simp (cis3str == NULL || 423140366Simp strcmp(ent->pp_cis[2], cis3str) != 0)) 424140366Simp matches = 0; 425140366Simp if (matches && ent->pp_cis[3] && 426140366Simp (cis4str == NULL || 427140366Simp strcmp(ent->pp_cis[3], cis4str) != 0)) 428140366Simp matches = 0; 42966200Simp if (matchfn != NULL) 43066200Simp matches = (*matchfn)(dev, ent, matches); 43166200Simp if (matches) 43266200Simp return (ent); 43366200Simp } 43466200Simp return (NULL); 43566200Simp} 43666200Simp 437181342Simp/** 438181342Simp * @brief pccard_select_cfe 439181342Simp * 440181342Simp * Select a cfe entry to use. Should be called from the pccard's probe 441181342Simp * routine after it knows for sure that it wants this card. 442181342Simp * 443181342Simp * XXX I think we need to make this symbol be static, ala the kobj stuff 444181342Simp * we do for everything else. This is a quick hack. 445181342Simp */ 446181342Simpint 447181342Simppccard_select_cfe(device_t dev, int entry) 448181342Simp{ 449181342Simp struct pccard_ivar *devi = PCCARD_IVAR(dev); 450181342Simp struct pccard_function *pf = devi->pf; 451181342Simp 452181342Simp pccard_function_init(pf, entry); 453181342Simp return (pf->cfe ? 0 : ENOMEM); 454181342Simp} 455181342Simp 45652506Simp/* 45752506Simp * Initialize a PCCARD function. May be called as long as the function is 45852506Simp * disabled. 45982382Simp * 46082382Simp * Note: pccard_function_init should not keep resources allocated. It should 46182382Simp * only set them up ala isa pnp, set the values in the rl lists, and return. 46282382Simp * Any resource held after pccard_function_init is called is a bug. However, 46382382Simp * the bus routines to get the resources also assume that pccard_function_init 46482382Simp * does this, so they need to be fixed too. 46552506Simp */ 46682378Sjonstatic void 467181342Simppccard_function_init(struct pccard_function *pf, int entry) 46852506Simp{ 46965917Simp struct pccard_config_entry *cfe; 47067242Simp struct pccard_ivar *devi = PCCARD_IVAR(pf->dev); 47167242Simp struct resource_list *rl = &devi->resources; 47270762Simp struct resource_list_entry *rle; 473315221Spfg struct resource *r = NULL; 474237692Simp struct pccard_ce_iospace *ios; 475237692Simp struct pccard_ce_memspace *mems; 47667242Simp device_t bus; 477294883Sjhibbits rman_res_t start, end, len; 478144955Simp int i, rid, spaces; 47965917Simp 48070715Sjon if (pf->pf_flags & PFF_ENABLED) { 48170715Sjon printf("pccard_function_init: function is enabled"); 48270715Sjon return; 48370715Sjon } 484181342Simp 485181342Simp /* 486181342Simp * Driver probe routine requested a specific entry already 487181342Simp * that succeeded. 488181342Simp */ 489181342Simp if (pf->cfe != NULL) 490181342Simp return; 491181342Simp 492181342Simp /* 493181342Simp * walk the list of configuration entries until we find one that 494181342Simp * we can allocate all the resources to. 495181342Simp */ 49667242Simp bus = device_get_parent(pf->dev); 49772012Sphk STAILQ_FOREACH(cfe, &pf->cfe_head, cfe_list) { 498144930Simp if (cfe->iftype != PCCARD_IFTYPE_IO) 499144930Simp continue; 500181342Simp if (entry != -1 && cfe->number != entry) 501181342Simp continue; 50290897Simp spaces = 0; 50367187Simp for (i = 0; i < cfe->num_iospace; i++) { 504237692Simp ios = cfe->iospace + i; 505237692Simp start = ios->start; 50667424Simp if (start) 507237692Simp end = start + ios->length - 1; 50867424Simp else 509296336Sjhibbits end = ~0; 510297000Sjhibbits DEVPRINTF((bus, "I/O rid %d start %#jx end %#jx\n", 51190897Simp i, start, end)); 512144930Simp rid = i; 513237692Simp len = ios->length; 514144955Simp r = bus_alloc_resource(bus, SYS_RES_IOPORT, &rid, 515144955Simp start, end, len, rman_make_alignment_flags(len)); 516237692Simp if (r == NULL) { 517237692Simp DEVPRINTF((bus, "I/O rid %d failed\n", i)); 51867187Simp goto not_this_one; 519237692Simp } 520144927Simp rle = resource_list_add(rl, SYS_RES_IOPORT, 521237692Simp rid, rman_get_start(r), rman_get_end(r), len); 522144927Simp if (rle == NULL) 523144930Simp panic("Cannot add resource rid %d IOPORT", rid); 52476424Simp rle->res = r; 52590897Simp spaces++; 52667187Simp } 527144930Simp for (i = 0; i < cfe->num_memspace; i++) { 528237692Simp mems = cfe->memspace + i; 529237692Simp start = mems->cardaddr + mems->hostaddr; 530144930Simp if (start) 531237692Simp end = start + mems->length - 1; 532144930Simp else 533296336Sjhibbits end = ~0; 534297000Sjhibbits DEVPRINTF((bus, "Memory rid %d start %#jx end %#jx\ncardaddr %#jx hostaddr %#jx length %#jx\n", 535237692Simp i, start, end, mems->cardaddr, mems->hostaddr, 536237692Simp mems->length)); 537144930Simp rid = i; 538237692Simp len = mems->length; 539144955Simp r = bus_alloc_resource(bus, SYS_RES_MEMORY, &rid, 540144955Simp start, end, len, rman_make_alignment_flags(len)); 541237692Simp if (r == NULL) { 542237692Simp DEVPRINTF((bus, "Memory rid %d failed\n", i)); 543237692Simp// goto not_this_one; 544237692Simp continue; 545237692Simp } 546144930Simp rle = resource_list_add(rl, SYS_RES_MEMORY, 547237692Simp rid, rman_get_start(r), rman_get_end(r), len); 548144930Simp if (rle == NULL) 549144930Simp panic("Cannot add resource rid %d MEM", rid); 550144930Simp rle->res = r; 551144930Simp spaces++; 55267187Simp } 55390897Simp if (spaces == 0) { 554140488Simp DEVPRINTF((bus, "Neither memory nor I/O mapped\n")); 55590897Simp goto not_this_one; 55690897Simp } 55767187Simp if (cfe->irqmask) { 558144930Simp rid = 0; 559144955Simp r = bus_alloc_resource_any(bus, SYS_RES_IRQ, &rid, 560144955Simp RF_SHAREABLE); 561237692Simp if (r == NULL) { 562237692Simp DEVPRINTF((bus, "IRQ rid %d failed\n", rid)); 56367187Simp goto not_this_one; 564237692Simp } 565144930Simp rle = resource_list_add(rl, SYS_RES_IRQ, rid, 56667242Simp rman_get_start(r), rman_get_end(r), 1); 567144927Simp if (rle == NULL) 568144930Simp panic("Cannot add resource rid %d IRQ", rid); 56976424Simp rle->res = r; 57067187Simp } 57167187Simp /* If we get to here, we've allocated all we need */ 57267167Simp pf->cfe = cfe; 57367187Simp break; 57467187Simp not_this_one:; 57567424Simp DEVPRVERBOSE((bus, "Allocation failed for cfe %d\n", 57667424Simp cfe->number)); 577144955Simp resource_list_purge(rl); 57867167Simp } 57952506Simp} 58052506Simp 58182378Sjon/* 58282378Sjon * Free resources allocated by pccard_function_init(), May be called as long 58382378Sjon * as the function is disabled. 58482382Simp * 58582382Simp * NOTE: This function should be unnecessary. pccard_function_init should 58682382Simp * never keep resources initialized. 58782378Sjon */ 58882378Sjonstatic void 58982378Sjonpccard_function_free(struct pccard_function *pf) 59082378Sjon{ 59182378Sjon struct pccard_ivar *devi = PCCARD_IVAR(pf->dev); 59282378Sjon struct resource_list_entry *rle; 59382378Sjon 59482378Sjon if (pf->pf_flags & PFF_ENABLED) { 595181342Simp printf("pccard_function_free: function is enabled"); 59682378Sjon return; 59782378Sjon } 59882378Sjon 599143785Simp STAILQ_FOREACH(rle, &devi->resources, link) { 60082378Sjon if (rle->res) { 601113242Simp if (rman_get_device(rle->res) != pf->sc->dev) 60282378Sjon device_printf(pf->sc->dev, 60382378Sjon "function_free: Resource still owned by " 60482378Sjon "child, oops. " 605297000Sjhibbits "(type=%d, rid=%d, addr=%#jx)\n", 60682378Sjon rle->type, rle->rid, 60782378Sjon rman_get_start(rle->res)); 60882378Sjon BUS_RELEASE_RESOURCE(device_get_parent(pf->sc->dev), 609113242Simp pf->sc->dev, rle->type, rle->rid, rle->res); 61082378Sjon rle->res = NULL; 61182378Sjon } 61282378Sjon } 61382378Sjon resource_list_free(&devi->resources); 61482378Sjon} 61582378Sjon 616121905Simpstatic void 617294883Sjhibbitspccard_mfc_adjust_iobase(struct pccard_function *pf, rman_res_t addr, 618294883Sjhibbits rman_res_t offset, rman_res_t size) 619121905Simp{ 620121958Simp bus_size_t iosize, tmp; 621121905Simp 622121905Simp if (addr != 0) { 623121905Simp if (pf->pf_mfc_iomax == 0) { 624121905Simp pf->pf_mfc_iobase = addr + offset; 625121905Simp pf->pf_mfc_iomax = pf->pf_mfc_iobase + size; 626121905Simp } else { 627121905Simp /* this makes the assumption that nothing overlaps */ 628121905Simp if (pf->pf_mfc_iobase > addr + offset) 629121905Simp pf->pf_mfc_iobase = addr + offset; 630121905Simp if (pf->pf_mfc_iomax < addr + offset + size) 631121905Simp pf->pf_mfc_iomax = addr + offset + size; 632121905Simp } 633121905Simp } 634121905Simp 635121905Simp tmp = pf->pf_mfc_iomax - pf->pf_mfc_iobase; 636121905Simp /* round up to nearest (2^n)-1 */ 637121905Simp for (iosize = 1; iosize < tmp; iosize <<= 1) 638121905Simp ; 639121905Simp iosize--; 640121905Simp 641122032Simp DEVPRINTF((pf->dev, "MFC: I/O base %#jx IOSIZE %#jx\n", 642122032Simp (uintmax_t)pf->pf_mfc_iobase, (uintmax_t)(iosize + 1))); 643121905Simp pccard_ccr_write(pf, PCCARD_CCR_IOBASE0, 644121905Simp pf->pf_mfc_iobase & 0xff); 645121905Simp pccard_ccr_write(pf, PCCARD_CCR_IOBASE1, 646121905Simp (pf->pf_mfc_iobase >> 8) & 0xff); 647121905Simp pccard_ccr_write(pf, PCCARD_CCR_IOBASE2, 0); 648121905Simp pccard_ccr_write(pf, PCCARD_CCR_IOBASE3, 0); 649121905Simp pccard_ccr_write(pf, PCCARD_CCR_IOSIZE, iosize); 650121905Simp} 651121905Simp 65252506Simp/* Enable a PCCARD function */ 65382378Sjonstatic int 65455720Simppccard_function_enable(struct pccard_function *pf) 65552506Simp{ 65652506Simp struct pccard_function *tmp; 65752506Simp int reg; 65855720Simp device_t dev = pf->sc->dev; 65970746Simp 66067333Simp if (pf->cfe == NULL) { 66167333Simp DEVPRVERBOSE((dev, "No config entry could be allocated.\n")); 66274632Simp return (ENOMEM); 66367333Simp } 66452506Simp 665181392Simp if (pf->pf_flags & PFF_ENABLED) 666181392Simp return (0); 66782378Sjon pf->sc->sc_enabled_count++; 66852506Simp 66952506Simp /* 67052506Simp * it's possible for different functions' CCRs to be in the same 67152506Simp * underlying page. Check for that. 67252506Simp */ 67352506Simp STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) { 67452506Simp if ((tmp->pf_flags & PFF_ENABLED) && 67552506Simp (pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) && 67652506Simp ((pf->ccr_base + PCCARD_CCR_SIZE) <= 67782378Sjon (tmp->ccr_base - tmp->pf_ccr_offset + 67882378Sjon tmp->pf_ccr_realsize))) { 67952506Simp pf->pf_ccrt = tmp->pf_ccrt; 68052506Simp pf->pf_ccrh = tmp->pf_ccrh; 68152506Simp pf->pf_ccr_realsize = tmp->pf_ccr_realsize; 68252506Simp 68352506Simp /* 68452506Simp * pf->pf_ccr_offset = (tmp->pf_ccr_offset - 68552506Simp * tmp->ccr_base) + pf->ccr_base; 68652506Simp */ 68770715Sjon /* pf->pf_ccr_offset = 68852506Simp (tmp->pf_ccr_offset + pf->ccr_base) - 68970715Sjon tmp->ccr_base; */ 69052506Simp pf->pf_ccr_window = tmp->pf_ccr_window; 69152506Simp break; 69252506Simp } 69352506Simp } 69452506Simp if (tmp == NULL) { 69555720Simp pf->ccr_rid = 0; 696296137Sjhibbits pf->ccr_res = bus_alloc_resource_anywhere(dev, SYS_RES_MEMORY, 697296137Sjhibbits &pf->ccr_rid, PCCARD_MEM_PAGE_SIZE, RF_ACTIVE); 69870715Sjon if (!pf->ccr_res) 69952506Simp goto bad; 700297000Sjhibbits DEVPRINTF((dev, "ccr_res == %#jx-%#jx, base=%#x\n", 70170746Simp rman_get_start(pf->ccr_res), rman_get_end(pf->ccr_res), 70270746Simp pf->ccr_base)); 70361788Simp CARD_SET_RES_FLAGS(device_get_parent(dev), dev, SYS_RES_MEMORY, 70461788Simp pf->ccr_rid, PCCARD_A_MEM_ATTR); 70570715Sjon CARD_SET_MEMORY_OFFSET(device_get_parent(dev), dev, 70670748Simp pf->ccr_rid, pf->ccr_base, &pf->pf_ccr_offset); 70755720Simp pf->pf_ccrt = rman_get_bustag(pf->ccr_res); 70855720Simp pf->pf_ccrh = rman_get_bushandle(pf->ccr_res); 70955720Simp pf->pf_ccr_realsize = 1; 71052506Simp } 71152506Simp 71252506Simp reg = (pf->cfe->number & PCCARD_CCR_OPTION_CFINDEX); 71352506Simp reg |= PCCARD_CCR_OPTION_LEVIREQ; 71452506Simp if (pccard_mfc(pf->sc)) { 71552506Simp reg |= (PCCARD_CCR_OPTION_FUNC_ENABLE | 71652506Simp PCCARD_CCR_OPTION_ADDR_DECODE); 71782383Simp /* PCCARD_CCR_OPTION_IRQ_ENABLE set elsewhere as needed */ 71852506Simp } 71952506Simp pccard_ccr_write(pf, PCCARD_CCR_OPTION, reg); 72052506Simp 72152506Simp reg = 0; 72252506Simp if ((pf->cfe->flags & PCCARD_CFE_IO16) == 0) 72352506Simp reg |= PCCARD_CCR_STATUS_IOIS8; 72452506Simp if (pf->cfe->flags & PCCARD_CFE_AUDIO) 72552506Simp reg |= PCCARD_CCR_STATUS_AUDIO; 72652506Simp pccard_ccr_write(pf, PCCARD_CCR_STATUS, reg); 72752506Simp 72852506Simp pccard_ccr_write(pf, PCCARD_CCR_SOCKETCOPY, 0); 72952506Simp 730121905Simp if (pccard_mfc(pf->sc)) 731121905Simp pccard_mfc_adjust_iobase(pf, 0, 0, 0); 73252506Simp 73352506Simp#ifdef PCCARDDEBUG 73452506Simp if (pccard_debug) { 73552506Simp STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) { 73670715Sjon device_printf(tmp->sc->dev, 737188212Swkoszek "function %d CCR at %d offset %#x: " 738188212Swkoszek "%#x %#x %#x %#x, %#x %#x %#x %#x, %#x\n", 73970715Sjon tmp->number, tmp->pf_ccr_window, 74055500Simp tmp->pf_ccr_offset, 74155500Simp pccard_ccr_read(tmp, 0x00), 74255500Simp pccard_ccr_read(tmp, 0x02), 74355500Simp pccard_ccr_read(tmp, 0x04), 74455500Simp pccard_ccr_read(tmp, 0x06), 74555500Simp pccard_ccr_read(tmp, 0x0A), 74670715Sjon pccard_ccr_read(tmp, 0x0C), 74755500Simp pccard_ccr_read(tmp, 0x0E), 74855500Simp pccard_ccr_read(tmp, 0x10), 74955500Simp pccard_ccr_read(tmp, 0x12)); 75052506Simp } 75152506Simp } 75252506Simp#endif 75352506Simp pf->pf_flags |= PFF_ENABLED; 75452506Simp return (0); 75552506Simp 75652506Simp bad: 75752506Simp /* 75852506Simp * Decrement the reference count, and power down the socket, if 75952506Simp * necessary. 76052506Simp */ 76182378Sjon pf->sc->sc_enabled_count--; 76265098Simp DEVPRINTF((dev, "bad --enabled_count = %d\n", pf->sc->sc_enabled_count)); 76352506Simp 76452506Simp return (1); 76552506Simp} 76652506Simp 76752506Simp/* Disable PCCARD function. */ 76882378Sjonstatic void 76955720Simppccard_function_disable(struct pccard_function *pf) 77052506Simp{ 77152506Simp struct pccard_function *tmp; 77255720Simp device_t dev = pf->sc->dev; 77352506Simp 77452506Simp if (pf->cfe == NULL) 77561788Simp panic("pccard_function_disable: function not initialized"); 77652506Simp 777181392Simp if ((pf->pf_flags & PFF_ENABLED) == 0) 77852506Simp return; 77970715Sjon if (pf->intr_handler != NULL) { 78082378Sjon struct pccard_ivar *devi = PCCARD_IVAR(pf->dev); 78182378Sjon struct resource_list_entry *rle = 78282378Sjon resource_list_find(&devi->resources, SYS_RES_IRQ, 0); 783144927Simp if (rle == NULL) 784144927Simp panic("Can't disable an interrupt with no IRQ res\n"); 78582378Sjon BUS_TEARDOWN_INTR(dev, pf->dev, rle->res, 78682378Sjon pf->intr_handler_cookie); 78770715Sjon } 78870715Sjon 78952506Simp /* 79052506Simp * it's possible for different functions' CCRs to be in the same 79152506Simp * underlying page. Check for that. Note we mark us as disabled 79252506Simp * first to avoid matching ourself. 79352506Simp */ 79452506Simp 79552506Simp pf->pf_flags &= ~PFF_ENABLED; 79652506Simp STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) { 79752506Simp if ((tmp->pf_flags & PFF_ENABLED) && 79852506Simp (pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) && 79952506Simp ((pf->ccr_base + PCCARD_CCR_SIZE) <= 80082378Sjon (tmp->ccr_base - tmp->pf_ccr_offset + 80182378Sjon tmp->pf_ccr_realsize))) 80252506Simp break; 80352506Simp } 80452506Simp 80552506Simp /* Not used by anyone else; unmap the CCR. */ 80652506Simp if (tmp == NULL) { 80770715Sjon bus_release_resource(dev, SYS_RES_MEMORY, pf->ccr_rid, 80855720Simp pf->ccr_res); 80955720Simp pf->ccr_res = NULL; 81052506Simp } 81152506Simp 81252506Simp /* 81352506Simp * Decrement the reference count, and power down the socket, if 81452506Simp * necessary. 81552506Simp */ 81682378Sjon pf->sc->sc_enabled_count--; 81752506Simp} 81852506Simp 81953873Simp#define PCCARD_NPORT 2 82053873Simp#define PCCARD_NMEM 5 82153873Simp#define PCCARD_NIRQ 1 82253873Simp#define PCCARD_NDRQ 0 82353873Simp 82452506Simpstatic int 82552506Simppccard_probe(device_t dev) 82652506Simp{ 82767333Simp device_set_desc(dev, "16-bit PCCard bus"); 828150391Simp return (0); 82952506Simp} 83052506Simp 83159193Simpstatic int 83259193Simppccard_attach(device_t dev) 83359193Simp{ 83464850Simp struct pccard_softc *sc = PCCARD_SOFTC(dev); 835150362Simp int err; 83661788Simp 83759193Simp sc->dev = dev; 83861788Simp sc->sc_enabled_count = 0; 839150362Simp if ((err = pccard_device_create(sc)) != 0) 840150362Simp return (err); 841153773Simp STAILQ_INIT(&sc->card.pf_head); 84274632Simp return (bus_generic_attach(dev)); 84359193Simp} 84459193Simp 84582378Sjonstatic int 84682378Sjonpccard_detach(device_t dev) 84782378Sjon{ 848106362Simp pccard_detach_card(dev); 849150362Simp pccard_device_destroy(device_get_softc(dev)); 850150362Simp return (0); 85182378Sjon} 85282378Sjon 85387975Simpstatic int 85487975Simppccard_suspend(device_t self) 85587975Simp{ 856106362Simp pccard_detach_card(self); 85787975Simp return (0); 85887975Simp} 85987975Simp 86087975Simpstatic 86187975Simpint 86287975Simppccard_resume(device_t self) 86387975Simp{ 86487975Simp return (0); 86587975Simp} 86687975Simp 86753873Simpstatic void 86853873Simppccard_print_resources(struct resource_list *rl, const char *name, int type, 86953873Simp int count, const char *format) 87053873Simp{ 87153873Simp struct resource_list_entry *rle; 87253873Simp int printed; 87353873Simp int i; 87453873Simp 87553873Simp printed = 0; 87653873Simp for (i = 0; i < count; i++) { 87753873Simp rle = resource_list_find(rl, type, i); 87876424Simp if (rle != NULL) { 87953873Simp if (printed == 0) 88053873Simp printf(" %s ", name); 88153873Simp else if (printed > 0) 88253873Simp printf(","); 88353873Simp printed++; 88453873Simp printf(format, rle->start); 88553873Simp if (rle->count > 1) { 88653873Simp printf("-"); 88753873Simp printf(format, rle->start + rle->count - 1); 88853873Simp } 88953873Simp } else if (i > 3) { 89053873Simp /* check the first few regardless */ 89153873Simp break; 89253873Simp } 89353873Simp } 89453873Simp} 89553873Simp 89653873Simpstatic int 89753873Simppccard_print_child(device_t dev, device_t child) 89853873Simp{ 89966847Simp struct pccard_ivar *devi = PCCARD_IVAR(child); 90053873Simp struct resource_list *rl = &devi->resources; 90153873Simp int retval = 0; 90253873Simp 90353873Simp retval += bus_print_child_header(dev, child); 90453873Simp retval += printf(" at"); 90553873Simp 90676424Simp if (devi != NULL) { 90753873Simp pccard_print_resources(rl, "port", SYS_RES_IOPORT, 90853873Simp PCCARD_NPORT, "%#lx"); 90953873Simp pccard_print_resources(rl, "iomem", SYS_RES_MEMORY, 91053873Simp PCCARD_NMEM, "%#lx"); 91153873Simp pccard_print_resources(rl, "irq", SYS_RES_IRQ, PCCARD_NIRQ, 91253873Simp "%ld"); 91370715Sjon pccard_print_resources(rl, "drq", SYS_RES_DRQ, PCCARD_NDRQ, 91453873Simp "%ld"); 915147963Simp retval += printf(" function %d config %d", devi->pf->number, 916147963Simp devi->pf->cfe->number); 91753873Simp } 91853873Simp 91953873Simp retval += bus_print_child_footer(dev, child); 92053873Simp 92153873Simp return (retval); 92253873Simp} 92353873Simp 92453873Simpstatic int 92553873Simppccard_set_resource(device_t dev, device_t child, int type, int rid, 926294883Sjhibbits rman_res_t start, rman_res_t count) 92753873Simp{ 92866847Simp struct pccard_ivar *devi = PCCARD_IVAR(child); 92953873Simp struct resource_list *rl = &devi->resources; 93053873Simp 93153873Simp if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY 93253873Simp && type != SYS_RES_IRQ && type != SYS_RES_DRQ) 93374632Simp return (EINVAL); 93453873Simp if (rid < 0) 93574632Simp return (EINVAL); 93653873Simp if (type == SYS_RES_IOPORT && rid >= PCCARD_NPORT) 93774632Simp return (EINVAL); 93853873Simp if (type == SYS_RES_MEMORY && rid >= PCCARD_NMEM) 93974632Simp return (EINVAL); 94053873Simp if (type == SYS_RES_IRQ && rid >= PCCARD_NIRQ) 94174632Simp return (EINVAL); 94253873Simp if (type == SYS_RES_DRQ && rid >= PCCARD_NDRQ) 94374632Simp return (EINVAL); 94453873Simp 94553873Simp resource_list_add(rl, type, rid, start, start + count - 1, count); 94682378Sjon if (NULL != resource_list_alloc(rl, device_get_parent(dev), dev, 94782378Sjon type, &rid, start, start + count - 1, count, 0)) 94882378Sjon return 0; 94982378Sjon else 95082378Sjon return ENOMEM; 95153873Simp} 95253873Simp 95353873Simpstatic int 95453873Simppccard_get_resource(device_t dev, device_t child, int type, int rid, 955294883Sjhibbits rman_res_t *startp, rman_res_t *countp) 95653873Simp{ 95766847Simp struct pccard_ivar *devi = PCCARD_IVAR(child); 95853873Simp struct resource_list *rl = &devi->resources; 95953873Simp struct resource_list_entry *rle; 96053873Simp 96153873Simp rle = resource_list_find(rl, type, rid); 96276424Simp if (rle == NULL) 96374632Simp return (ENOENT); 96470715Sjon 96576424Simp if (startp != NULL) 96653873Simp *startp = rle->start; 96776424Simp if (countp != NULL) 96853873Simp *countp = rle->count; 96953873Simp 97074632Simp return (0); 97153873Simp} 97253873Simp 97353873Simpstatic void 97453873Simppccard_delete_resource(device_t dev, device_t child, int type, int rid) 97553873Simp{ 97666847Simp struct pccard_ivar *devi = PCCARD_IVAR(child); 97753873Simp struct resource_list *rl = &devi->resources; 97853873Simp resource_list_delete(rl, type, rid); 97953873Simp} 98053873Simp 98159193Simpstatic int 98259193Simppccard_set_res_flags(device_t dev, device_t child, int type, int rid, 983188179Simp u_long flags) 98459193Simp{ 98574632Simp return (CARD_SET_RES_FLAGS(device_get_parent(dev), child, type, 98674632Simp rid, flags)); 98759193Simp} 98859193Simp 98959193Simpstatic int 99059193Simppccard_set_memory_offset(device_t dev, device_t child, int rid, 991140692Simp uint32_t offset, uint32_t *deltap) 99270715Sjon 99359193Simp{ 99474632Simp return (CARD_SET_MEMORY_OFFSET(device_get_parent(dev), child, rid, 99574632Simp offset, deltap)); 99659193Simp} 99759193Simp 998104641Simpstatic void 999104641Simppccard_probe_nomatch(device_t bus, device_t child) 1000104641Simp{ 1001104641Simp struct pccard_ivar *devi = PCCARD_IVAR(child); 1002147963Simp struct pccard_function *pf = devi->pf; 1003104641Simp struct pccard_softc *sc = PCCARD_SOFTC(bus); 1004148019Simp int i; 1005104641Simp 1006104641Simp device_printf(bus, "<unknown card>"); 1007148012Simp printf(" (manufacturer=0x%04x, product=0x%04x, function_type=%d) " 1008148012Simp "at function %d\n", sc->card.manufacturer, sc->card.product, 1009148012Simp pf->function, pf->number); 1010148012Simp device_printf(bus, " CIS info: "); 1011148012Simp for (i = 0; sc->card.cis1_info[i] != NULL && i < 4; i++) 1012148012Simp printf("%s%s", i > 0 ? ", " : "", sc->card.cis1_info[i]); 1013148012Simp printf("\n"); 1014104641Simp return; 1015104641Simp} 1016104641Simp 101766058Simpstatic int 1018104641Simppccard_child_location_str(device_t bus, device_t child, char *buf, 1019104641Simp size_t buflen) 1020104641Simp{ 1021104641Simp struct pccard_ivar *devi = PCCARD_IVAR(child); 1022147963Simp struct pccard_function *pf = devi->pf; 1023104641Simp 1024147963Simp snprintf(buf, buflen, "function=%d", pf->number); 1025104641Simp return (0); 1026104641Simp} 1027104641Simp 1028104641Simpstatic int 1029104641Simppccard_child_pnpinfo_str(device_t bus, device_t child, char *buf, 1030104641Simp size_t buflen) 1031104641Simp{ 1032104641Simp struct pccard_ivar *devi = PCCARD_IVAR(child); 1033147963Simp struct pccard_function *pf = devi->pf; 1034104641Simp struct pccard_softc *sc = PCCARD_SOFTC(bus); 1035147963Simp char cis0[128], cis1[128]; 1036104641Simp 1037297365Simp devctl_safe_quote(cis0, sc->card.cis1_info[0], sizeof(cis0)); 1038297365Simp devctl_safe_quote(cis1, sc->card.cis1_info[1], sizeof(cis1)); 1039104641Simp snprintf(buf, buflen, "manufacturer=0x%04x product=0x%04x " 1040104641Simp "cisvendor=\"%s\" cisproduct=\"%s\" function_type=%d", 1041147963Simp sc->card.manufacturer, sc->card.product, cis0, cis1, pf->function); 1042104641Simp return (0); 1043104641Simp} 1044104641Simp 1045104641Simpstatic int 1046188179Simppccard_read_ivar(device_t bus, device_t child, int which, uintptr_t *result) 104766058Simp{ 104866847Simp struct pccard_ivar *devi = PCCARD_IVAR(child); 1049147963Simp struct pccard_function *pf = devi->pf; 105066779Simp struct pccard_softc *sc = PCCARD_SOFTC(bus); 105166779Simp 1052147963Simp if (!pf) 1053147963Simp panic("No pccard function pointer"); 105466779Simp switch (which) { 105566779Simp default: 1056147963Simp return (EINVAL); 1057189318Simp case PCCARD_IVAR_FUNCE_DISK: 1058189318Simp *(uint16_t *)result = pf->pf_funce_disk_interface | 1059189318Simp (pf->pf_funce_disk_power << 8); 1060189318Simp break; 106166779Simp case PCCARD_IVAR_ETHADDR: 1062147963Simp bcopy(pf->pf_funce_lan_nid, result, ETHER_ADDR_LEN); 106366779Simp break; 106466779Simp case PCCARD_IVAR_VENDOR: 1065147963Simp *(uint32_t *)result = sc->card.manufacturer; 106666779Simp break; 106766779Simp case PCCARD_IVAR_PRODUCT: 1068147963Simp *(uint32_t *)result = sc->card.product; 106966779Simp break; 107090964Sshiba case PCCARD_IVAR_PRODEXT: 1071147963Simp *(uint16_t *)result = sc->card.prodext; 107290964Sshiba break; 107375761Simp case PCCARD_IVAR_FUNCTION: 1074147963Simp *(uint32_t *)result = pf->function; 107575761Simp break; 107666779Simp case PCCARD_IVAR_FUNCTION_NUMBER: 1077147963Simp *(uint32_t *)result = pf->number; 107866779Simp break; 107966779Simp case PCCARD_IVAR_VENDOR_STR: 1080147963Simp *(const char **)result = sc->card.cis1_info[0]; 108166779Simp break; 108266779Simp case PCCARD_IVAR_PRODUCT_STR: 1083147963Simp *(const char **)result = sc->card.cis1_info[1]; 108466779Simp break; 108566779Simp case PCCARD_IVAR_CIS3_STR: 1086147963Simp *(const char **)result = sc->card.cis1_info[2]; 108766779Simp break; 108867167Simp case PCCARD_IVAR_CIS4_STR: 1089147963Simp *(const char **)result = sc->card.cis1_info[3]; 109067167Simp break; 109166779Simp } 109266779Simp return (0); 109366058Simp} 109466058Simp 109566779Simpstatic void 109666779Simppccard_driver_added(device_t dev, driver_t *driver) 109766779Simp{ 109882378Sjon struct pccard_softc *sc = PCCARD_SOFTC(dev); 109982378Sjon struct pccard_function *pf; 110082378Sjon device_t child; 110182378Sjon 110282378Sjon STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 110382378Sjon if (STAILQ_EMPTY(&pf->cfe_head)) 110482378Sjon continue; 110582378Sjon child = pf->dev; 110682378Sjon if (device_get_state(child) != DS_NOTPRESENT) 110782378Sjon continue; 1108181342Simp pccard_probe_and_attach_child(dev, child, pf); 110982378Sjon } 111082378Sjon return; 111166779Simp} 111266058Simp 111367242Simpstatic struct resource * 111467242Simppccard_alloc_resource(device_t dev, device_t child, int type, int *rid, 1115294883Sjhibbits rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) 111667242Simp{ 111782378Sjon struct pccard_ivar *dinfo; 1118315221Spfg struct resource_list_entry *rle = NULL; 111982378Sjon int passthrough = (device_get_parent(child) != dev); 1120295832Sjhibbits int isdefault = (RMAN_IS_DEFAULT_RANGE(start, end) && count == 1); 1121104641Simp struct resource *r = NULL; 112267242Simp 1123121905Simp /* XXX I'm no longer sure this is right */ 112482378Sjon if (passthrough) { 112582378Sjon return (BUS_ALLOC_RESOURCE(device_get_parent(dev), child, 112682378Sjon type, rid, start, end, count, flags)); 112782378Sjon } 112870715Sjon 112982378Sjon dinfo = device_get_ivars(child); 113082378Sjon rle = resource_list_find(&dinfo->resources, type, *rid); 113170715Sjon 1132121905Simp if (rle == NULL && isdefault) 1133121905Simp return (NULL); /* no resource of that type/rid */ 1134121905Simp if (rle == NULL || rle->res == NULL) { 1135144955Simp /* XXX Need to adjust flags */ 1136121905Simp r = bus_alloc_resource(dev, type, rid, start, end, 1137144955Simp count, flags); 1138121905Simp if (r == NULL) 1139121905Simp goto bad; 1140121905Simp resource_list_add(&dinfo->resources, type, *rid, 1141121905Simp rman_get_start(r), rman_get_end(r), count); 1142121905Simp rle = resource_list_find(&dinfo->resources, type, *rid); 1143121905Simp if (!rle) 1144121905Simp goto bad; 1145121905Simp rle->res = r; 114667269Simp } 1147121905Simp /* 1148144955Simp * If dev doesn't own the device, then we can't give this device 1149144955Simp * out. 1150121905Simp */ 1151113242Simp if (rman_get_device(rle->res) != dev) 1152104641Simp return (NULL); 1153144955Simp rman_set_device(rle->res, child); 1154144955Simp if (flags & RF_ACTIVE) 1155144955Simp BUS_ACTIVATE_RESOURCE(dev, child, type, *rid, rle->res); 1156104641Simp return (rle->res); 1157104641Simpbad:; 1158104641Simp device_printf(dev, "WARNING: Resource not reserved by pccard\n"); 1159104641Simp return (NULL); 116067242Simp} 116167242Simp 116267242Simpstatic int 116367242Simppccard_release_resource(device_t dev, device_t child, int type, int rid, 116467242Simp struct resource *r) 116567242Simp{ 116682378Sjon struct pccard_ivar *dinfo; 116782378Sjon int passthrough = (device_get_parent(child) != dev); 1168315221Spfg struct resource_list_entry *rle = NULL; 116970715Sjon 117082378Sjon if (passthrough) 117182378Sjon return BUS_RELEASE_RESOURCE(device_get_parent(dev), child, 117282378Sjon type, rid, r); 117370715Sjon 117482378Sjon dinfo = device_get_ivars(child); 117570715Sjon 117682378Sjon rle = resource_list_find(&dinfo->resources, type, rid); 117770715Sjon 117882378Sjon if (!rle) { 117982378Sjon device_printf(dev, "Allocated resource not found, " 1180297000Sjhibbits "%d %#x %#jx %#jx\n", 118182378Sjon type, rid, rman_get_start(r), rman_get_size(r)); 118282378Sjon return ENOENT; 118370715Sjon } 118482378Sjon if (!rle->res) { 118582378Sjon device_printf(dev, "Allocated resource not recorded\n"); 118682378Sjon return ENOENT; 118770715Sjon } 1188144955Simp /* 1189144955Simp * Deactivate the resource (since it is being released), and 1190144955Simp * assign it to the bus. 1191144955Simp */ 1192144955Simp BUS_DEACTIVATE_RESOURCE(dev, child, type, rid, rle->res); 1193144955Simp rman_set_device(rle->res, dev); 1194144955Simp return (0); 119567242Simp} 119667242Simp 119767333Simpstatic void 119867333Simppccard_child_detached(device_t parent, device_t dev) 119967333Simp{ 120067333Simp struct pccard_ivar *ivar = PCCARD_IVAR(dev); 1201147963Simp struct pccard_function *pf = ivar->pf; 120267333Simp 120382378Sjon pccard_function_disable(pf); 120467333Simp} 120567333Simp 1206166901Spisostatic int 1207170163Spisopccard_filter(void *arg) 120870762Simp{ 120982378Sjon struct pccard_function *pf = (struct pccard_function*) arg; 121082378Sjon int reg; 1211102923Simp int doisr = 1; 121282378Sjon 121382383Simp /* 1214102923Simp * MFC cards know if they interrupted, so we have to ack the 1215102923Simp * interrupt and call the ISR. Non-MFC cards don't have these 1216102923Simp * bits, so they always get called. Many non-MFC cards have 1217102923Simp * this bit set always upon read, but some do not. 1218102923Simp * 1219102923Simp * We always ack the interrupt, even if there's no ISR 1220102923Simp * for the card. This is done on the theory that acking 1221102923Simp * the interrupt will pacify the card enough to keep an 1222102923Simp * interrupt storm from happening. Of course this won't 1223102923Simp * help in the non-MFC case. 1224116311Simp * 1225116311Simp * This has no impact for MPSAFEness of the client drivers. 1226116311Simp * We register this with whatever flags the intr_handler 1227116311Simp * was registered with. All these functions are MPSAFE. 122882383Simp */ 1229102923Simp if (pccard_mfc(pf->sc)) { 1230102923Simp reg = pccard_ccr_read(pf, PCCARD_CCR_STATUS); 1231102923Simp if (reg & PCCARD_CCR_STATUS_INTR) 1232102923Simp pccard_ccr_write(pf, PCCARD_CCR_STATUS, 1233102923Simp reg & ~PCCARD_CCR_STATUS_INTR); 1234102923Simp else 1235102923Simp doisr = 0; 1236102923Simp } 1237166901Spiso if (doisr) { 1238170163Spiso if (pf->intr_filter != NULL) 1239170163Spiso return (pf->intr_filter(pf->intr_handler_arg)); 1240170849Simp return (FILTER_SCHEDULE_THREAD); 1241166901Spiso } 1242170163Spiso return (FILTER_STRAY); 124370715Sjon} 124470715Sjon 1245170163Spisostatic void 1246170163Spisopccard_intr(void *arg) 1247170163Spiso{ 1248170163Spiso struct pccard_function *pf = (struct pccard_function*) arg; 1249170163Spiso 1250170163Spiso pf->intr_handler(pf->intr_handler_arg); 1251170163Spiso} 1252170163Spiso 125370715Sjonstatic int 125470762Simppccard_setup_intr(device_t dev, device_t child, struct resource *irq, 1255166901Spiso int flags, driver_filter_t *filt, driver_intr_t *intr, void *arg, 1256166901Spiso void **cookiep) 125770715Sjon{ 1258102713Simp struct pccard_softc *sc = PCCARD_SOFTC(dev); 125970715Sjon struct pccard_ivar *ivar = PCCARD_IVAR(child); 1260147963Simp struct pccard_function *pf = ivar->pf; 126190445Simp int err; 126270715Sjon 1263170163Spiso if (pf->intr_filter != NULL || pf->intr_handler != NULL) 1264101762Simp panic("Only one interrupt handler per function allowed"); 1265170163Spiso err = bus_generic_setup_intr(dev, child, irq, flags, pccard_filter, 1266170849Simp intr ? pccard_intr : NULL, pf, cookiep); 126790445Simp if (err != 0) 126890445Simp return (err); 1269170163Spiso pf->intr_filter = filt; 1270147963Simp pf->intr_handler = intr; 1271147963Simp pf->intr_handler_arg = arg; 1272147963Simp pf->intr_handler_cookie = *cookiep; 1273102713Simp if (pccard_mfc(sc)) { 1274147963Simp pccard_ccr_write(pf, PCCARD_CCR_OPTION, 1275147963Simp pccard_ccr_read(pf, PCCARD_CCR_OPTION) | 1276102713Simp PCCARD_CCR_OPTION_IREQ_ENABLE); 1277102713Simp } 127874632Simp return (0); 127970715Sjon} 128070715Sjon 128170715Sjonstatic int 128270762Simppccard_teardown_intr(device_t dev, device_t child, struct resource *r, 128370762Simp void *cookie) 128470715Sjon{ 1285102713Simp struct pccard_softc *sc = PCCARD_SOFTC(dev); 128670715Sjon struct pccard_ivar *ivar = PCCARD_IVAR(child); 1287147963Simp struct pccard_function *pf = ivar->pf; 128882378Sjon int ret; 128970715Sjon 1290102713Simp if (pccard_mfc(sc)) { 1291147963Simp pccard_ccr_write(pf, PCCARD_CCR_OPTION, 1292147963Simp pccard_ccr_read(pf, PCCARD_CCR_OPTION) & 1293102713Simp ~PCCARD_CCR_OPTION_IREQ_ENABLE); 1294102713Simp } 129590445Simp ret = bus_generic_teardown_intr(dev, child, r, cookie); 129682378Sjon if (ret == 0) { 1297147963Simp pf->intr_handler = NULL; 1298147963Simp pf->intr_handler_arg = NULL; 1299147963Simp pf->intr_handler_cookie = NULL; 130082378Sjon } 130170715Sjon 130282378Sjon return (ret); 130370715Sjon} 130470715Sjon 1305121905Simpstatic int 1306121905Simppccard_activate_resource(device_t brdev, device_t child, int type, int rid, 1307121905Simp struct resource *r) 1308121905Simp{ 1309121905Simp struct pccard_ivar *ivar = PCCARD_IVAR(child); 1310147963Simp struct pccard_function *pf = ivar->pf; 1311121905Simp 1312121905Simp switch(type) { 1313121905Simp case SYS_RES_IOPORT: 1314121905Simp /* 1315121905Simp * We need to adjust IOBASE[01] and IOSIZE if we're an MFC 1316121905Simp * card. 1317121905Simp */ 1318121905Simp if (pccard_mfc(pf->sc)) 1319121905Simp pccard_mfc_adjust_iobase(pf, rman_get_start(r), 0, 1320121905Simp rman_get_size(r)); 1321121905Simp break; 1322121905Simp default: 1323121905Simp break; 1324121905Simp } 1325121905Simp return (bus_generic_activate_resource(brdev, child, type, rid, r)); 1326121905Simp} 1327121905Simp 1328121905Simpstatic int 1329121905Simppccard_deactivate_resource(device_t brdev, device_t child, int type, 1330121905Simp int rid, struct resource *r) 1331121905Simp{ 1332121905Simp /* XXX undo pccard_activate_resource? XXX */ 1333121905Simp return (bus_generic_deactivate_resource(brdev, child, type, rid, r)); 1334121905Simp} 1335121905Simp 1336150098Simpstatic int 1337150098Simppccard_attr_read_impl(device_t brdev, device_t child, uint32_t offset, 1338150098Simp uint8_t *val) 1339150098Simp{ 1340150098Simp struct pccard_ivar *devi = PCCARD_IVAR(child); 1341150098Simp struct pccard_function *pf = devi->pf; 1342150098Simp 1343150098Simp /* 1344150098Simp * Optimization. Most of the time, devices want to access 1345150098Simp * the same page of the attribute memory that the CCR is in. 1346150098Simp * We take advantage of this fact here. 1347150098Simp */ 1348150098Simp if (offset / PCCARD_MEM_PAGE_SIZE == 1349150098Simp pf->ccr_base / PCCARD_MEM_PAGE_SIZE) 1350150098Simp *val = bus_space_read_1(pf->pf_ccrt, pf->pf_ccrh, 1351150098Simp offset % PCCARD_MEM_PAGE_SIZE); 1352150098Simp else { 1353150098Simp CARD_SET_MEMORY_OFFSET(brdev, child, pf->ccr_rid, offset, 1354150098Simp &offset); 1355150098Simp *val = bus_space_read_1(pf->pf_ccrt, pf->pf_ccrh, offset); 1356150098Simp CARD_SET_MEMORY_OFFSET(brdev, child, pf->ccr_rid, pf->ccr_base, 1357150098Simp &offset); 1358150098Simp } 1359150098Simp return 0; 1360150098Simp} 1361150098Simp 1362150098Simpstatic int 1363150098Simppccard_attr_write_impl(device_t brdev, device_t child, uint32_t offset, 1364150098Simp uint8_t val) 1365150098Simp{ 1366150098Simp struct pccard_ivar *devi = PCCARD_IVAR(child); 1367150098Simp struct pccard_function *pf = devi->pf; 1368150098Simp 1369150098Simp /* 1370150098Simp * Optimization. Most of the time, devices want to access 1371150098Simp * the same page of the attribute memory that the CCR is in. 1372150098Simp * We take advantage of this fact here. 1373150098Simp */ 1374150098Simp if (offset / PCCARD_MEM_PAGE_SIZE == 1375150098Simp pf->ccr_base / PCCARD_MEM_PAGE_SIZE) 1376150098Simp bus_space_write_1(pf->pf_ccrt, pf->pf_ccrh, 1377150098Simp offset % PCCARD_MEM_PAGE_SIZE, val); 1378150098Simp else { 1379150098Simp CARD_SET_MEMORY_OFFSET(brdev, child, pf->ccr_rid, offset, 1380150098Simp &offset); 1381150098Simp bus_space_write_1(pf->pf_ccrt, pf->pf_ccrh, offset, val); 1382150098Simp CARD_SET_MEMORY_OFFSET(brdev, child, pf->ccr_rid, pf->ccr_base, 1383150098Simp &offset); 1384150098Simp } 1385150098Simp 1386150098Simp return 0; 1387150098Simp} 1388150098Simp 1389150098Simpstatic int 1390150098Simppccard_ccr_read_impl(device_t brdev, device_t child, uint32_t offset, 1391150098Simp uint8_t *val) 1392150098Simp{ 1393150098Simp struct pccard_ivar *devi = PCCARD_IVAR(child); 1394150098Simp 1395150098Simp *val = pccard_ccr_read(devi->pf, offset); 1396222764Simp DEVPRINTF((child, "ccr_read of %#x (%#x) is %#x\n", offset, 1397222764Simp devi->pf->pf_ccr_offset, *val)); 1398150098Simp return 0; 1399150098Simp} 1400150098Simp 1401150098Simpstatic int 1402150098Simppccard_ccr_write_impl(device_t brdev, device_t child, uint32_t offset, 1403150098Simp uint8_t val) 1404150098Simp{ 1405150098Simp struct pccard_ivar *devi = PCCARD_IVAR(child); 1406150098Simp struct pccard_function *pf = devi->pf; 1407150098Simp 1408150098Simp /* 1409150098Simp * Can't use pccard_ccr_write since client drivers may access 1410150098Simp * registers not contained in the 'mask' if they are non-standard. 1411150098Simp */ 1412222764Simp DEVPRINTF((child, "ccr_write of %#x to %#x (%#x)\n", val, offset, 1413222764Simp devi->pf->pf_ccr_offset)); 1414150098Simp bus_space_write_1(pf->pf_ccrt, pf->pf_ccrh, pf->pf_ccr_offset + offset, 1415150098Simp val); 1416150098Simp return 0; 1417150098Simp} 1418150098Simp 1419150098Simp 142052506Simpstatic device_method_t pccard_methods[] = { 142152506Simp /* Device interface */ 142252506Simp DEVMETHOD(device_probe, pccard_probe), 142359193Simp DEVMETHOD(device_attach, pccard_attach), 142482378Sjon DEVMETHOD(device_detach, pccard_detach), 142552506Simp DEVMETHOD(device_shutdown, bus_generic_shutdown), 142687975Simp DEVMETHOD(device_suspend, pccard_suspend), 142787975Simp DEVMETHOD(device_resume, pccard_resume), 142852506Simp 142952506Simp /* Bus interface */ 143052506Simp DEVMETHOD(bus_print_child, pccard_print_child), 143166779Simp DEVMETHOD(bus_driver_added, pccard_driver_added), 143267333Simp DEVMETHOD(bus_child_detached, pccard_child_detached), 143367242Simp DEVMETHOD(bus_alloc_resource, pccard_alloc_resource), 143467242Simp DEVMETHOD(bus_release_resource, pccard_release_resource), 1435121905Simp DEVMETHOD(bus_activate_resource, pccard_activate_resource), 1436121905Simp DEVMETHOD(bus_deactivate_resource, pccard_deactivate_resource), 143770715Sjon DEVMETHOD(bus_setup_intr, pccard_setup_intr), 143870715Sjon DEVMETHOD(bus_teardown_intr, pccard_teardown_intr), 143952506Simp DEVMETHOD(bus_set_resource, pccard_set_resource), 144052506Simp DEVMETHOD(bus_get_resource, pccard_get_resource), 144152506Simp DEVMETHOD(bus_delete_resource, pccard_delete_resource), 1442104641Simp DEVMETHOD(bus_probe_nomatch, pccard_probe_nomatch), 144366058Simp DEVMETHOD(bus_read_ivar, pccard_read_ivar), 1444104641Simp DEVMETHOD(bus_child_pnpinfo_str, pccard_child_pnpinfo_str), 1445104641Simp DEVMETHOD(bus_child_location_str, pccard_child_location_str), 144652506Simp 144759193Simp /* Card Interface */ 144859193Simp DEVMETHOD(card_set_res_flags, pccard_set_res_flags), 144959193Simp DEVMETHOD(card_set_memory_offset, pccard_set_memory_offset), 145059193Simp DEVMETHOD(card_attach_card, pccard_attach_card), 145159193Simp DEVMETHOD(card_detach_card, pccard_detach_card), 1452150098Simp DEVMETHOD(card_do_product_lookup, pccard_do_product_lookup), 1453147711Simp DEVMETHOD(card_cis_scan, pccard_scan_cis), 1454150098Simp DEVMETHOD(card_attr_read, pccard_attr_read_impl), 1455150098Simp DEVMETHOD(card_attr_write, pccard_attr_write_impl), 1456150098Simp DEVMETHOD(card_ccr_read, pccard_ccr_read_impl), 1457150098Simp DEVMETHOD(card_ccr_write, pccard_ccr_write_impl), 145859193Simp 145952506Simp { 0, 0 } 146052506Simp}; 146152506Simp 146252506Simpstatic driver_t pccard_driver = { 146352506Simp "pccard", 146452506Simp pccard_methods, 146564850Simp sizeof(struct pccard_softc) 146652506Simp}; 146752506Simp 146852506Simpdevclass_t pccard_devclass; 146952506Simp 1470101905Simp/* Maybe we need to have a slot device? */ 147153873SimpDRIVER_MODULE(pccard, pcic, pccard_driver, pccard_devclass, 0, 0); 1472101905SimpDRIVER_MODULE(pccard, cbb, pccard_driver, pccard_devclass, 0, 0); 147364927SimpMODULE_VERSION(pccard, 1); 1474