Home | History | Annotate | Line # | Download | only in cardbus
cardbus_map.c revision 1.3.2.1
      1  1.3.2.1  bouyer /*	$NetBSD: cardbus_map.c,v 1.3.2.1 2000/11/20 11:39:53 bouyer Exp $	*/
      2      1.1    haya 
      3      1.1    haya /*
      4  1.3.2.1  bouyer  * Copyright (c) 1999 and 2000
      5      1.1    haya  *      HAYAKAWA Koichi.  All rights reserved.
      6      1.1    haya  *
      7      1.1    haya  * Redistribution and use in source and binary forms, with or without
      8      1.1    haya  * modification, are permitted provided that the following conditions
      9      1.1    haya  * are met:
     10      1.1    haya  * 1. Redistributions of source code must retain the above copyright
     11      1.1    haya  *    notice, this list of conditions and the following disclaimer.
     12      1.1    haya  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1    haya  *    notice, this list of conditions and the following disclaimer in the
     14      1.1    haya  *    documentation and/or other materials provided with the distribution.
     15      1.1    haya  * 3. All advertising materials mentioning features or use of this software
     16      1.1    haya  *    must display the following acknowledgement:
     17      1.1    haya  *	This product includes software developed by HAYAKAWA Koichi.
     18      1.1    haya  * 4. The name of the author may not be used to endorse or promote products
     19      1.1    haya  *    derived from this software without specific prior written permission.
     20      1.1    haya  *
     21      1.1    haya  *
     22      1.1    haya  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23      1.1    haya  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     24      1.1    haya  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     25      1.1    haya  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     26      1.1    haya  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     27      1.1    haya  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     28      1.1    haya  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29      1.1    haya  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     30      1.1    haya  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     31      1.1    haya  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     32      1.1    haya  * POSSIBILITY OF SUCH DAMAGE.
     33      1.1    haya  */
     34      1.1    haya 
     35      1.1    haya 
     36      1.1    haya #include <sys/types.h>
     37      1.1    haya #include <sys/param.h>
     38      1.1    haya #include <sys/systm.h>
     39      1.1    haya #include <sys/device.h>
     40      1.1    haya 
     41      1.1    haya #include <machine/bus.h>
     42      1.1    haya 
     43      1.1    haya #include <dev/cardbus/cardbusvar.h>
     44      1.1    haya 
     45      1.1    haya #include <dev/pci/pcireg.h>	/* XXX */
     46      1.1    haya 
     47      1.1    haya #if defined DEBUG && !defined CARDBUS_MAP_DEBUG
     48      1.1    haya #define CARDBUS_MAP_DEBUG
     49      1.1    haya #endif
     50      1.1    haya 
     51      1.1    haya #if defined CARDBUS_MAP_DEBUG
     52      1.1    haya #define STATIC
     53      1.1    haya #define DPRINTF(a) printf a
     54      1.1    haya #else
     55      1.1    haya #define STATIC static
     56      1.1    haya #define DPRINTF(a)
     57      1.1    haya #endif
     58      1.1    haya 
     59      1.1    haya 
     60      1.1    haya static int cardbus_io_find __P((cardbus_chipset_tag_t, cardbus_function_tag_t,
     61      1.1    haya 				cardbustag_t, int, cardbusreg_t,
     62      1.1    haya 				bus_addr_t *, bus_size_t *, int *));
     63      1.1    haya static int cardbus_mem_find __P((cardbus_chipset_tag_t, cardbus_function_tag_t,
     64      1.1    haya 				 cardbustag_t, int, cardbusreg_t,
     65      1.1    haya 				 bus_addr_t *, bus_size_t *, int *));
     66      1.1    haya 
     67      1.1    haya /*
     68      1.1    haya  * static int cardbus_io_find(cardbus_chipset_tag_t cc,
     69      1.1    haya  *			      cardbus_function_tag_t cf, cardbustag_t tag,
     70      1.1    haya  *			      int reg, cardbusreg_t type, bus_addr_t *basep,
     71      1.1    haya  *			      bus_size_t *sizep, int *flagsp)
     72  1.3.2.1  bouyer  * This code is stolen from sys/dev/pci_map.c.
     73      1.1    haya  */
     74      1.1    haya static int
     75      1.1    haya cardbus_io_find(cc, cf, tag, reg, type, basep, sizep, flagsp)
     76  1.3.2.1  bouyer 	cardbus_chipset_tag_t cc;
     77  1.3.2.1  bouyer 	cardbus_function_tag_t cf;
     78  1.3.2.1  bouyer 	cardbustag_t tag;
     79  1.3.2.1  bouyer 	int reg;
     80  1.3.2.1  bouyer 	cardbusreg_t type;
     81  1.3.2.1  bouyer 	bus_addr_t *basep;
     82  1.3.2.1  bouyer 	bus_size_t *sizep;
     83  1.3.2.1  bouyer 	int *flagsp;
     84      1.1    haya {
     85  1.3.2.1  bouyer 	cardbusreg_t address, mask;
     86  1.3.2.1  bouyer 	int s;
     87      1.1    haya 
     88  1.3.2.1  bouyer 	/* EXT ROM is able to map on memory space ONLY. */
     89  1.3.2.1  bouyer 	if (reg == CARDBUS_ROM_REG) {
     90  1.3.2.1  bouyer 		return 1;
     91  1.3.2.1  bouyer 	}
     92  1.3.2.1  bouyer 
     93  1.3.2.1  bouyer 	if(reg < PCI_MAPREG_START || reg >= PCI_MAPREG_END || (reg & 3)) {
     94  1.3.2.1  bouyer 		panic("cardbus_io_find: bad request");
     95  1.3.2.1  bouyer 	}
     96  1.3.2.1  bouyer 
     97  1.3.2.1  bouyer 	/*
     98  1.3.2.1  bouyer 	 * Section 6.2.5.1, `Address Maps', tells us that:
     99  1.3.2.1  bouyer 	 *
    100  1.3.2.1  bouyer 	 * 1) The builtin software should have already mapped the device in a
    101  1.3.2.1  bouyer 	 * reasonable way.
    102  1.3.2.1  bouyer 	 *
    103  1.3.2.1  bouyer 	 * 2) A device which wants 2^n bytes of memory will hardwire the bottom
    104  1.3.2.1  bouyer 	 * n bits of the address to 0.  As recommended, we write all 1s and see
    105  1.3.2.1  bouyer 	 * what we get back.
    106  1.3.2.1  bouyer 	 */
    107  1.3.2.1  bouyer 	s = splhigh();
    108  1.3.2.1  bouyer 	address = cardbus_conf_read(cc, cf, tag, reg);
    109  1.3.2.1  bouyer 	cardbus_conf_write(cc, cf, tag, reg, 0xffffffff);
    110  1.3.2.1  bouyer 	mask = cardbus_conf_read(cc, cf, tag, reg);
    111  1.3.2.1  bouyer 	cardbus_conf_write(cc, cf, tag, reg, address);
    112  1.3.2.1  bouyer 	splx(s);
    113  1.3.2.1  bouyer 
    114  1.3.2.1  bouyer 	if (PCI_MAPREG_TYPE(address) != PCI_MAPREG_TYPE_IO) {
    115  1.3.2.1  bouyer 		printf("cardbus_io_find: expected type i/o, found mem\n");
    116  1.3.2.1  bouyer 		return 1;
    117  1.3.2.1  bouyer 	}
    118  1.3.2.1  bouyer 
    119  1.3.2.1  bouyer 	if (PCI_MAPREG_IO_SIZE(mask) == 0) {
    120  1.3.2.1  bouyer 		printf("cardbus_io_find: void region\n");
    121  1.3.2.1  bouyer 		return 1;
    122  1.3.2.1  bouyer 	}
    123  1.3.2.1  bouyer 
    124  1.3.2.1  bouyer 	if (basep != 0) {
    125  1.3.2.1  bouyer 		*basep = PCI_MAPREG_IO_ADDR(address);
    126  1.3.2.1  bouyer 	}
    127  1.3.2.1  bouyer 	if (sizep != 0) {
    128  1.3.2.1  bouyer 		*sizep = PCI_MAPREG_IO_SIZE(mask);
    129  1.3.2.1  bouyer 	}
    130  1.3.2.1  bouyer 	if (flagsp != 0) {
    131  1.3.2.1  bouyer 		*flagsp = 0;
    132  1.3.2.1  bouyer 	}
    133      1.1    haya 
    134  1.3.2.1  bouyer 	return 0;
    135      1.1    haya }
    136      1.1    haya 
    137      1.1    haya 
    138      1.1    haya 
    139      1.1    haya /*
    140      1.1    haya  * static int cardbus_mem_find(cardbus_chipset_tag_t cc,
    141      1.1    haya  *			       cardbus_function_tag_t cf, cardbustag_t tag,
    142      1.1    haya  *			       int reg, cardbusreg_t type, bus_addr_t *basep,
    143      1.1    haya  *			       bus_size_t *sizep, int *flagsp)
    144  1.3.2.1  bouyer  * This code is stolen from sys/dev/pci_map.c.
    145      1.1    haya  */
    146      1.1    haya static int
    147      1.1    haya cardbus_mem_find(cc, cf, tag, reg, type, basep, sizep, flagsp)
    148  1.3.2.1  bouyer 	cardbus_chipset_tag_t cc;
    149  1.3.2.1  bouyer 	cardbus_function_tag_t cf;
    150  1.3.2.1  bouyer 	cardbustag_t tag;
    151  1.3.2.1  bouyer 	int reg;
    152  1.3.2.1  bouyer 	cardbusreg_t type;
    153  1.3.2.1  bouyer 	bus_addr_t *basep;
    154  1.3.2.1  bouyer 	bus_size_t *sizep;
    155  1.3.2.1  bouyer 	int *flagsp;
    156      1.1    haya {
    157  1.3.2.1  bouyer 	cardbusreg_t address, mask;
    158  1.3.2.1  bouyer 	int s;
    159      1.1    haya 
    160  1.3.2.1  bouyer 	if (reg != CARDBUS_ROM_REG &&
    161  1.3.2.1  bouyer 	    (reg < PCI_MAPREG_START || reg >= PCI_MAPREG_END || (reg & 3))) {
    162  1.3.2.1  bouyer 		panic("cardbus_mem_find: bad request");
    163  1.3.2.1  bouyer 	}
    164  1.3.2.1  bouyer 
    165  1.3.2.1  bouyer 	/*
    166  1.3.2.1  bouyer 	 * Section 6.2.5.1, `Address Maps', tells us that:
    167  1.3.2.1  bouyer 	 *
    168  1.3.2.1  bouyer 	 * 1) The builtin software should have already mapped the device in a
    169  1.3.2.1  bouyer 	 * reasonable way.
    170  1.3.2.1  bouyer 	 *
    171  1.3.2.1  bouyer 	 * 2) A device which wants 2^n bytes of memory will hardwire the bottom
    172  1.3.2.1  bouyer 	 * n bits of the address to 0.  As recommended, we write all 1s and see
    173  1.3.2.1  bouyer 	 * what we get back.
    174  1.3.2.1  bouyer 	 */
    175  1.3.2.1  bouyer 	s = splhigh();
    176  1.3.2.1  bouyer 	address = cardbus_conf_read(cc, cf, tag, reg);
    177  1.3.2.1  bouyer 	cardbus_conf_write(cc, cf, tag, reg, 0xffffffff);
    178  1.3.2.1  bouyer 	mask = cardbus_conf_read(cc, cf, tag, reg);
    179  1.3.2.1  bouyer 	cardbus_conf_write(cc, cf, tag, reg, address);
    180  1.3.2.1  bouyer 	splx(s);
    181  1.3.2.1  bouyer 
    182  1.3.2.1  bouyer 	if (reg != CARDBUS_ROM_REG) {
    183  1.3.2.1  bouyer 		/* memory space BAR */
    184  1.3.2.1  bouyer 
    185  1.3.2.1  bouyer 		if (PCI_MAPREG_TYPE(address) != PCI_MAPREG_TYPE_MEM) {
    186  1.3.2.1  bouyer 			printf("cardbus_mem_find: expected type mem, found i/o\n");
    187  1.3.2.1  bouyer 			return 1;
    188  1.3.2.1  bouyer 		}
    189  1.3.2.1  bouyer 		if (PCI_MAPREG_MEM_TYPE(address) != PCI_MAPREG_MEM_TYPE(type)) {
    190  1.3.2.1  bouyer 			printf("cardbus_mem_find: expected mem type %08x, found %08x\n",
    191  1.3.2.1  bouyer 			    PCI_MAPREG_MEM_TYPE(type),
    192  1.3.2.1  bouyer 			    PCI_MAPREG_MEM_TYPE(address));
    193  1.3.2.1  bouyer 			return 1;
    194  1.3.2.1  bouyer 		}
    195  1.3.2.1  bouyer 	}
    196  1.3.2.1  bouyer 
    197  1.3.2.1  bouyer 	if (PCI_MAPREG_MEM_SIZE(mask) == 0) {
    198  1.3.2.1  bouyer 		printf("cardbus_mem_find: void region\n");
    199  1.3.2.1  bouyer 		return 1;
    200  1.3.2.1  bouyer 	}
    201  1.3.2.1  bouyer 
    202  1.3.2.1  bouyer 	switch (PCI_MAPREG_MEM_TYPE(address)) {
    203  1.3.2.1  bouyer 	case PCI_MAPREG_MEM_TYPE_32BIT:
    204  1.3.2.1  bouyer 	case PCI_MAPREG_MEM_TYPE_32BIT_1M:
    205  1.3.2.1  bouyer 		break;
    206  1.3.2.1  bouyer 	case PCI_MAPREG_MEM_TYPE_64BIT:
    207  1.3.2.1  bouyer 		printf("cardbus_mem_find: 64-bit memory mapping register\n");
    208  1.3.2.1  bouyer 		return 1;
    209  1.3.2.1  bouyer 	default:
    210  1.3.2.1  bouyer 		printf("cardbus_mem_find: reserved mapping register type\n");
    211  1.3.2.1  bouyer 		return 1;
    212  1.3.2.1  bouyer 	}
    213  1.3.2.1  bouyer 
    214  1.3.2.1  bouyer 	if (basep != 0) {
    215  1.3.2.1  bouyer 		*basep = PCI_MAPREG_MEM_ADDR(address);
    216  1.3.2.1  bouyer 	}
    217  1.3.2.1  bouyer 	if (sizep != 0) {
    218  1.3.2.1  bouyer 		*sizep = PCI_MAPREG_MEM_SIZE(mask);
    219  1.3.2.1  bouyer 	}
    220  1.3.2.1  bouyer 	if (flagsp != 0) {
    221  1.3.2.1  bouyer 		*flagsp = PCI_MAPREG_MEM_PREFETCHABLE(address) ?
    222  1.3.2.1  bouyer 		    BUS_SPACE_MAP_PREFETCHABLE : 0;
    223  1.3.2.1  bouyer 	}
    224  1.3.2.1  bouyer 
    225  1.3.2.1  bouyer 	return 0;
    226      1.1    haya }
    227      1.1    haya 
    228      1.1    haya 
    229      1.1    haya 
    230      1.1    haya 
    231      1.1    haya /*
    232  1.3.2.1  bouyer  * int cardbus_mapreg_map(struct cardbus_softc *, int, int, cardbusreg_t,
    233      1.1    haya  *			  int bus_space_tag_t *, bus_space_handle_t *,
    234      1.1    haya  *			  bus_addr_t *, bus_size_t *)
    235      1.1    haya  *    This function maps bus-space on the value of Base Address
    236      1.1    haya  *   Register (BAR) indexed by the argument `reg' (the second argument).
    237      1.1    haya  *   When the value of the BAR is not valid, such as 0x00000000, a new
    238      1.1    haya  *   address should be allocated for the BAR and new address values is
    239      1.1    haya  *   written on the BAR.
    240      1.1    haya  */
    241      1.1    haya int
    242  1.3.2.1  bouyer cardbus_mapreg_map(sc, func, reg, type, busflags, tagp, handlep, basep, sizep)
    243  1.3.2.1  bouyer 	struct cardbus_softc *sc;
    244  1.3.2.1  bouyer 	int func, reg, busflags;
    245  1.3.2.1  bouyer 	cardbusreg_t type;
    246  1.3.2.1  bouyer 	bus_space_tag_t *tagp;
    247  1.3.2.1  bouyer 	bus_space_handle_t *handlep;
    248  1.3.2.1  bouyer 	bus_addr_t *basep;
    249  1.3.2.1  bouyer 	bus_size_t *sizep;
    250      1.1    haya {
    251  1.3.2.1  bouyer 	cardbus_chipset_tag_t cc = sc->sc_cc;
    252  1.3.2.1  bouyer 	cardbus_function_tag_t cf = sc->sc_cf;
    253  1.3.2.1  bouyer 	bus_space_tag_t bustag;
    254      1.1    haya #if rbus
    255  1.3.2.1  bouyer 	rbus_tag_t rbustag;
    256      1.1    haya #endif
    257  1.3.2.1  bouyer 	bus_space_handle_t handle;
    258  1.3.2.1  bouyer 	bus_addr_t base;
    259  1.3.2.1  bouyer 	bus_size_t size;
    260  1.3.2.1  bouyer 	int flags;
    261  1.3.2.1  bouyer 	int status = 0;
    262      1.1    haya 
    263  1.3.2.1  bouyer 	cardbustag_t tag = cardbus_make_tag(cc, cf, sc->sc_bus, sc->sc_device, func);
    264      1.1    haya 
    265  1.3.2.1  bouyer 	DPRINTF(("cardbus_mapreg_map called: %s %x\n", sc->sc_dev.dv_xname,
    266      1.1    haya 	   type));
    267      1.1    haya 
    268  1.3.2.1  bouyer 	if (PCI_MAPREG_TYPE(type) == PCI_MAPREG_TYPE_IO) {
    269  1.3.2.1  bouyer 		if (cardbus_io_find(cc, cf, tag, reg, type, &base, &size, &flags)) {
    270  1.3.2.1  bouyer 			status = 1;
    271  1.3.2.1  bouyer 		}
    272  1.3.2.1  bouyer 		bustag = sc->sc_iot;
    273      1.1    haya #if rbus
    274  1.3.2.1  bouyer 		rbustag = sc->sc_rbus_iot;
    275      1.1    haya #endif
    276  1.3.2.1  bouyer 	} else {
    277  1.3.2.1  bouyer 		if (cardbus_mem_find(cc, cf, tag, reg, type, &base, &size, &flags)){
    278  1.3.2.1  bouyer 			status = 1;
    279  1.3.2.1  bouyer 		}
    280  1.3.2.1  bouyer 		bustag = sc->sc_memt;
    281      1.1    haya #if rbus
    282  1.3.2.1  bouyer 		rbustag = sc->sc_rbus_memt;
    283      1.1    haya #endif
    284  1.3.2.1  bouyer 	}
    285  1.3.2.1  bouyer 	if (status == 0) {
    286      1.1    haya #if rbus
    287  1.3.2.1  bouyer 		bus_addr_t mask = size - 1;
    288  1.3.2.1  bouyer 		if (base != 0) {
    289  1.3.2.1  bouyer 			mask = 0xffffffff;
    290  1.3.2.1  bouyer 		}
    291  1.3.2.1  bouyer 		if ((*cf->cardbus_space_alloc)(cc, rbustag, base, size, mask,
    292  1.3.2.1  bouyer 		    size, busflags | flags, &base, &handle)) {
    293  1.3.2.1  bouyer 			panic("io alloc");
    294  1.3.2.1  bouyer 		}
    295      1.1    haya #else
    296  1.3.2.1  bouyer 		bus_addr_t start = 0x8300;
    297  1.3.2.1  bouyer 		bus_addr_t end = 0x8400;
    298  1.3.2.1  bouyer 		if (base != 0) {
    299  1.3.2.1  bouyer 			bus_addr_t start = base;
    300  1.3.2.1  bouyer 			bus_addr_t end = base + size;
    301  1.3.2.1  bouyer 		}
    302  1.3.2.1  bouyer 		if (bus_space_alloc(bustag, start, end, size, size, 0, 0, &base, &handle)) {
    303  1.3.2.1  bouyer 			panic("io alloc");
    304  1.3.2.1  bouyer 		}
    305      1.1    haya #endif
    306  1.3.2.1  bouyer 	}
    307  1.3.2.1  bouyer 	cardbus_conf_write(cc, cf, tag, reg, base);
    308      1.1    haya 
    309  1.3.2.1  bouyer 	DPRINTF(("cardbus_mapreg_map: physaddr %lx\n", base));
    310      1.1    haya 
    311  1.3.2.1  bouyer 	if (tagp != 0) {
    312  1.3.2.1  bouyer 		*tagp = bustag;
    313  1.3.2.1  bouyer 	}
    314  1.3.2.1  bouyer 	if (handlep != 0) {
    315  1.3.2.1  bouyer 		*handlep = handle;
    316  1.3.2.1  bouyer 	}
    317  1.3.2.1  bouyer 	if (basep != 0) {
    318  1.3.2.1  bouyer 		*basep = base;
    319  1.3.2.1  bouyer 	}
    320  1.3.2.1  bouyer 	if (sizep != 0) {
    321  1.3.2.1  bouyer 		*sizep = size;
    322  1.3.2.1  bouyer 	}
    323  1.3.2.1  bouyer 	cardbus_free_tag(cc, cf, tag);
    324  1.3.2.1  bouyer 
    325  1.3.2.1  bouyer 	return 0;
    326      1.1    haya }
    327      1.1    haya 
    328      1.1    haya 
    329      1.1    haya 
    330      1.1    haya 
    331      1.1    haya 
    332  1.3.2.1  bouyer /*
    333  1.3.2.1  bouyer  * int cardbus_mapreg_unmap(struct cardbus_softc *sc, int func, int reg,
    334  1.3.2.1  bouyer  *			    bus_space_tag_t tag, bus_space_handle_t handle,
    335  1.3.2.1  bouyer  *			    bus_size_t size)
    336  1.3.2.1  bouyer  *
    337  1.3.2.1  bouyer  *   This function releases bus-space region and close memory or io
    338  1.3.2.1  bouyer  *   window on the bridge.
    339  1.3.2.1  bouyer  *
    340  1.3.2.1  bouyer  *  Arguments:
    341  1.3.2.1  bouyer  *   struct cardbus_softc *sc; the pointer to the device structure of cardbus.
    342  1.3.2.1  bouyer  *   int func; the number of function on the device.
    343  1.3.2.1  bouyer  *   int reg; the offset of BAR register.
    344  1.3.2.1  bouyer  */
    345  1.3.2.1  bouyer int
    346  1.3.2.1  bouyer cardbus_mapreg_unmap(sc, func, reg, tag, handle, size)
    347  1.3.2.1  bouyer 	struct cardbus_softc *sc;
    348  1.3.2.1  bouyer 	int func, reg;
    349  1.3.2.1  bouyer 	bus_space_tag_t tag;
    350  1.3.2.1  bouyer 	bus_space_handle_t handle;
    351  1.3.2.1  bouyer 	bus_size_t size;
    352  1.3.2.1  bouyer {
    353  1.3.2.1  bouyer 	cardbus_chipset_tag_t cc = sc->sc_cc;
    354  1.3.2.1  bouyer 	cardbus_function_tag_t cf = sc->sc_cf;
    355  1.3.2.1  bouyer 	int st = 1;
    356  1.3.2.1  bouyer 	cardbustag_t cardbustag;
    357  1.3.2.1  bouyer #if rbus
    358  1.3.2.1  bouyer 	rbus_tag_t rbustag;
    359  1.3.2.1  bouyer 
    360  1.3.2.1  bouyer 	if (sc->sc_iot == tag) {
    361  1.3.2.1  bouyer 		/* bus space is io space */
    362  1.3.2.1  bouyer 		DPRINTF(("%s: unmap i/o space\n", sc->sc_dev.dv_xname));
    363  1.3.2.1  bouyer 		rbustag = sc->sc_rbus_iot;
    364  1.3.2.1  bouyer 	} else if (sc->sc_memt == tag) {
    365  1.3.2.1  bouyer 		/* bus space is memory space */
    366  1.3.2.1  bouyer 		DPRINTF(("%s: unmap mem space\n", sc->sc_dev.dv_xname));
    367  1.3.2.1  bouyer 		rbustag = sc->sc_rbus_memt;
    368  1.3.2.1  bouyer 	} else {
    369  1.3.2.1  bouyer 		return 1;
    370  1.3.2.1  bouyer 	}
    371  1.3.2.1  bouyer #endif
    372  1.3.2.1  bouyer 
    373  1.3.2.1  bouyer 	cardbustag = cardbus_make_tag(cc, cf, sc->sc_bus, sc->sc_device, func);
    374  1.3.2.1  bouyer 
    375  1.3.2.1  bouyer 	cardbus_conf_write(cc, cf, cardbustag, reg, 0);
    376  1.3.2.1  bouyer 
    377  1.3.2.1  bouyer #if rbus
    378  1.3.2.1  bouyer 	(*cf->cardbus_space_free)(cc, rbustag, handle, size);
    379  1.3.2.1  bouyer #endif
    380  1.3.2.1  bouyer 
    381  1.3.2.1  bouyer 	cardbus_free_tag(cc, cf, cardbustag);
    382  1.3.2.1  bouyer 
    383  1.3.2.1  bouyer 	return st;
    384  1.3.2.1  bouyer }
    385  1.3.2.1  bouyer 
    386  1.3.2.1  bouyer 
    387  1.3.2.1  bouyer 
    388  1.3.2.1  bouyer 
    389      1.1    haya 
    390      1.1    haya /*
    391      1.1    haya  * int cardbus_save_bar(cardbus_devfunc_t);
    392      1.1    haya  *
    393      1.1    haya  *   This function saves the Base Address Registers at the CardBus
    394      1.1    haya  *   function denoted by the argument.
    395      1.1    haya  */
    396      1.1    haya int cardbus_save_bar(ct)
    397  1.3.2.1  bouyer 	cardbus_devfunc_t ct;
    398      1.1    haya {
    399  1.3.2.1  bouyer 	cardbustag_t tag = Cardbus_make_tag(ct);
    400  1.3.2.1  bouyer 	cardbus_chipset_tag_t cc = ct->ct_cc;
    401  1.3.2.1  bouyer 	cardbus_function_tag_t cf = ct->ct_cf;
    402  1.3.2.1  bouyer 
    403  1.3.2.1  bouyer 	ct->ct_bar[0] = cardbus_conf_read(cc, cf, tag, CARDBUS_BASE0_REG);
    404  1.3.2.1  bouyer 	ct->ct_bar[1] = cardbus_conf_read(cc, cf, tag, CARDBUS_BASE1_REG);
    405  1.3.2.1  bouyer 	ct->ct_bar[2] = cardbus_conf_read(cc, cf, tag, CARDBUS_BASE2_REG);
    406  1.3.2.1  bouyer 	ct->ct_bar[3] = cardbus_conf_read(cc, cf, tag, CARDBUS_BASE3_REG);
    407  1.3.2.1  bouyer 	ct->ct_bar[4] = cardbus_conf_read(cc, cf, tag, CARDBUS_BASE4_REG);
    408  1.3.2.1  bouyer 	ct->ct_bar[5] = cardbus_conf_read(cc, cf, tag, CARDBUS_BASE5_REG);
    409      1.1    haya 
    410  1.3.2.1  bouyer 	DPRINTF(("cardbus_save_bar: %x %x\n", ct->ct_bar[0], ct->ct_bar[1]));
    411      1.1    haya 
    412  1.3.2.1  bouyer 	Cardbus_free_tag(ct, tag);
    413      1.1    haya 
    414  1.3.2.1  bouyer 	return 0;
    415      1.1    haya }
    416      1.1    haya 
    417      1.1    haya 
    418      1.1    haya 
    419      1.1    haya /*
    420      1.1    haya  * int cardbus_restore_bar(cardbus_devfunc_t);
    421      1.1    haya  *
    422      1.1    haya  *   This function saves the Base Address Registers at the CardBus
    423      1.1    haya  *   function denoted by the argument.
    424      1.1    haya  */
    425      1.1    haya int cardbus_restore_bar(ct)
    426  1.3.2.1  bouyer 	cardbus_devfunc_t ct;
    427      1.1    haya {
    428  1.3.2.1  bouyer 	cardbustag_t tag = Cardbus_make_tag(ct);
    429  1.3.2.1  bouyer 	cardbus_chipset_tag_t cc = ct->ct_cc;
    430  1.3.2.1  bouyer 	cardbus_function_tag_t cf = ct->ct_cf;
    431  1.3.2.1  bouyer 
    432  1.3.2.1  bouyer 	cardbus_conf_write(cc, cf, tag, CARDBUS_BASE0_REG, ct->ct_bar[0]);
    433  1.3.2.1  bouyer 	cardbus_conf_write(cc, cf, tag, CARDBUS_BASE1_REG, ct->ct_bar[1]);
    434  1.3.2.1  bouyer 	cardbus_conf_write(cc, cf, tag, CARDBUS_BASE2_REG, ct->ct_bar[2]);
    435  1.3.2.1  bouyer 	cardbus_conf_write(cc, cf, tag, CARDBUS_BASE3_REG, ct->ct_bar[3]);
    436  1.3.2.1  bouyer 	cardbus_conf_write(cc, cf, tag, CARDBUS_BASE4_REG, ct->ct_bar[4]);
    437  1.3.2.1  bouyer 	cardbus_conf_write(cc, cf, tag, CARDBUS_BASE5_REG, ct->ct_bar[5]);
    438  1.3.2.1  bouyer 
    439  1.3.2.1  bouyer 	Cardbus_free_tag(ct, tag);
    440      1.1    haya 
    441  1.3.2.1  bouyer 	return 0;
    442      1.1    haya }
    443