Home | History | Annotate | Line # | Download | only in ic
i82365var.h revision 1.7
      1  1.7   msaitoh /*	$NetBSD: i82365var.h,v 1.7 1999/01/21 07:43:33 msaitoh Exp $	*/
      2  1.2   thorpej 
      3  1.2   thorpej /*
      4  1.2   thorpej  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
      5  1.2   thorpej  *
      6  1.2   thorpej  * Redistribution and use in source and binary forms, with or without
      7  1.2   thorpej  * modification, are permitted provided that the following conditions
      8  1.2   thorpej  * are met:
      9  1.2   thorpej  * 1. Redistributions of source code must retain the above copyright
     10  1.2   thorpej  *    notice, this list of conditions and the following disclaimer.
     11  1.2   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.2   thorpej  *    notice, this list of conditions and the following disclaimer in the
     13  1.2   thorpej  *    documentation and/or other materials provided with the distribution.
     14  1.2   thorpej  * 3. All advertising materials mentioning features or use of this software
     15  1.2   thorpej  *    must display the following acknowledgement:
     16  1.2   thorpej  *	This product includes software developed by Marc Horowitz.
     17  1.2   thorpej  * 4. The name of the author may not be used to endorse or promote products
     18  1.2   thorpej  *    derived from this software without specific prior written permission.
     19  1.2   thorpej  *
     20  1.2   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.2   thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.2   thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.2   thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.2   thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.2   thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.2   thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.2   thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.2   thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.2   thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.2   thorpej  */
     31  1.2   thorpej 
     32  1.2   thorpej #include <sys/device.h>
     33  1.2   thorpej 
     34  1.2   thorpej #include <dev/pcmcia/pcmciareg.h>
     35  1.2   thorpej #include <dev/pcmcia/pcmciachip.h>
     36  1.2   thorpej 
     37  1.2   thorpej #include <dev/ic/i82365reg.h>
     38  1.2   thorpej 
     39  1.5   thorpej struct proc;
     40  1.5   thorpej 
     41  1.5   thorpej struct pcic_event {
     42  1.5   thorpej 	SIMPLEQ_ENTRY(pcic_event) pe_q;
     43  1.5   thorpej 	int pe_type;
     44  1.5   thorpej };
     45  1.5   thorpej 
     46  1.5   thorpej /* pe_type */
     47  1.5   thorpej #define	PCIC_EVENT_INSERTION	0
     48  1.5   thorpej #define	PCIC_EVENT_REMOVAL	1
     49  1.5   thorpej 
     50  1.2   thorpej struct pcic_handle {
     51  1.2   thorpej 	struct pcic_softc *sc;
     52  1.2   thorpej 	int	vendor;
     53  1.2   thorpej 	int	sock;
     54  1.2   thorpej 	int	flags;
     55  1.7   msaitoh 	int laststate;
     56  1.2   thorpej 	int	memalloc;
     57  1.2   thorpej 	struct {
     58  1.2   thorpej 		bus_addr_t	addr;
     59  1.2   thorpej 		bus_size_t	size;
     60  1.2   thorpej 		long		offset;
     61  1.2   thorpej 		int		kind;
     62  1.2   thorpej 	} mem[PCIC_MEM_WINS];
     63  1.2   thorpej 	int	ioalloc;
     64  1.2   thorpej 	struct {
     65  1.2   thorpej 		bus_addr_t	addr;
     66  1.2   thorpej 		bus_size_t	size;
     67  1.2   thorpej 		int		width;
     68  1.2   thorpej 	} io[PCIC_IO_WINS];
     69  1.2   thorpej 	int	ih_irq;
     70  1.2   thorpej 	struct device *pcmcia;
     71  1.5   thorpej 
     72  1.5   thorpej 	int shutdown;
     73  1.5   thorpej 	struct proc *event_thread;
     74  1.5   thorpej 	SIMPLEQ_HEAD(, pcic_event) events;
     75  1.2   thorpej };
     76  1.2   thorpej 
     77  1.2   thorpej #define	PCIC_FLAG_SOCKETP	0x0001
     78  1.2   thorpej #define	PCIC_FLAG_CARDP		0x0002
     79  1.7   msaitoh 
     80  1.7   msaitoh #define PCIC_LASTSTATE_PRESENT	0x0002
     81  1.7   msaitoh #define PCIC_LASTSTATE_HALF		0x0001
     82  1.7   msaitoh #define PCIC_LASTSTATE_EMPTY	0x0000
     83  1.2   thorpej 
     84  1.2   thorpej #define	C0SA PCIC_CHIP0_BASE+PCIC_SOCKETA_INDEX
     85  1.2   thorpej #define	C0SB PCIC_CHIP0_BASE+PCIC_SOCKETB_INDEX
     86  1.2   thorpej #define	C1SA PCIC_CHIP1_BASE+PCIC_SOCKETA_INDEX
     87  1.2   thorpej #define	C1SB PCIC_CHIP1_BASE+PCIC_SOCKETB_INDEX
     88  1.2   thorpej 
     89  1.2   thorpej /*
     90  1.2   thorpej  * This is sort of arbitrary.  It merely needs to be "enough". It can be
     91  1.2   thorpej  * overridden in the conf file, anyway.
     92  1.2   thorpej  */
     93  1.2   thorpej 
     94  1.2   thorpej #define	PCIC_MEM_PAGES	4
     95  1.2   thorpej #define	PCIC_MEMSIZE	PCIC_MEM_PAGES*PCIC_MEM_PAGESIZE
     96  1.2   thorpej 
     97  1.2   thorpej #define	PCIC_NSLOTS	4
     98  1.2   thorpej 
     99  1.2   thorpej struct pcic_softc {
    100  1.2   thorpej 	struct device dev;
    101  1.2   thorpej 
    102  1.2   thorpej 	bus_space_tag_t memt;
    103  1.2   thorpej 	bus_space_handle_t memh;
    104  1.2   thorpej 	bus_space_tag_t iot;
    105  1.2   thorpej 	bus_space_handle_t ioh;
    106  1.2   thorpej 
    107  1.2   thorpej 	/* XXX isa_chipset_tag_t, pci_chipset_tag_t, etc. */
    108  1.4      matt 	void *intr_est;
    109  1.2   thorpej 
    110  1.2   thorpej 	pcmcia_chipset_tag_t pct;
    111  1.2   thorpej 
    112  1.2   thorpej 	/* this needs to be large enough to hold PCIC_MEM_PAGES bits */
    113  1.2   thorpej 	int	subregionmask;
    114  1.6  christos #define PCIC_MAX_MEM_PAGES	(8 * sizeof(int))
    115  1.2   thorpej 
    116  1.2   thorpej 	/* used by memory window mapping functions */
    117  1.2   thorpej 	bus_addr_t membase;
    118  1.2   thorpej 
    119  1.2   thorpej 	/*
    120  1.2   thorpej 	 * used by io window mapping functions.  These can actually overlap
    121  1.2   thorpej 	 * with another pcic, since the underlying extent mapper will deal
    122  1.2   thorpej 	 * with individual allocations.  This is here to deal with the fact
    123  1.2   thorpej 	 * that different busses have different real widths (different pc
    124  1.2   thorpej 	 * hardware seems to use 10 or 12 bits for the I/O bus).
    125  1.2   thorpej 	 */
    126  1.2   thorpej 	bus_addr_t iobase;
    127  1.2   thorpej 	bus_addr_t iosize;
    128  1.2   thorpej 
    129  1.2   thorpej 	int	irq;
    130  1.2   thorpej 	void	*ih;
    131  1.2   thorpej 
    132  1.2   thorpej 	struct pcic_handle handle[PCIC_NSLOTS];
    133  1.2   thorpej };
    134  1.2   thorpej 
    135  1.2   thorpej 
    136  1.2   thorpej int	pcic_ident_ok __P((int));
    137  1.2   thorpej int	pcic_vendor __P((struct pcic_handle *));
    138  1.2   thorpej char	*pcic_vendor_to_string __P((int));
    139  1.2   thorpej 
    140  1.2   thorpej void	pcic_attach __P((struct pcic_softc *));
    141  1.2   thorpej void	pcic_attach_sockets __P((struct pcic_softc *));
    142  1.2   thorpej int	pcic_intr __P((void *arg));
    143  1.2   thorpej 
    144  1.2   thorpej static inline int pcic_read __P((struct pcic_handle *, int));
    145  1.2   thorpej static inline void pcic_write __P((struct pcic_handle *, int, int));
    146  1.2   thorpej 
    147  1.2   thorpej int	pcic_chip_mem_alloc __P((pcmcia_chipset_handle_t, bus_size_t,
    148  1.2   thorpej 	    struct pcmcia_mem_handle *));
    149  1.2   thorpej void	pcic_chip_mem_free __P((pcmcia_chipset_handle_t,
    150  1.2   thorpej 	    struct pcmcia_mem_handle *));
    151  1.2   thorpej int	pcic_chip_mem_map __P((pcmcia_chipset_handle_t, int, bus_addr_t,
    152  1.2   thorpej 	    bus_size_t, struct pcmcia_mem_handle *, bus_addr_t *, int *));
    153  1.2   thorpej void	pcic_chip_mem_unmap __P((pcmcia_chipset_handle_t, int));
    154  1.2   thorpej 
    155  1.2   thorpej int	pcic_chip_io_alloc __P((pcmcia_chipset_handle_t, bus_addr_t,
    156  1.2   thorpej 	    bus_size_t, bus_size_t, struct pcmcia_io_handle *));
    157  1.2   thorpej void	pcic_chip_io_free __P((pcmcia_chipset_handle_t,
    158  1.2   thorpej 	    struct pcmcia_io_handle *));
    159  1.2   thorpej int	pcic_chip_io_map __P((pcmcia_chipset_handle_t, int, bus_addr_t,
    160  1.2   thorpej 	    bus_size_t, struct pcmcia_io_handle *, int *));
    161  1.2   thorpej void	pcic_chip_io_unmap __P((pcmcia_chipset_handle_t, int));
    162  1.2   thorpej 
    163  1.2   thorpej void	pcic_chip_socket_enable __P((pcmcia_chipset_handle_t));
    164  1.2   thorpej void	pcic_chip_socket_disable __P((pcmcia_chipset_handle_t));
    165  1.2   thorpej 
    166  1.2   thorpej static __inline int pcic_read __P((struct pcic_handle *, int));
    167  1.2   thorpej static __inline int
    168  1.2   thorpej pcic_read(h, idx)
    169  1.2   thorpej 	struct pcic_handle *h;
    170  1.2   thorpej 	int idx;
    171  1.2   thorpej {
    172  1.2   thorpej 	if (idx != -1)
    173  1.2   thorpej 		bus_space_write_1(h->sc->iot, h->sc->ioh, PCIC_REG_INDEX,
    174  1.2   thorpej 		    h->sock + idx);
    175  1.2   thorpej 	return (bus_space_read_1(h->sc->iot, h->sc->ioh, PCIC_REG_DATA));
    176  1.2   thorpej }
    177  1.2   thorpej 
    178  1.2   thorpej static __inline void pcic_write __P((struct pcic_handle *, int, int));
    179  1.2   thorpej static __inline void
    180  1.2   thorpej pcic_write(h, idx, data)
    181  1.2   thorpej 	struct pcic_handle *h;
    182  1.2   thorpej 	int idx;
    183  1.2   thorpej 	int data;
    184  1.2   thorpej {
    185  1.2   thorpej 	if (idx != -1)
    186  1.2   thorpej 		bus_space_write_1(h->sc->iot, h->sc->ioh, PCIC_REG_INDEX,
    187  1.2   thorpej 		    h->sock + idx);
    188  1.2   thorpej 	bus_space_write_1(h->sc->iot, h->sc->ioh, PCIC_REG_DATA, (data));
    189  1.2   thorpej }
    190