/*
* Copyright (c) 1998, 1999 Christoph Badura. All rights reserved.
* Copyright (c) 1997 Marc Horowitz. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Marc Horowitz.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
struct tcic_handle {
struct tcic_softc *sc;
int sock; /* socket number */
int flags;
int sstat; /* last value of R_SSTAT */
int memalloc;
int memwins;
struct {
bus_addr_t addr;
bus_size_t size;
int size2; /* size as 2^n scaled by 4K */
long offset;
int speed; /* in ns */
int kind;
} mem[TCIC_MAX_MEM_WINS];
int ioalloc;
struct {
bus_addr_t addr;
bus_size_t size;
int width;
int speed; /* in ns */
} io[TCIC_IO_WINS];
int ih_irq;
device_t pcmcia;
int shutdown;
struct lwp *event_thread;
SIMPLEQ_HEAD(, tcic_event) events;
};
int chipid;
int validirqs;
int pwrena; /* holds TCIC_PWR_ENA on'084 and successors */
/* XXX isa_chipset_tag_t, pci_chipset_tag_t, etc. */
void *intr_est;
pcmcia_chipset_tag_t pct;
/* this needs to be large enough to hold TCIC_MEM_PAGES bits */
int subregionmask;
/* used by memory window mapping functions */
bus_addr_t membase;
int memsize2; /* int(log2(memsize)) */
/*
* used by io window mapping functions. These can actually overlap
* with another tcic, since the underlying extent mapper will deal
* with individual allocations. This is here to deal with the fact
* that different busses have different real widths (different pc
* hardware seems to use 10 or 12 bits for the I/O bus).
*/
bus_addr_t iobase;
bus_size_t iosize;
int irq;
void *ih;
struct tcic_handle handle[TCIC_NSLOTS];
};
int tcic_log2(u_int);
int tcic_ns2wscnt(int);
int tcic_check_reserved_bits(bus_space_tag_t, bus_space_handle_t);
int tcic_chipid(bus_space_tag_t, bus_space_handle_t);
int tcic_chipid_known(int);
const char *tcic_chipid_to_string(int);
int tcic_validirqs(int);
/* XXX appropriate socket must have been selected already. */
for (i = 0; i < 10000; i++) {
if (tcic_read_1(h, TCIC_R_SSTAT) & TCIC_SSTAT_RDY)
return;
delay(500);
}
#ifdef DIAGNOSTIC
printf("tcic_wait_ready ready never happened\n");
#endif
}
static __inline int tcic_read_aux_1(bus_space_tag_t, bus_space_handle_t, int, int);
static __inline int
tcic_read_aux_1(bus_space_tag_t iot, bus_space_handle_t ioh, int auxreg, int reg)
{
int mode, val;
mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
val = bus_space_read_1(iot, ioh, reg);
return val;
}
static __inline int tcic_read_aux_2(bus_space_tag_t, bus_space_handle_t, int);
static __inline int
tcic_read_aux_2(bus_space_tag_t iot, bus_space_handle_t ioh, int auxreg)
{
int mode, val;
mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
val = bus_space_read_2(iot, ioh, TCIC_R_AUX);
return val;
}
static __inline void tcic_write_aux_1(bus_space_tag_t, bus_space_handle_t, int, int, int);
static __inline void
tcic_write_aux_1(bus_space_tag_t iot, bus_space_handle_t ioh, int auxreg, int reg, int val)
{
int mode;
mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
bus_space_write_1(iot, ioh, reg, val);
}